Search in sources :

Example 81 with ActorRef

use of akka.actor.ActorRef in project controller by opendaylight.

the class TransactionProxyTest method testReadyWithReadWrite.

@Test
public void testReadyWithReadWrite() throws Exception {
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
    final NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    doReturn(readDataReply(null)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqReadData(), any(Timeout.class));
    expectBatchedModificationsReady(actorRef, true);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    transactionProxy.read(TestModel.TEST_PATH);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
    assertTrue(ready instanceof SingleCommitCohortProxy);
    verifyCohortFutures((SingleCommitCohortProxy) ready, new CommitTransactionReply().toSerializable());
    List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
    assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
    verifyBatchedModifications(batchedModifications.get(0), true, true, new WriteModification(TestModel.TEST_PATH, nodeToWrite));
    assertEquals("getTotalMessageCount", 1, batchedModifications.get(0).getTotalMessagesSent());
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) CommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 82 with ActorRef

use of akka.actor.ActorRef in project controller by opendaylight.

the class TransactionProxyTest method testExistsWithPriorRecordingOperationSuccessful.

@Test
public void testExistsWithPriorRecordingOperationSuccessful() throws Exception {
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE);
    NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    expectBatchedModifications(actorRef, 1);
    doReturn(dataExistsReply(true)).when(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class));
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);
    transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
    Boolean exists = transactionProxy.exists(TestModel.TEST_PATH).checkedGet();
    assertEquals("Exists response", true, exists);
    InOrder inOrder = Mockito.inOrder(mockActorContext);
    inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), isA(BatchedModifications.class), any(Timeout.class));
    inOrder.verify(mockActorContext).executeOperationAsync(eq(actorSelection(actorRef)), eqDataExists(), any(Timeout.class));
}
Also used : InOrder(org.mockito.InOrder) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 83 with ActorRef

use of akka.actor.ActorRef in project controller by opendaylight.

the class TransactionProxyTest method testDelete.

@Test
public void testDelete() throws Exception {
    dataStoreContextBuilder.shardBatchedModificationCount(1);
    ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY);
    expectBatchedModifications(actorRef, 1);
    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
    transactionProxy.delete(TestModel.TEST_PATH);
    verifyOneBatchedModification(actorRef, new DeleteModification(TestModel.TEST_PATH), false);
}
Also used : ActorRef(akka.actor.ActorRef) DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) NormalizedNodeAggregatorTest(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest) Test(org.junit.Test)

Example 84 with ActorRef

use of akka.actor.ActorRef in project controller by opendaylight.

the class ShardSnapshotActorTest method testSerializeSnapshot.

private static void testSerializeSnapshot(final String testName, final ShardDataTreeSnapshot snapshot, final boolean withInstallSnapshot) throws Exception {
    new TestKit(getSystem()) {

        {
            final ActorRef snapshotActor = getSystem().actorOf(ShardSnapshotActor.props(), testName);
            watch(snapshotActor);
            final NormalizedNode<?, ?> expectedRoot = snapshot.getRootNode().get();
            ByteArrayOutputStream installSnapshotStream = withInstallSnapshot ? new ByteArrayOutputStream() : null;
            ShardSnapshotActor.requestSnapshot(snapshotActor, snapshot, Optional.ofNullable(installSnapshotStream), getRef());
            final CaptureSnapshotReply reply = expectMsgClass(duration("3 seconds"), CaptureSnapshotReply.class);
            assertNotNull("getSnapshotState is null", reply.getSnapshotState());
            assertEquals("SnapshotState type", ShardSnapshotState.class, reply.getSnapshotState().getClass());
            assertEquals("Snapshot", snapshot, ((ShardSnapshotState) reply.getSnapshotState()).getSnapshot());
            if (installSnapshotStream != null) {
                final ShardDataTreeSnapshot deserialized;
                try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(installSnapshotStream.toByteArray()))) {
                    deserialized = ShardDataTreeSnapshot.deserialize(in);
                }
                assertEquals("Deserialized snapshot type", snapshot.getClass(), deserialized.getClass());
                final Optional<NormalizedNode<?, ?>> maybeNode = deserialized.getRootNode();
                assertEquals("isPresent", true, maybeNode.isPresent());
                assertEquals("Root node", expectedRoot, maybeNode.get());
            }
        }
    };
}
Also used : CaptureSnapshotReply(org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply) ShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) ByteArrayInputStream(java.io.ByteArrayInputStream) ActorRef(akka.actor.ActorRef) TestKit(akka.testkit.javadsl.TestKit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ObjectInputStream(java.io.ObjectInputStream)

Example 85 with ActorRef

use of akka.actor.ActorRef in project controller by opendaylight.

the class DistributedEntityOwnershipIntegrationTest method testLeaderEntityOwnersReassignedAfterShutdown.

@Test
public void testLeaderEntityOwnersReassignedAfterShutdown() throws Exception {
    followerDatastoreContextBuilder.shardElectionTimeoutFactor(5).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
    String name = "testLeaderEntityOwnersReassignedAfterShutdown";
    MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
    MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    MemberNode follower2Node = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
    AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
    leaderDistributedDataStore.waitTillReady();
    follower1Node.configDataStore().waitTillReady();
    follower2Node.configDataStore().waitTillReady();
    follower1Node.waitForMembersUp("member-1", "member-3");
    final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
    final DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
    final DOMEntityOwnershipService follower2EntityOwnershipService = newOwnershipService(follower2Node.configDataStore());
    leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    // Register follower1 candidate for entity1 and verify it becomes owner
    follower1EntityOwnershipService.registerCandidate(ENTITY1);
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-2");
    // Register leader candidate for entity1
    leaderEntityOwnershipService.registerCandidate(ENTITY1);
    verifyCandidates(leaderDistributedDataStore, ENTITY1, "member-2", "member-1");
    verifyOwner(leaderDistributedDataStore, ENTITY1, "member-2");
    // Register leader candidate for entity2 and verify it becomes owner
    leaderEntityOwnershipService.registerCandidate(ENTITY2);
    verifyOwner(leaderDistributedDataStore, ENTITY2, "member-1");
    // Register follower2 candidate for entity2
    follower2EntityOwnershipService.registerCandidate(ENTITY2);
    verifyCandidates(leaderDistributedDataStore, ENTITY2, "member-1", "member-3");
    verifyOwner(leaderDistributedDataStore, ENTITY2, "member-1");
    // Re-enable elections on all remaining followers so one becomes the new leader
    ActorRef follower1Shard = IntegrationTestKit.findLocalShard(follower1Node.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    follower1Shard.tell(DatastoreContext.newBuilderFrom(followerDatastoreContextBuilder.build()).customRaftPolicyImplementation(null).build(), ActorRef.noSender());
    ActorRef follower2Shard = IntegrationTestKit.findLocalShard(follower2Node.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
    follower2Shard.tell(DatastoreContext.newBuilderFrom(followerDatastoreContextBuilder.build()).customRaftPolicyImplementation(null).build(), ActorRef.noSender());
    // Shutdown the leader and verify its removed from the candidate list
    leaderNode.cleanup();
    follower1Node.waitForMemberDown("member-1");
    follower2Node.waitForMemberDown("member-1");
    // Verify the prior leader's entity owners are re-assigned.
    verifyCandidates(follower1Node.configDataStore(), ENTITY1, "member-2", "member-1");
    verifyCandidates(follower1Node.configDataStore(), ENTITY2, "member-1", "member-3");
    verifyOwner(follower1Node.configDataStore(), ENTITY1, "member-2");
    verifyOwner(follower1Node.configDataStore(), ENTITY2, "member-3");
}
Also used : DOMEntityOwnershipService(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService) MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) ActorRef(akka.actor.ActorRef) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) Test(org.junit.Test)

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