diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 42250da..d70be1a 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,6 +2,7 @@ + @@ -9,6 +10,6 @@ - + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index d0dbce0..8cc9393 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,5 +1,6 @@ + - + diff --git a/README.txt b/README.txt index 9b41b1b..0805c9b 100644 --- a/README.txt +++ b/README.txt @@ -9,6 +9,15 @@ - Entonces, el contenido del bote se multiplica por dos y se divide entre todos los jugadores. - Pasadas N rondas, el jugador se queda con lo que ganó + monedas iniciales. +- Tipos de jugadores: + - Pícaro: no colabora nunca. + - Santo: colabora siempre. + - Justiciero: colabora si y solo si todos los jugadores han colaborado en el turno anterior. + +Comprobar distribución de ganancia según variación en tipo de jugadores; Pícaro, santo o justiciero. + +10 jugadores, 100 turnos, 100 monedas iniciales. + Comprobar cómo de dispuesta está la gente a contribuir a un bien, que será compartido por todos por igual, hayan contribuido o no. \ No newline at end of file diff --git a/build/reports/tests/test/classes/dev.freireservices.social_altruism.chat.ChatQuickStartTest.html b/build/reports/tests/test/classes/dev.freireservices.social_altruism.chat.ChatQuickStartTest.html index 5faed4a..c130203 100644 --- a/build/reports/tests/test/classes/dev.freireservices.social_altruism.chat.ChatQuickStartTest.html +++ b/build/reports/tests/test/classes/dev.freireservices.social_altruism.chat.ChatQuickStartTest.html @@ -3,14 +3,14 @@ -Test results - Class dev.freireservices.social_altruism.chat.ChatQuickStartTest +Test results - Class dev.freireservices.social_altruism.chat.PotQuickStartTest
-

Class dev.freireservices.social_altruism.chat.ChatQuickStartTest

+

Class dev.freireservices.social_altruism.chat.PotQuickStartTest

@@ -76,11 +76,11 @@

testGreeterActorSendingOfGreeting

-
java.lang.AssertionError: Timeout (10 seconds) during expectMessageClass waiting for class dev.freireservices.social_altruism.chat.ChatPotProtocol$PotReturned
+
java.lang.AssertionError: Timeout (10 seconds) during expectMessageClass waiting for class dev.freireservices.social_altruism.chat.potroom.PotRoom$PotReturned
 	at akka.actor.testkit.typed.internal.TestProbeImpl.assertFail(TestProbeImpl.scala:399)
 	at akka.actor.testkit.typed.internal.TestProbeImpl.expectMessageClass_internal(TestProbeImpl.scala:239)
 	at akka.actor.testkit.typed.internal.TestProbeImpl.expectMessageClass(TestProbeImpl.scala:227)
-	at dev.freireservices.social_altruism.chat.ChatQuickStartTest.testGreeterActorSendingOfGreeting(ChatQuickStartTest.java:35)
+	at dev.freireservices.social_altruism.chat.PotQuickStartTest.testGreeterActorSendingOfGreeting(ChatQuickStartTest.java:35)
 	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
 	at java.base/java.lang.reflect.Method.invoke(Method.java:578)
 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
diff --git a/build/reports/tests/test/index.html b/build/reports/tests/test/index.html
index 38f91d6..967f259 100644
--- a/build/reports/tests/test/index.html
+++ b/build/reports/tests/test/index.html
@@ -71,8 +71,8 @@
 

Failed tests

@@ -119,7 +119,7 @@ -dev.freireservices.social_altruism.chat.ChatQuickStartTest +dev.freireservices.social_altruism.chat.PotQuickStartTest 1 1 diff --git a/build/reports/tests/test/packages/dev.freireservices.social_altruism.chat.html b/build/reports/tests/test/packages/dev.freireservices.social_altruism.chat.html index 06c7426..fd4c050 100644 --- a/build/reports/tests/test/packages/dev.freireservices.social_altruism.chat.html +++ b/build/reports/tests/test/packages/dev.freireservices.social_altruism.chat.html @@ -70,8 +70,8 @@

Failed tests

@@ -90,7 +90,7 @@ -ChatQuickStartTest +ChatQuickStartTest 1 1 diff --git a/build/test-results/test/TEST-dev.freireservices.social_altruism.chat.ChatQuickStartTest.xml b/build/test-results/test/TEST-dev.freireservices.social_altruism.chat.ChatQuickStartTest.xml index cb3f4fe..ef5fda6 100644 --- a/build/test-results/test/TEST-dev.freireservices.social_altruism.chat.ChatQuickStartTest.xml +++ b/build/test-results/test/TEST-dev.freireservices.social_altruism.chat.ChatQuickStartTest.xml @@ -1,52 +1,61 @@ - + - - java.lang.AssertionError: Timeout (10 seconds) during expectMessageClass waiting for class dev.freireservices.social_altruism.chat.ChatPotProtocol$PotReturned - at akka.actor.testkit.typed.internal.TestProbeImpl.assertFail(TestProbeImpl.scala:399) - at akka.actor.testkit.typed.internal.TestProbeImpl.expectMessageClass_internal(TestProbeImpl.scala:239) - at akka.actor.testkit.typed.internal.TestProbeImpl.expectMessageClass(TestProbeImpl.scala:227) - at dev.freireservices.social_altruism.chat.ChatQuickStartTest.testGreeterActorSendingOfGreeting(ChatQuickStartTest.java:35) - at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) - at java.base/java.lang.reflect.Method.invoke(Method.java:578) - at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) - at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) - at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) - at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) - at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) - at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) - at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) - at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) - at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) - at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) - at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) - at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) - at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) - at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) - at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) - at org.junit.runners.ParentRunner.run(ParentRunner.java:413) - at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:108) - at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:57) - at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:39) - at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62) - at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:52) - at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) - at java.base/java.lang.reflect.Method.invoke(Method.java:578) - at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) - at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) - at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33) - at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94) - at jdk.proxy1/jdk.proxy1.$Proxy2.processTestClass(Unknown Source) - at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176) - at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129) - at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100) - at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60) - at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56) - at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113) - at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65) - at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69) - at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74) - + + java.lang.AssertionError: + Timeout (10 seconds) during expectMessageClass waiting for class + dev.freireservices.social_altruism.chat.potroom.PotRoom$PotReturned + at akka.actor.testkit.typed.internal.TestProbeImpl.assertFail(TestProbeImpl.scala:399) + at akka.actor.testkit.typed.internal.TestProbeImpl.expectMessageClass_internal(TestProbeImpl.scala:239) + at akka.actor.testkit.typed.internal.TestProbeImpl.expectMessageClass(TestProbeImpl.scala:227) + at + dev.freireservices.social_altruism.chat.PotQuickStartTest.testGreeterActorSendingOfGreeting(ChatQuickStartTest.java:35) + at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) + at java.base/java.lang.reflect.Method.invoke(Method.java:578) + at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) + at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) + at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) + at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) + at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) + at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) + at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) + at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) + at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) + at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) + at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) + at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) + at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) + at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) + at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) + at org.junit.runners.ParentRunner.run(ParentRunner.java:413) + at + org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:108) + at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:57) + at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:39) + at + org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62) + at + org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:52) + at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) + at java.base/java.lang.reflect.Method.invoke(Method.java:578) + at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36) + at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) + at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33) + at + org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94) + at jdk.proxy1/jdk.proxy1.$Proxy2.processTestClass(Unknown Source) + at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176) + at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129) + at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100) + at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60) + at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56) + at + org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113) + at + org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65) + at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69) + at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74) + test + + + org.projectlombok + lombok + 1.18.30 + provided + + + @@ -87,7 +96,7 @@ -classpath - dev.freireservices.social_altruism.chat.ChatQuickStart + dev.freireservices.social_altruism.chat.PotQuickStart diff --git a/src/main/java/dev/freireservices/social_altruism/chat/ChatPotProtocol.java b/src/main/java/dev/freireservices/social_altruism/chat/ChatPotProtocol.java deleted file mode 100644 index 57a8f17..0000000 --- a/src/main/java/dev/freireservices/social_altruism/chat/ChatPotProtocol.java +++ /dev/null @@ -1,184 +0,0 @@ -package dev.freireservices.social_altruism.chat; - -import static java.nio.charset.StandardCharsets.*; -import static java.util.Collections.emptyList; - -import akka.actor.typed.ActorRef; -import akka.actor.typed.Behavior; -import akka.actor.typed.javadsl.ActorContext; -import akka.actor.typed.javadsl.Behaviors; -import dev.freireservices.social_altruism.chat.commands.Commands; -import dev.freireservices.social_altruism.chat.events.Events; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.List; - -public class ChatPotProtocol { - private final ActorContext context; - - private final List> sessions; - - public double getCurrentPot() { - return currentPot; - } - - public void resetPot() { - this.currentPot = 0; - } - - public void addToPot(double pot) { - this.currentPot += pot; - } - - private double currentPot = 0.0; - - public int getCurrentTurn() { - return currentTurn; - } - - public int incrementCurrentTurnAndGet() { - this.currentTurn++; - return this.currentTurn; - } - - private int currentTurn = 0; - private int totalTurns = 0; - - public int getParticipantsInTurn() { - return participantsInTurn; - } - - public void incrementParticipantsInTurn() { - this.participantsInTurn++; - } - - public void resetParticipantsInTurn() { - this.participantsInTurn = 0; - } - - public int getNumberOfParticipants() { - return numberOfParticipants; - } - - private int participantsInTurn = 0; - private final int numberOfParticipants; - - private ChatPotProtocol( - ActorContext context, - List> sessions, - int numberOfParticipants, - int turns) { - this.context = context; - this.sessions = sessions; - this.numberOfParticipants = numberOfParticipants; - this.totalTurns = turns; - } - - // #chatroom-behavior - // #chatroom-protocol - - private Behavior onGetPotSession(Commands.EnterPot enterPot) { - - // Add check session started - if (sessions.stream() - .anyMatch( - s -> - s.path() - .name() - .equals(URLEncoder.encode(enterPot.replyTo().path().name(), UTF_8)))) { - - enterPot.replyTo().tell(new Events.SessionDenied("Can only enter a pot once")); - } - - context.getLog().info("Participant joined {} pot", enterPot.replyTo().path().name()); - - ActorRef client = enterPot.replyTo(); - - ActorRef session = - context.spawn( - Session.create(client), URLEncoder.encode(enterPot.replyTo().path().name(), UTF_8)); - - // narrow to only expose PostMessage - client.tell(new Events.SessionGranted(session.narrow())); - - sessions.add(session); - - if (numberOfParticipants == sessions.size()) { - context.getLog().info("All participants joined; pot is ready to start."); - return createPotBehaviour(); - } else { - // Waiting for more participants - context.getLog().info("Waiting for more participants."); - return Behaviors.same(); - } - } - - private Behavior onPlayTurn(Commands.PlayTurn playTurn) { - - context - .getLog() - .info( - "Participant {} joined for turn {} with {}", - playTurn.replyTo().path().name(), - currentTurn, - playTurn.pot()); - - // Add to current pot - addToPot(playTurn.pot()); - incrementParticipantsInTurn(); - - if (getParticipantsInTurn() == numberOfParticipants) { - - double amountToShare = (getCurrentPot() * 2) / numberOfParticipants; - sessions.forEach(s -> s.tell(new SharePotWithParticipants(amountToShare))); - - resetPot(); - resetParticipantsInTurn(); - - context.getLog().info("Turn {} complete", getCurrentTurn()); - - if (incrementCurrentTurnAndGet() == totalTurns) { - context.getLog().info("All turns completed"); - return Behaviors.stopped(); - } - } - - return Behaviors.same(); - } - - private Behavior createPotBehaviour() { - return Behaviors.receive(Commands.RoomCommand.class) - .onMessage(Commands.EnterPot.class, this::onGetPotSession) - .onMessage(Commands.PlayTurn.class, this::onPlayTurn) - .build(); - } - - public static Behavior create(int numberOfParticipants, int turns) { - return Behaviors.setup( - ctx -> - new ChatPotProtocol(ctx, new ArrayList<>(), numberOfParticipants, turns) - .createPotBehaviour()); - } - - interface SessionCommand {} - - public record ParticipateInTurn(String message) implements SessionCommand {} - - public record SharePotWithParticipants(double returnedAmount) implements SessionCommand {} - - static class Session { - static Behavior create(ActorRef client) { - return Behaviors.receive(ChatPotProtocol.SessionCommand.class) - .onMessage( - SharePotWithParticipants.class, - pot -> onSharePotWithParticipants(client, pot.returnedAmount)) - .build(); - } - - private static Behavior onSharePotWithParticipants( - ActorRef participant, double returnedAmount) { - participant.tell(new Events.PotReturned(participant, returnedAmount)); - return Behaviors.same(); - } - } -} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/ChatQuickStart.java b/src/main/java/dev/freireservices/social_altruism/chat/ChatQuickStart.java deleted file mode 100644 index 54914e8..0000000 --- a/src/main/java/dev/freireservices/social_altruism/chat/ChatQuickStart.java +++ /dev/null @@ -1,77 +0,0 @@ -package dev.freireservices.social_altruism.chat; - -import akka.actor.typed.ActorRef; -import akka.actor.typed.ActorSystem; -import akka.actor.typed.Behavior; -import akka.actor.typed.Terminated; -import akka.actor.typed.javadsl.Behaviors; -import dev.freireservices.social_altruism.chat.commands.Commands; -import dev.freireservices.social_altruism.chat.events.Events; -import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.IntStream; - -public class ChatQuickStart { - - public static void main(String[] args) { - // #actor-system - ActorSystem.create(Main.create(), "PotRoom"); - } - - public static class Main { - - static List> sessions = new ArrayList<>(); - - static final int numberOfParticipants = 2; - static final int numberOfTurns = 100; - - public static Behavior create() { - return Behaviors.setup( - context -> { - ActorRef chatRoom = - context.spawn( - ChatPotProtocol.create(numberOfParticipants, numberOfTurns), "potRoom"); - - // Agregamos jugadores - sessions.addAll( - IntStream.range(0, numberOfParticipants) - .mapToObj( - i -> - context.spawn( - Participante.create(getRandomNumberBetween(0, 100)), - "participante-" + i)) - .toList()); - - // Entrar en pot - for (ActorRef session : sessions) { - chatRoom.tell(new Commands.EnterPot(session)); - } - - for (int i = 0; i < numberOfTurns; i++) { - // Participar en cada turno cantidad diferente - for (ActorRef session : sessions) { - - // Pícaro - if (session.path().name().contains("participante-0")) { - chatRoom.tell(new Commands.PlayTurn(session, 0)); - } else { - chatRoom.tell(new Commands.PlayTurn(session, getRandomNumberBetween(0, 10))); - } - } - } - - return Behaviors.receive(Void.class) - .onSignal(Terminated.class, sig -> Behaviors.stopped()) - .build(); - }); - } - } - - // #actor-system - - public static int getRandomNumberBetween(int min, int max) { - SecureRandom secureRandom = new SecureRandom(); - return secureRandom.nextInt(max - min) + min; - } -} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/Participante.java b/src/main/java/dev/freireservices/social_altruism/chat/Participante.java deleted file mode 100644 index 0577c3b..0000000 --- a/src/main/java/dev/freireservices/social_altruism/chat/Participante.java +++ /dev/null @@ -1,85 +0,0 @@ -package dev.freireservices.social_altruism.chat; - -import akka.actor.typed.Behavior; -import akka.actor.typed.javadsl.ActorContext; -import akka.actor.typed.javadsl.Behaviors; -import dev.freireservices.social_altruism.chat.events.Events; - -public class Participante { - - public static Behavior create(int monedasInit) { - return Behaviors.setup(ctx -> new Participante(ctx, monedasInit).behavior()); - } - - private final ActorContext context; - - public double getMonedas() { - return monedas; - } - - public void setMonedas(double monedas) { - this.monedas = monedas; - } - - public void decrementMonedas(double monedas) { - this.monedas -= monedas; - } - - public void incrementMonedas(double monedas) { - this.monedas += monedas; - } - - private double monedas; - - public double getMonedasInit() { - return monedasInit; - } - - private final double monedasInit; - - private Participante(ActorContext context, double monedas) { - this.context = context; - this.monedas = monedas; - this.monedasInit = monedas; - } - - private Behavior behavior() { - return Behaviors.receive(Events.SessionEvent.class) - .onMessage(Events.SessionDenied.class, this::onSessionDenied) - .onMessage(Events.SessionGranted.class, this::onSessionGranted) - .onMessage(Events.PotReturned.class, this::onPotReturned) - .build(); - } - - private Behavior onSessionDenied(Events.SessionDenied message) { - context.getLog().info("cannot start chat room session: {}", message.reason()); - return Behaviors.stopped(); - } - - private Behavior onSessionGranted(Events.SessionGranted message) { - return Behaviors.same(); - } - - private Behavior onPotReturned(Events.PotReturned potReturned) { - context.getLog().info("Pot returned: {}", potReturned.returnedAmount()); - incrementMonedas(potReturned.returnedAmount()); - context - .getLog() - .info( - "Player {} has now {} coins; started with {} for a total profit of: {} %", - potReturned.participant().path().name(), - getMonedas(), - getMonedasInit(), - calculateProfit()); - - //Calcular contribución total. - //Si detecta baja contribución aplicar penalización - - - return Behaviors.same(); - } - - private double calculateProfit() { - return Math.round((getMonedas() * 100) / getMonedasInit() -100); - } -} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/PotQuickStart.java b/src/main/java/dev/freireservices/social_altruism/chat/PotQuickStart.java new file mode 100644 index 0000000..9bb2b5d --- /dev/null +++ b/src/main/java/dev/freireservices/social_altruism/chat/PotQuickStart.java @@ -0,0 +1,83 @@ +package dev.freireservices.social_altruism.chat; + +import static dev.freireservices.social_altruism.chat.participant.ParticipantType.*; + +import akka.actor.typed.ActorRef; +import akka.actor.typed.ActorSystem; +import akka.actor.typed.Behavior; +import akka.actor.typed.Terminated; +import akka.actor.typed.javadsl.Behaviors; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol; +import dev.freireservices.social_altruism.chat.events.ParticipantProtocol; +import dev.freireservices.social_altruism.chat.participant.Participant; +import dev.freireservices.social_altruism.chat.potroom.PotRoom; +import java.util.ArrayList; +import java.util.List; + +public class PotQuickStart { + + public static final int MONEDAS_INIT = 100; + + public static void main(String[] args) { + // #actor-system + ActorSystem.create(Main.create(), "PotRoom"); + } + + public static class Main { + + static List> sessions = new ArrayList<>(); + + static final int numberOfParticipants = 3; + static final int numberOfTurns = 100; + + public static Behavior create() { + return Behaviors.setup( + context -> { + ActorRef chatRoom = + context.spawn( + PotRoom.create(numberOfParticipants, numberOfTurns), "potRoom"); + + // Agregamos jugadores + final var picaroZero = Participant.create(MONEDAS_INIT, PICARO); + final var santoZero = Participant.create(MONEDAS_INIT, SANTO); + final var justiZero = Participant.create(MONEDAS_INIT, JUSTICIERO); + + sessions.add(context.spawn(picaroZero, "participante-picaro-0")); + sessions.add(context.spawn(santoZero, "participante-santo-0")); + sessions.add(context.spawn(justiZero, "participante-justiciero-0")); + + // Entrar en pot + for (ActorRef session : sessions) { + chatRoom.tell(new PotRoomProtocol.EnterPot(session)); + } + +/* for (int i = 0; i < numberOfTurns; i++) { + // Participar en cada turno cantidad diferente + for (ActorRef session : sessions) { + + // Pícaro + if (session.path().name().contains("participante-0")) { + chatRoom.tell(new PotRoomProtocol.PlayTurn(session, 0)); + // Justiciero + } else if (session.path().name().contains("participante-1")) { + + // ActorRef chatRoom, double pot, + // ActorRef replyTo) + + chatRoom.tell(new PotRoomProtocol.PlayTurn(session, 1)); + // Santo + } else if (session.path().name().contains("participante-2")) { + chatRoom.tell(new PotRoomProtocol.PlayTurn(session, 2)); + } + } + }*/ + + return Behaviors.receive(Void.class) + .onSignal(Terminated.class, sig -> Behaviors.stopped()) + .build(); + }); + } + } + + // #actor-system +} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/TipoDeParticipante.java b/src/main/java/dev/freireservices/social_altruism/chat/TipoDeParticipante.java deleted file mode 100644 index b298e8b..0000000 --- a/src/main/java/dev/freireservices/social_altruism/chat/TipoDeParticipante.java +++ /dev/null @@ -1,8 +0,0 @@ -package dev.freireservices.social_altruism.chat; - -public enum TipoDeParticipante { - SANTO, - JUSTICIERO, - PICARO, - -} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/commands/Commands.java b/src/main/java/dev/freireservices/social_altruism/chat/commands/Commands.java deleted file mode 100644 index cdd817d..0000000 --- a/src/main/java/dev/freireservices/social_altruism/chat/commands/Commands.java +++ /dev/null @@ -1,15 +0,0 @@ -package dev.freireservices.social_altruism.chat.commands; - -import akka.actor.typed.ActorRef; -import dev.freireservices.social_altruism.chat.events.Events; - -public class Commands { - public interface RoomCommand {} - - public record EnterPot(ActorRef replyTo) implements RoomCommand {} - - public record PlayTurn(ActorRef replyTo, double pot) implements RoomCommand {} - - // #chatroom-protocol - // #chatroom-behavior -} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/commands/PotRoomProtocol.java b/src/main/java/dev/freireservices/social_altruism/chat/commands/PotRoomProtocol.java new file mode 100644 index 0000000..2e09b2c --- /dev/null +++ b/src/main/java/dev/freireservices/social_altruism/chat/commands/PotRoomProtocol.java @@ -0,0 +1,32 @@ +package dev.freireservices.social_altruism.chat.commands; + +import akka.actor.typed.ActorRef; + +import java.util.List; + +import static dev.freireservices.social_altruism.chat.events.ParticipantProtocol.*; + +public class PotRoomProtocol { + public interface PotRoomMessage {} + + public record EnterPot(ActorRef replyTo) + implements PotRoomMessage {} + + public record StartSession( + ActorRef replyTo, + List> sessions) + implements PotRoomMessage {} + + public record ParticipateInTurn(String message) implements PotRoomMessage {} + + public record ShareReturnPotWithParticipants(double returnedAmount) implements PotRoomMessage {} + + public record PlayTurn( + //ActorRef chatRoom, + ActorRef replyTo, + double pot) + implements PotRoomMessage {} + + // #chatroom-protocol + // #chatroom-behavior +} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/events/Events.java b/src/main/java/dev/freireservices/social_altruism/chat/events/Events.java deleted file mode 100644 index 22ab9e6..0000000 --- a/src/main/java/dev/freireservices/social_altruism/chat/events/Events.java +++ /dev/null @@ -1,16 +0,0 @@ -package dev.freireservices.social_altruism.chat.events; - -import akka.actor.typed.ActorRef; -import dev.freireservices.social_altruism.chat.ChatPotProtocol; - -public class Events { - public interface SessionEvent {} - - public record SessionGranted(ActorRef handle) implements SessionEvent {} - - public record SessionDenied(String reason) implements SessionEvent {} - - public record PotReturned(ActorRef participant, double returnedAmount) implements SessionEvent {} - - -} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/events/ParticipantProtocol.java b/src/main/java/dev/freireservices/social_altruism/chat/events/ParticipantProtocol.java new file mode 100644 index 0000000..ba24671 --- /dev/null +++ b/src/main/java/dev/freireservices/social_altruism/chat/events/ParticipantProtocol.java @@ -0,0 +1,29 @@ +package dev.freireservices.social_altruism.chat.events; + +import akka.actor.typed.ActorRef; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol.PotRoomMessage; + +import java.util.List; + +public class ParticipantProtocol { + public interface ParticipantMessage {} + + public record SessionGranted( + ActorRef chatRoom, + ActorRef handle) + implements ParticipantMessage {} + + public record SessionStarted( + ActorRef replyTo, + List> participants) + implements ParticipantMessage {} + + public record SessionDenied(String reason) implements ParticipantMessage {} + + public record PotReturned( + ActorRef handle, + ActorRef participant, + double returnedAmount) + implements ParticipantMessage {} +} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/participant/Participant.java b/src/main/java/dev/freireservices/social_altruism/chat/participant/Participant.java new file mode 100644 index 0000000..4c078b9 --- /dev/null +++ b/src/main/java/dev/freireservices/social_altruism/chat/participant/Participant.java @@ -0,0 +1,171 @@ +package dev.freireservices.social_altruism.chat.participant; + +import static dev.freireservices.social_altruism.chat.participant.ParticipantType.*; +import static dev.freireservices.social_altruism.chat.participant.ParticipantType.JUSTICIERO; + +import akka.actor.typed.ActorRef; +import akka.actor.typed.Behavior; +import akka.actor.typed.javadsl.ActorContext; +import akka.actor.typed.javadsl.Behaviors; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol.ParticipateInTurn; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol.PotRoomMessage; +import dev.freireservices.social_altruism.chat.events.ParticipantProtocol; +import java.security.SecureRandom; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class Participant { + + private final ActorContext context; + private ActorRef chatRoom; + + private boolean collaborateSwitch; + private int currentTurn; + private double coins; + private final double initialCoins; + private int participantNumber; + private int totalTurns; + private final ParticipantType participantType; + + private Participant( + ActorContext context, + double coins, + ParticipantType participantType) { + this.context = context; + this.coins = coins; + this.initialCoins = coins; + this.participantType = participantType; + this.collaborateSwitch = participantType == JUSTICIERO || participantType == SANTO; + } + + public static Behavior create( + int initialCoins, ParticipantType participantType) { + return Behaviors.setup(ctx -> new Participant(ctx, initialCoins, participantType).behavior()); + } + + public void decrementCoins(double coins) { + this.coins -= coins; + } + + public void incrementCoins(double coins) { + this.coins += coins; + } + + private Behavior behavior() { + return Behaviors.receive(ParticipantProtocol.ParticipantMessage.class) + .onMessage(ParticipantProtocol.SessionStarted.class, this::onSessionStarted) + .onMessage(ParticipantProtocol.SessionDenied.class, this::onSessionDenied) + .onMessage(ParticipantProtocol.SessionGranted.class, this::onSessionGranted) + .onMessage(ParticipantProtocol.PotReturned.class, this::onPotReturned) + .build(); + } + + private Behavior onSessionDenied( + ParticipantProtocol.SessionDenied message) { + context.getLog().info("cannot start chat room session: {}", message.reason()); + return Behaviors.stopped(); + } + + private Behavior onSessionGranted( + ParticipantProtocol.SessionGranted message) { + setChatRoom(message.chatRoom()); + return Behaviors.same(); + } + + private Behavior onSessionStarted( + ParticipantProtocol.SessionStarted startSession) { + resetCurrentTurn(); + setParticipantNumber(startSession.participants().size()); + playTurn(startSession.replyTo()); + + context.getLog().info("Session started with {} participants", startSession.participants()); + return Behaviors.same(); + } + + private void playTurn(ActorRef replyTo) { + if (getCoins() > 0 && getCurrentTurn() < getTotalTurns()) { + replyTo.tell(new PotRoomProtocol.PlayTurn(context.getSelf(), getCurrentTurnParticipation())); + incrementCurrentTurn(); + } + } + + private double getCurrentTurnParticipation() { + var currentTurnCoins = getRandomNumberBetween(0, Math.floor(getCoins())); + decrementCoins(currentTurnCoins); + return currentTurnCoins; + } + + public static double getRandomNumberBetween(double min, double max) { + SecureRandom secureRandom = new SecureRandom(); + return secureRandom.nextDouble(max - min) + min; + } + + private Behavior onPotReturned( + ParticipantProtocol.PotReturned potReturned) { + context.getLog().info("Pot returned: {}", potReturned.returnedAmount()); + incrementCoins(potReturned.returnedAmount()); + + context + .getLog() + .info( + "Player {} has now {} coins; started with {} for a total profit of: {} %", + potReturned.participant().path().name(), + getCoins(), + getInitialCoins(), + calculateProfit()); + + // Still game? + if (getCoins() > 0) { + playTurn(potReturned.handle()); + } else { + context + .getLog() + .info( + "Player {} has now {} coins; started with {} for a total profit of: {} %", + potReturned.participant().path().name(), + getCoins(), + getInitialCoins(), + calculateProfit()); + + return Behaviors.stopped(); + } + adjustBehaviour(potReturned); + return Behaviors.same(); + } + + private void adjustBehaviour(ParticipantProtocol.PotReturned potReturned) { + + switch (participantType) { + case SANTO: + setCollaborateSwitch(true); + break; + case PICARO: + setCollaborateSwitch(false); + break; + case JUSTICIERO: + // Tweak minimum amount to collaborate + setCollaborateSwitch(potReturned.returnedAmount() > getParticipantNumber()); + break; + } + } + + public void participant() { + ActorRef handle; + // return this; + } + + public void resetCurrentTurn() { + setCurrentTurn(0); + } + + public void incrementCurrentTurn() { + setCurrentTurn(this.currentTurn++); + } + + private double calculateProfit() { + return Math.round((getCoins() * 100) / getInitialCoins() - 100); + } +} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/participant/ParticipantType.java b/src/main/java/dev/freireservices/social_altruism/chat/participant/ParticipantType.java new file mode 100644 index 0000000..eb1c374 --- /dev/null +++ b/src/main/java/dev/freireservices/social_altruism/chat/participant/ParticipantType.java @@ -0,0 +1,8 @@ +package dev.freireservices.social_altruism.chat.participant; + +public enum ParticipantType { + SANTO, + JUSTICIERO, + PICARO, + +} diff --git a/src/main/java/dev/freireservices/social_altruism/chat/potroom/PotRoom.java b/src/main/java/dev/freireservices/social_altruism/chat/potroom/PotRoom.java new file mode 100644 index 0000000..4c8fb22 --- /dev/null +++ b/src/main/java/dev/freireservices/social_altruism/chat/potroom/PotRoom.java @@ -0,0 +1,184 @@ +package dev.freireservices.social_altruism.chat.potroom; + +import static java.nio.charset.StandardCharsets.*; + +import akka.actor.typed.ActorRef; +import akka.actor.typed.Behavior; +import akka.actor.typed.javadsl.ActorContext; +import akka.actor.typed.javadsl.Behaviors; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol.PotRoomMessage; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol.ShareReturnPotWithParticipants; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol.StartSession; +import dev.freireservices.social_altruism.chat.events.ParticipantProtocol; +import dev.freireservices.social_altruism.chat.events.ParticipantProtocol.ParticipantMessage; +import lombok.Getter; + +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.List; + +@Getter +public class PotRoom { + private final ActorContext context; + private final List> participants; + + private double currentPot = 0.0; + private int currentTurn = 0; + private int totalTurns = 0; + private int participantsInTurn = 0; + private final int numberOfParticipants; + + private PotRoom( + ActorContext context, + List> participants, + int numberOfParticipants, + int turns) { + this.context = context; + this.participants = participants; + this.numberOfParticipants = numberOfParticipants; + this.totalTurns = turns; + } + + public void resetPot() { + this.currentPot = 0; + } + + public void addToPot(double pot) { + this.currentPot += pot; + } + + public void incrementParticipantsInTurn() { + this.participantsInTurn++; + } + + public void resetParticipantsInTurn() { + this.participantsInTurn = 0; + } + + public int incrementCurrentTurnAndGet() { + this.currentTurn++; + return this.currentTurn; + } + + // #chatroom-behavior + // #chatroom-protocol + + private Behavior onGetPotSession( + ActorRef chatRoom, PotRoomProtocol.EnterPot enterPot) { + + validate(enterPot); + + context.getLog().info("Participant joined {} pot", enterPot.replyTo().path().name()); + + ActorRef client = enterPot.replyTo(); + + ActorRef session = + context.spawn( + Session.create(chatRoom, client), + URLEncoder.encode(enterPot.replyTo().path().name(), UTF_8)); + + client.tell(new ParticipantProtocol.SessionGranted(chatRoom,session.narrow())); + + participants.add(session); + + if (getNumberOfParticipants() == participants.size()) { + context.getLog().info("All participants joined; pot is ready to start."); + + // Communicate session start and share pot info with all participants + chatRoom.tell(new StartSession(enterPot.replyTo(), participants)); + + return createPotBehaviour(chatRoom); + } else { + // Waiting for more participants + context.getLog().info("Waiting for more participants."); + return Behaviors.same(); + } + } + + private void validate(PotRoomProtocol.EnterPot enterPot) { + // Add check session started + if (participants.stream() + .anyMatch( + s -> + s.path() + .name() + .equals(URLEncoder.encode(enterPot.replyTo().path().name(), UTF_8)))) { + + enterPot.replyTo().tell(new ParticipantProtocol.SessionDenied("Can only enter a pot once")); + } + } + + private Behavior onPlayTurn(PotRoomProtocol.PlayTurn playTurn) { + context + .getLog() + .info( + "Participant joined for turn {} with {}", + //playTurn.replyTo().path().name(), + currentTurn, + playTurn.pot()); + + // Add to current pot + addToPot(playTurn.pot()); + incrementParticipantsInTurn(); + + if (getParticipantsInTurn() == numberOfParticipants) { + + double amountToShare = (getCurrentPot() * 2) / numberOfParticipants; + participants.forEach(s -> s.tell(new ShareReturnPotWithParticipants(amountToShare))); + + resetPot(); + resetParticipantsInTurn(); + + context.getLog().info("Turn {} complete", getCurrentTurn()); + + if (incrementCurrentTurnAndGet() == totalTurns) { + context.getLog().info("All turns completed"); + return Behaviors.stopped(); + } + } + return Behaviors.same(); + } + + private Behavior createPotBehaviour(ActorRef chatRoom) { + return Behaviors.receive(PotRoomMessage.class) + .onMessage(PotRoomProtocol.EnterPot.class, x -> onGetPotSession(chatRoom, x)) + .onMessage(PotRoomProtocol.PlayTurn.class, this::onPlayTurn) + .build(); + } + + public static Behavior create(int numberOfParticipants, int turns) { + return Behaviors.setup( + ctx -> + new PotRoom(ctx, new ArrayList<>(), numberOfParticipants, turns) + .createPotBehaviour(ctx.getSelf())); + } + + static class Session { + static Behavior create( + ActorRef chatRoom, ActorRef client) { + return Behaviors.receive(PotRoomMessage.class) + .onMessage( + ShareReturnPotWithParticipants.class, + sharePot -> onSharePotWithParticipants(chatRoom, client, sharePot.returnedAmount())) + .onMessage( + StartSession.class, + (startSession) -> onSessionStarted(startSession.replyTo(), startSession.sessions())) + .build(); + } + + private static Behavior onSessionStarted( + ActorRef replyTo, List> participants) { + participants.forEach(s -> s.tell(new StartSession(replyTo, participants))); + return Behaviors.same(); + } + + private static Behavior onSharePotWithParticipants( + ActorRef chatRoom, + ActorRef participant, + double returnedAmount) { + participant.tell(new ParticipantProtocol.PotReturned(chatRoom, participant, returnedAmount)); + return Behaviors.same(); + } + } +} diff --git a/src/test/java/dev/freireservices/social_altruism/chat/ChatQuickStartTest.java b/src/test/java/dev/freireservices/social_altruism/chat/ChatQuickStartTest.java deleted file mode 100644 index fc92c52..0000000 --- a/src/test/java/dev/freireservices/social_altruism/chat/ChatQuickStartTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package dev.freireservices.social_altruism.chat; - -import akka.actor.testkit.typed.javadsl.ActorTestKit; -import akka.actor.testkit.typed.javadsl.TestProbe; -import akka.actor.typed.ActorRef; -import dev.freireservices.social_altruism.chat.commands.Commands; -import dev.freireservices.social_altruism.chat.events.Events; -import java.time.Duration; -import org.junit.Test; - -// #definition -public class ChatQuickStartTest { - - // #definition - - // #test - @Test - // FIXME - Improve or delete.. - public void testCooperationCaseOne() { - - final ActorTestKit testKit = ActorTestKit.create(); - - TestProbe testProbe = testKit.createTestProbe(); - - ActorRef chatRoomTest = - testKit.spawn(ChatPotProtocol.create(2, 1), "chatRoom"); - - ActorRef participanteUno = - testKit.spawn(Participante.create(100), "participanteUno"); - - ActorRef participanteDos = - testKit.spawn(Participante.create(10), "participanteDos"); - - ActorRef participanteTres = - testKit.spawn(Participante.create(100), "participanteTres"); - - ActorRef participanteCuatro = - testKit.spawn(Participante.create(10), "participanteCuatro"); - - // Enter POT - - chatRoomTest.tell(new Commands.EnterPot(participanteUno)); - chatRoomTest.tell(new Commands.EnterPot(participanteDos)); - - chatRoomTest.tell(new Commands.EnterPot(participanteTres)); - chatRoomTest.tell(new Commands.EnterPot(participanteCuatro)); - - // Turnos - chatRoomTest.tell(new Commands.PlayTurn(participanteUno, 1)); - chatRoomTest.tell(new Commands.PlayTurn(participanteDos, 2)); - chatRoomTest.tell(new Commands.PlayTurn(participanteTres, 3)); - chatRoomTest.tell(new Commands.PlayTurn(participanteCuatro, 4)); - - // #assert - // #assert - - } - - @Test - public void testActorGetsUserDenied() { - final ActorTestKit testKit = ActorTestKit.create(); - TestProbe testProbe = testKit.createTestProbe(); - - ActorRef chatRoomTest = - testKit.spawn(ChatPotProtocol.create(2, 1), "chatRoom"); - - chatRoomTest.tell(new Commands.EnterPot(testProbe.ref())); - - testProbe.expectMessageClass(Events.SessionGranted.class, Duration.ofSeconds(10)); - - chatRoomTest.tell(new Commands.EnterPot(testProbe.ref())); - - Events.SessionDenied sessionDenied = - new Events.SessionDenied("Can only enter a pot once"); - - testProbe.expectMessage(Duration.ofSeconds(10), sessionDenied); - - // #assert - } -} diff --git a/src/test/java/dev/freireservices/social_altruism/chat/PotQuickStartTest.java b/src/test/java/dev/freireservices/social_altruism/chat/PotQuickStartTest.java new file mode 100644 index 0000000..e829d72 --- /dev/null +++ b/src/test/java/dev/freireservices/social_altruism/chat/PotQuickStartTest.java @@ -0,0 +1,73 @@ +package dev.freireservices.social_altruism.chat; + +import static dev.freireservices.social_altruism.chat.participant.ParticipantType.*; + +import akka.actor.testkit.typed.javadsl.ActorTestKit; +import akka.actor.testkit.typed.javadsl.TestProbe; +import akka.actor.typed.ActorRef; +import dev.freireservices.social_altruism.chat.commands.PotRoomProtocol; +import dev.freireservices.social_altruism.chat.events.ParticipantProtocol; +import dev.freireservices.social_altruism.chat.participant.Participant; +import dev.freireservices.social_altruism.chat.potroom.PotRoom; +import java.time.Duration; +import java.util.List; +import org.junit.Test; + +// #definition +public class PotQuickStartTest { + + // #definition + + // #test + @Test + // FIXME - Improve or delete.. + public void testCooperationCaseOne() { + + final ActorTestKit testKit = ActorTestKit.create(); + + ActorRef chatRoomTest = + testKit.spawn(PotRoom.create(3, 1), "potRoom"); + + ActorRef p1 = testKit.spawn(Participant.create(100, PICARO), "PICARO-1"); + + ActorRef p2 = testKit.spawn(Participant.create(100, JUSTICIERO), "JUSTICIERO-1"); + + ActorRef p3 = testKit.spawn(Participant.create(10, SANTO), "SANTO-1"); + + final List> sessions = List.of(p1, p2, p3); + + // Enter POT + chatRoomTest.tell(new PotRoomProtocol.EnterPot(p1)); + chatRoomTest.tell(new PotRoomProtocol.EnterPot(p2)); + chatRoomTest.tell(new PotRoomProtocol.EnterPot(p3)); + + // Turnos + chatRoomTest.tell(new PotRoomProtocol.PlayTurn(p1,0)); + chatRoomTest.tell(new PotRoomProtocol.PlayTurn(p2,1)); + chatRoomTest.tell(new PotRoomProtocol.PlayTurn(p3, 3)); + + // #assert + // #assert + + } + + @Test + public void testActorGetsUserDenied() { + final ActorTestKit testKit = ActorTestKit.create(); + TestProbe testProbe = testKit.createTestProbe("TestProbe"); + + ActorRef chatRoomTest = + testKit.spawn(PotRoom.create(2, 1), "chatRoom"); + + chatRoomTest.tell(new PotRoomProtocol.EnterPot(testProbe.ref())); + + testProbe.expectMessageClass(ParticipantProtocol.SessionGranted.class, Duration.ofSeconds(10)); + + chatRoomTest.tell(new PotRoomProtocol.EnterPot(testProbe.ref())); + + testProbe.expectMessage( + Duration.ofSeconds(10), new ParticipantProtocol.SessionDenied("Can only enter a pot once")); + + // #assert + } +} diff --git a/target/app-1.0.jar b/target/app-1.0.jar deleted file mode 100644 index 83dea82..0000000 Binary files a/target/app-1.0.jar and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$ParticipateInTurn.class b/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$ParticipateInTurn.class deleted file mode 100644 index 110c86f..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$ParticipateInTurn.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$Session.class b/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$Session.class deleted file mode 100644 index 040a414..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$Session.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$SessionCommand.class b/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$SessionCommand.class deleted file mode 100644 index 66a9db4..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$SessionCommand.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$SharePotWithParticipants.class b/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$SharePotWithParticipants.class deleted file mode 100644 index b4ab40d..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol$SharePotWithParticipants.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol.class b/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol.class deleted file mode 100644 index 210abc4..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/ChatPotProtocol.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/ChatQuickStart$Main.class b/target/classes/dev/freireservices/social_altruism/chat/ChatQuickStart$Main.class deleted file mode 100644 index b85a450..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/ChatQuickStart$Main.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/ChatQuickStart.class b/target/classes/dev/freireservices/social_altruism/chat/ChatQuickStart.class deleted file mode 100644 index f23f601..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/ChatQuickStart.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/Participante.class b/target/classes/dev/freireservices/social_altruism/chat/Participante.class deleted file mode 100644 index 50901fe..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/Participante.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/commands/Commands$EnterPot.class b/target/classes/dev/freireservices/social_altruism/chat/commands/Commands$EnterPot.class deleted file mode 100644 index a29b006..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/commands/Commands$EnterPot.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/commands/Commands$PlayTurn.class b/target/classes/dev/freireservices/social_altruism/chat/commands/Commands$PlayTurn.class deleted file mode 100644 index 592fa31..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/commands/Commands$PlayTurn.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/commands/Commands$RoomCommand.class b/target/classes/dev/freireservices/social_altruism/chat/commands/Commands$RoomCommand.class deleted file mode 100644 index c2c21b5..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/commands/Commands$RoomCommand.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/commands/Commands.class b/target/classes/dev/freireservices/social_altruism/chat/commands/Commands.class deleted file mode 100644 index c019d43..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/commands/Commands.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/events/Events$PotReturned.class b/target/classes/dev/freireservices/social_altruism/chat/events/Events$PotReturned.class deleted file mode 100644 index 456cab7..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/events/Events$PotReturned.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/events/Events$SessionDenied.class b/target/classes/dev/freireservices/social_altruism/chat/events/Events$SessionDenied.class deleted file mode 100644 index 25246fa..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/events/Events$SessionDenied.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/events/Events$SessionEvent.class b/target/classes/dev/freireservices/social_altruism/chat/events/Events$SessionEvent.class deleted file mode 100644 index 67f3be3..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/events/Events$SessionEvent.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/events/Events$SessionGranted.class b/target/classes/dev/freireservices/social_altruism/chat/events/Events$SessionGranted.class deleted file mode 100644 index a07e9b9..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/events/Events$SessionGranted.class and /dev/null differ diff --git a/target/classes/dev/freireservices/social_altruism/chat/events/Events.class b/target/classes/dev/freireservices/social_altruism/chat/events/Events.class deleted file mode 100644 index d317bba..0000000 Binary files a/target/classes/dev/freireservices/social_altruism/chat/events/Events.class and /dev/null differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index 6667767..aab51e7 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,3 +1,3 @@ -artifactId=app +artifactId=SocialAltruism groupId=hello-akka-java version=1.0 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 3a2e51c..b1377cd 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1,16 +1,20 @@ -dev/freireservices/social_altruism/chat/ChatPotProtocol$PotReturned.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$Session.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$EnterPot.class -dev/freireservices/social_altruism/chat/ChatQuickStart.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$SessionGranted.class -dev/freireservices/social_altruism/chat/ChatQuickStart$Main.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$SharePotWithParticipants.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$MessagePosted.class -dev/freireservices/social_altruism/chat/Participante.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$SessionEvent.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$SessionCommand.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$ParticipateInTurn.class -dev/freireservices/social_altruism/chat/ChatPotProtocol.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$UpdatePlayerAfterTurn.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$RoomCommand.class -dev/freireservices/social_altruism/chat/ChatPotProtocol$SessionDenied.class +dev/freireservices/social_altruism/chat/commands/PotRoomProtocol$PotRoomMessage.class +dev/freireservices/social_altruism/chat/events/ParticipantProtocol$ParticipantMessage.class +dev/freireservices/social_altruism/chat/participant/ParticipantType.class +dev/freireservices/social_altruism/chat/commands/PotRoomProtocol$ParticipateInTurn.class +dev/freireservices/social_altruism/chat/events/ParticipantProtocol$SessionStarted.class +dev/freireservices/social_altruism/chat/events/ParticipantProtocol.class +dev/freireservices/social_altruism/chat/PotQuickStart.class +dev/freireservices/social_altruism/chat/commands/PotRoomProtocol.class +dev/freireservices/social_altruism/chat/commands/PotRoomProtocol$EnterPot.class +dev/freireservices/social_altruism/chat/PotQuickStart$Main.class +dev/freireservices/social_altruism/chat/potroom/PotRoom.class +dev/freireservices/social_altruism/chat/events/ParticipantProtocol$SessionGranted.class +dev/freireservices/social_altruism/chat/events/ParticipantProtocol$SessionDenied.class +dev/freireservices/social_altruism/chat/commands/PotRoomProtocol$SharePotWithParticipants.class +dev/freireservices/social_altruism/chat/participant/Participant.class +dev/freireservices/social_altruism/chat/commands/PotRoomProtocol$PlayTurn.class +dev/freireservices/social_altruism/chat/potroom/PotRoom$Session.class +dev/freireservices/social_altruism/chat/commands/PotRoomProtocol$StartSession.class +dev/freireservices/social_altruism/chat/events/ParticipantProtocol$PotReturned.class +dev/freireservices/social_altruism/chat/participant/Participant$1.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index b7effec..08603a0 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1,3 +1,6 @@ -/Users/rdev/Source/social_altruism_akka/src/main/java/dev/freireservices/social_altruism/chat/ChatQuickStart.java -/Users/rdev/Source/social_altruism_akka/src/main/java/dev/freireservices/social_altruism/chat/ChatPotProtocol.java -/Users/rdev/Source/social_altruism_akka/src/main/java/dev/freireservices/social_altruism/chat/Participante.java +/Users/rdev/Source/social_altruism_akka/src/main/java/dev/freireservices/social_altruism/chat/potroom/PotRoom.java +/Users/rdev/Source/social_altruism_akka/src/main/java/dev/freireservices/social_altruism/chat/commands/PotRoomProtocol.java +/Users/rdev/Source/social_altruism_akka/src/main/java/dev/freireservices/social_altruism/chat/events/ParticipantProtocol.java +/Users/rdev/Source/social_altruism_akka/src/main/java/dev/freireservices/social_altruism/chat/participant/Participant.java +/Users/rdev/Source/social_altruism_akka/src/main/java/dev/freireservices/social_altruism/chat/PotQuickStart.java +/Users/rdev/Source/social_altruism_akka/src/main/java/dev/freireservices/social_altruism/chat/participant/ParticipantType.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst index 0f63274..deb7792 100644 --- a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst @@ -1 +1 @@ -dev/freireservices/social_altruism/chat/ChatQuickStartTest.class +dev/freireservices/social_altruism/chat/PotQuickStartTest.class diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst index 62f7eca..2a8f773 100644 --- a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst @@ -1 +1 @@ -/Users/rdev/Source/social_altruism_akka/src/test/java/dev/freireservices/social_altruism/chat/ChatQuickStartTest.java +/Users/rdev/Source/social_altruism_akka/src/test/java/dev/freireservices/social_altruism/chat/PotQuickStartTest.java diff --git a/target/surefire-reports/TEST-com.example.AkkaQuickstartTest.xml b/target/surefire-reports/TEST-com.example.AkkaQuickstartTest.xml deleted file mode 100644 index 11eeca3..0000000 --- a/target/surefire-reports/TEST-com.example.AkkaQuickstartTest.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/surefire-reports/TEST-dev.freireservices.social_altruism.chat.ChatQuickStartTest.xml b/target/surefire-reports/TEST-dev.freireservices.social_altruism.chat.ChatQuickStartTest.xml deleted file mode 100644 index c75837c..0000000 --- a/target/surefire-reports/TEST-dev.freireservices.social_altruism.chat.ChatQuickStartTest.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/target/surefire-reports/com.example.AkkaQuickstartTest.txt b/target/surefire-reports/com.example.AkkaQuickstartTest.txt deleted file mode 100644 index 61c871e..0000000 --- a/target/surefire-reports/com.example.AkkaQuickstartTest.txt +++ /dev/null @@ -1,4 +0,0 @@ -------------------------------------------------------------------------------- -Test set: dev.freireservices.social_altruism.chat.ChatQuickStartTest -------------------------------------------------------------------------------- -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.387 s -- in dev.freireservices.social_altruism.chat.ChatQuickStartTest diff --git a/target/surefire-reports/dev.freireservices.social_altruism.chat.ChatQuickStartTest.txt b/target/surefire-reports/dev.freireservices.social_altruism.chat.ChatQuickStartTest.txt deleted file mode 100644 index 3a81013..0000000 --- a/target/surefire-reports/dev.freireservices.social_altruism.chat.ChatQuickStartTest.txt +++ /dev/null @@ -1,4 +0,0 @@ -------------------------------------------------------------------------------- -Test set: dev.freireservices.social_altruism.chat.ChatQuickStartTest -------------------------------------------------------------------------------- -Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.155 s -- in dev.freireservices.social_altruism.chat.ChatQuickStartTest diff --git a/target/test-classes/dev/freireservices/social_altruism/chat/ChatQuickStartTest.class b/target/test-classes/dev/freireservices/social_altruism/chat/ChatQuickStartTest.class deleted file mode 100644 index 5cb271f..0000000 Binary files a/target/test-classes/dev/freireservices/social_altruism/chat/ChatQuickStartTest.class and /dev/null differ