use of akka.actor.ActorRef in project controller by opendaylight.
the class IntegrationTestKit method findLocalShard.
public static ActorRef findLocalShard(final ActorContext actorContext, final String shardName) {
ActorRef shard = null;
for (int i = 0; i < 20 * 5 && shard == null; i++) {
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
Optional<ActorRef> shardReply = actorContext.findLocalShard(shardName);
if (shardReply.isPresent()) {
shard = shardReply.get();
}
}
return shard;
}
use of akka.actor.ActorRef in project controller by opendaylight.
the class IntegrationTestKit method verifyShardState.
public static void verifyShardState(final AbstractDataStore datastore, final String shardName, final Consumer<OnDemandShardState> verifier) throws Exception {
ActorContext actorContext = datastore.getActorContext();
Future<ActorRef> future = actorContext.findLocalShardAsync(shardName);
ActorRef shardActor = Await.result(future, Duration.create(10, TimeUnit.SECONDS));
AssertionError lastError = null;
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
OnDemandShardState shardState = (OnDemandShardState) actorContext.executeOperation(shardActor, GetOnDemandRaftState.INSTANCE);
try {
verifier.accept(shardState);
return;
} catch (AssertionError e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
use of akka.actor.ActorRef in project controller by opendaylight.
the class RemoteTransactionContextTest method sendReply.
private void sendReply(final Object message) {
final ActorRef askActor = kit.getLastSender();
kit.watch(askActor);
kit.reply(new Failure(new IllegalStateException()));
kit.expectTerminated(askActor);
}
use of akka.actor.ActorRef in project controller by opendaylight.
the class MeteredBoundedMailboxTest method shouldSendMsgToDeadLetterWhenQueueIsFull.
@Test
public void shouldSendMsgToDeadLetterWhenQueueIsFull() throws InterruptedException {
final TestKit mockReceiver = new TestKit(actorSystem);
actorSystem.eventStream().subscribe(mockReceiver.testActor(), DeadLetter.class);
final FiniteDuration twentySeconds = new FiniteDuration(20, TimeUnit.SECONDS);
ActorRef pingPongActor = actorSystem.actorOf(PingPongActor.props(lock).withMailbox(config.getMailBoxName()), "pingpongactor");
actorSystem.mailboxes().settings();
lock.lock();
try {
// 12th message is sent to dead letter.
for (int i = 0; i < 12; i++) {
pingPongActor.tell("ping", mockReceiver.testActor());
}
mockReceiver.expectMsgClass(twentySeconds, DeadLetter.class);
} finally {
lock.unlock();
}
mockReceiver.receiveN(11, twentySeconds);
}
use of akka.actor.ActorRef in project controller by opendaylight.
the class LeaderTest method setupIsolatedLeaderCheckTestWithTwoFollowers.
private RaftActorBehavior setupIsolatedLeaderCheckTestWithTwoFollowers(final RaftPolicy raftPolicy) {
ActorRef followerActor1 = getSystem().actorOf(MessageCollectorActor.props(), "follower-1");
ActorRef followerActor2 = getSystem().actorOf(MessageCollectorActor.props(), "follower-2");
MockRaftActorContext leaderActorContext = createActorContext();
Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put("follower-1", followerActor1.path().toString());
peerAddresses.put("follower-2", followerActor2.path().toString());
leaderActorContext.setPeerAddresses(peerAddresses);
leaderActorContext.setRaftPolicy(raftPolicy);
leader = new Leader(leaderActorContext);
leader.markFollowerActive("follower-1");
leader.markFollowerActive("follower-2");
RaftActorBehavior newBehavior = leader.handleMessage(leaderActor, Leader.ISOLATED_LEADER_CHECK);
assertTrue("Behavior not instance of Leader when all followers are active", newBehavior instanceof Leader);
// kill 1 follower and verify if that got killed
final TestKit probe = new TestKit(getSystem());
probe.watch(followerActor1);
followerActor1.tell(PoisonPill.getInstance(), ActorRef.noSender());
final Terminated termMsg1 = probe.expectMsgClass(Terminated.class);
assertEquals(termMsg1.getActor(), followerActor1);
leader.markFollowerInActive("follower-1");
leader.markFollowerActive("follower-2");
newBehavior = leader.handleMessage(leaderActor, Leader.ISOLATED_LEADER_CHECK);
assertTrue("Behavior not instance of Leader when majority of followers are active", newBehavior instanceof Leader);
// kill 2nd follower and leader should change to Isolated leader
followerActor2.tell(PoisonPill.getInstance(), null);
probe.watch(followerActor2);
followerActor2.tell(PoisonPill.getInstance(), ActorRef.noSender());
final Terminated termMsg2 = probe.expectMsgClass(Terminated.class);
assertEquals(termMsg2.getActor(), followerActor2);
leader.markFollowerInActive("follower-2");
return leader.handleMessage(leaderActor, Leader.ISOLATED_LEADER_CHECK);
}
Aggregations