Skip to content

Commit

Permalink
🐛 fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sanshengshui committed Sep 13, 2021
1 parent ff7cfd7 commit 7988a96
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -55,6 +56,28 @@ public void test1actorsAnd100KMessages() throws InterruptedException {
testActorsAndMessages(1, _100K, 1);
}

@Test
public void testFailedInit() throws InterruptedException {
actorSystem.createDispatcher(ROOT_DISPATCHER, Executors.newWorkStealingPool(parallelism));
ActorTestCtx testCtx1 = getActorTestCtx(1);
ActorTestCtx testCtx2 = getActorTestCtx(1);

ActorRef actorId1 = actorSystem.createRootActor(ROOT_DISPATCHER,
new FailedToInitActor.FailedToInitActorCreator(
new EntityActorId(UUID.randomUUID().toString()), testCtx1, 1, 3000));
ActorRef actorId2 = actorSystem.createRootActor(ROOT_DISPATCHER,
new FailedToInitActor.FailedToInitActorCreator(
new EntityActorId(UUID.randomUUID().toString()), testCtx2, 2, 1));

actorId1.tell(new IntActorMsg(42));
actorId2.tell(new IntActorMsg(42));

Assert.assertFalse(testCtx1.getLatch().await(2, TimeUnit.SECONDS));
Assert.assertFalse(testCtx1.getLatch().await(1, TimeUnit.SECONDS));
Assert.assertFalse(testCtx1.getLatch().await(3, TimeUnit.SECONDS));
}


public void testActorsAndMessages(int actorsCount, int msgNumber, int times) throws InterruptedException {
Random random = new Random();
int[] randomIntegers = new int[msgNumber];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public boolean process(ActorMsg msg) {
sum += value;
count += 1;
if (count == testCtx.getExpectedInvocationCount()) {
testCtx.getActual().set(sum);
testCtx.getInvocationCount().addAndGet(count);
sum = 0;
count = 0;
testCtx.getLatch().countDown();
}
testCtx.getActual().set(sum);
testCtx.getInvocationCount().addAndGet(count);
sum = 0;
count = 0;
testCtx.getLatch().countDown();
}
return true;
}
Expand Down

0 comments on commit 7988a96

Please sign in to comment.