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());
}
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));
}
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);
}
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());
}
}
};
}
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");
}
Aggregations