Search in sources :

Example 56 with TestActorRef

use of akka.testkit.TestActorRef in project controller by opendaylight.

the class ShardTest method testRegisterDataTreeChangeListener.

@Test
public void testRegisterDataTreeChangeListener() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testRegisterDataTreeChangeListener");
            waitUntilLeader(shard);
            shard.tell(new UpdateSchemaContext(SchemaContextHelper.full()), ActorRef.noSender());
            final MockDataTreeChangeListener listener = new MockDataTreeChangeListener(1);
            final ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, TestModel.TEST_PATH), "testRegisterDataTreeChangeListener-DataTreeChangeListener");
            shard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, false), getRef());
            final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("3 seconds"), RegisterDataTreeNotificationListenerReply.class);
            final String replyPath = reply.getListenerRegistrationPath().toString();
            assertTrue("Incorrect reply path: " + replyPath, replyPath.matches("akka:\\/\\/test\\/user\\/testRegisterDataTreeChangeListener\\/\\$.*"));
            final YangInstanceIdentifier path = TestModel.TEST_PATH;
            writeToStore(shard, path, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
            listener.waitForChangeEvents();
        }
    };
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) MockDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RegisterDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 57 with TestActorRef

use of akka.testkit.TestActorRef in project controller by opendaylight.

the class ShardTest method testClusteredDataChangeListenerRegistration.

@Test
public void testClusteredDataChangeListenerRegistration() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final String testName = "testClusteredDataChangeListenerRegistration";
            final ShardIdentifier followerShardID = ShardIdentifier.create("inventory", MemberName.forName(actorFactory.generateActorId(testName + "-follower")), "config");
            final ShardIdentifier leaderShardID = ShardIdentifier.create("inventory", MemberName.forName(actorFactory.generateActorId(testName + "-leader")), "config");
            final TestActorRef<Shard> followerShard = actorFactory.createTestActor(Shard.builder().id(followerShardID).datastoreContext(dataStoreContextBuilder.shardElectionTimeoutFactor(1000).build()).peerAddresses(Collections.singletonMap(leaderShardID.toString(), "akka://test/user/" + leaderShardID.toString())).schemaContextProvider(() -> SCHEMA_CONTEXT).props().withDispatcher(Dispatchers.DefaultDispatcherId()), followerShardID.toString());
            final TestActorRef<Shard> leaderShard = actorFactory.createTestActor(Shard.builder().id(leaderShardID).datastoreContext(newDatastoreContext()).peerAddresses(Collections.singletonMap(followerShardID.toString(), "akka://test/user/" + followerShardID.toString())).schemaContextProvider(() -> SCHEMA_CONTEXT).props().withDispatcher(Dispatchers.DefaultDispatcherId()), leaderShardID.toString());
            leaderShard.tell(TimeoutNow.INSTANCE, ActorRef.noSender());
            final String leaderPath = waitUntilLeader(followerShard);
            assertEquals("Shard leader path", leaderShard.path().toString(), leaderPath);
            final YangInstanceIdentifier path = TestModel.TEST_PATH;
            final MockDataChangeListener listener = new MockDataChangeListener(1);
            final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener, path), actorFactory.generateActorId(testName + "-DataChangeListener"));
            followerShard.tell(new RegisterChangeListener(path, dclActor, AsyncDataBroker.DataChangeScope.BASE, true), getRef());
            final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), RegisterDataTreeNotificationListenerReply.class);
            assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath());
            writeToStore(followerShard, path, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
            listener.waitForChangeEvents();
        }
    };
}
Also used : RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) MockDataChangeListener(org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener) RegisterChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 58 with TestActorRef

use of akka.testkit.TestActorRef in project controller by opendaylight.

the class ShardTest method testRegisterRoleChangeListener.

@Test
public void testRegisterRoleChangeListener() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testRegisterRoleChangeListener");
            waitUntilLeader(shard);
            final ActorRef listener = getSystem().actorOf(MessageCollectorActor.props());
            shard.tell(new RegisterRoleChangeListener(), listener);
            MessageCollectorActor.expectFirstMatching(listener, RegisterRoleChangeListenerReply.class);
            ShardLeaderStateChanged leaderStateChanged = MessageCollectorActor.expectFirstMatching(listener, ShardLeaderStateChanged.class);
            assertEquals("getLocalShardDataTree present", true, leaderStateChanged.getLocalShardDataTree().isPresent());
            assertSame("getLocalShardDataTree", shard.underlyingActor().getDataStore().getDataTree(), leaderStateChanged.getLocalShardDataTree().get());
            MessageCollectorActor.clearMessages(listener);
            // Force a leader change
            shard.tell(new RequestVote(10000, "member2", 50, 50), getRef());
            leaderStateChanged = MessageCollectorActor.expectFirstMatching(listener, ShardLeaderStateChanged.class);
            assertEquals("getLocalShardDataTree present", false, leaderStateChanged.getLocalShardDataTree().isPresent());
        }
    };
}
Also used : RegisterRoleChangeListener(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener) ShardLeaderStateChanged(org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) RequestVote(org.opendaylight.controller.cluster.raft.messages.RequestVote) Test(org.junit.Test)

Example 59 with TestActorRef

use of akka.testkit.TestActorRef in project controller by opendaylight.

the class ShardTransactionFailureTest method testNegativeReadWithReadOnlyTransactionClosed.

@Test(expected = ReadFailedException.class)
public void testNegativeReadWithReadOnlyTransactionClosed() throws Exception {
    final ActorRef shard = createShard();
    final Props props = ShardTransaction.props(RO, STORE.newReadOnlyTransaction(nextTransactionId()), shard, datastoreContext, shardStats);
    final TestActorRef<ShardTransaction> subject = TestActorRef.create(getSystem(), props, "testNegativeReadWithReadOnlyTransactionClosed");
    Future<Object> future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
    Await.result(future, Duration.create(3, TimeUnit.SECONDS));
    subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor();
    future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
    Await.result(future, Duration.create(3, TimeUnit.SECONDS));
}
Also used : TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) Props(akka.actor.Props) ReadData(org.opendaylight.controller.cluster.datastore.messages.ReadData) Test(org.junit.Test)

Example 60 with TestActorRef

use of akka.testkit.TestActorRef in project controller by opendaylight.

the class ShardTransactionFailureTest method testNegativeReadWithReadWriteTransactionClosed.

@Test(expected = ReadFailedException.class)
public void testNegativeReadWithReadWriteTransactionClosed() throws Exception {
    final ActorRef shard = createShard();
    final Props props = ShardTransaction.props(RW, STORE.newReadWriteTransaction(nextTransactionId()), shard, datastoreContext, shardStats);
    final TestActorRef<ShardTransaction> subject = TestActorRef.create(getSystem(), props, "testNegativeReadWithReadWriteTransactionClosed");
    Future<Object> future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
    Await.result(future, Duration.create(3, TimeUnit.SECONDS));
    subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor();
    future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
    Await.result(future, Duration.create(3, TimeUnit.SECONDS));
}
Also used : TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) Props(akka.actor.Props) ReadData(org.opendaylight.controller.cluster.datastore.messages.ReadData) Test(org.junit.Test)

Aggregations

ActorRef (akka.actor.ActorRef)65 TestActorRef (akka.testkit.TestActorRef)65 Test (org.junit.Test)64 FiniteDuration (scala.concurrent.duration.FiniteDuration)18 TestKit (akka.testkit.javadsl.TestKit)17 AddServer (org.opendaylight.controller.cluster.raft.messages.AddServer)14 AddServerReply (org.opendaylight.controller.cluster.raft.messages.AddServerReply)13 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)13 DisableElectionsRaftPolicy (org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy)12 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)11 ByteString (com.google.protobuf.ByteString)10 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)10 MockDataChangeListener (org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener)10 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)10 AddressFromURIString (akka.actor.AddressFromURIString)9 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)9 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)9 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)9 Follower (org.opendaylight.controller.cluster.raft.behaviors.Follower)9 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)8