Search in sources :

Example 91 with ActorRef

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;
}
Also used : ActorRef(akka.actor.ActorRef)

Example 92 with ActorRef

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;
}
Also used : ActorRef(akka.actor.ActorRef) Stopwatch(com.google.common.base.Stopwatch) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) OnDemandShardState(org.opendaylight.controller.cluster.datastore.messages.OnDemandShardState)

Example 93 with ActorRef

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);
}
Also used : ActorRef(akka.actor.ActorRef) Failure(akka.actor.Status.Failure)

Example 94 with ActorRef

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);
}
Also used : ActorRef(akka.actor.ActorRef) FiniteDuration(scala.concurrent.duration.FiniteDuration) TestKit(akka.testkit.TestKit) Test(org.junit.Test)

Example 95 with ActorRef

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);
}
Also used : HashMap(java.util.HashMap) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) MockRaftActorContext(org.opendaylight.controller.cluster.raft.MockRaftActorContext) ByteString(com.google.protobuf.ByteString) TestKit(akka.testkit.javadsl.TestKit) Terminated(akka.actor.Terminated)

Aggregations

ActorRef (akka.actor.ActorRef)383 Test (org.junit.Test)253 TestActorRef (akka.testkit.TestActorRef)124 TestKit (akka.testkit.javadsl.TestKit)84 ActorSystem (akka.actor.ActorSystem)55 FiniteDuration (scala.concurrent.duration.FiniteDuration)53 Props (akka.actor.Props)46 Timeout (akka.util.Timeout)43 Configuration (org.apache.flink.configuration.Configuration)42 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)38 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)37 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)33 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)30 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)26 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)26 AddressFromURIString (akka.actor.AddressFromURIString)24 ArrayList (java.util.ArrayList)22 JobID (org.apache.flink.api.common.JobID)22 IOException (java.io.IOException)21 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)20