use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardManagerTest method testChangeServersVotingStatusWithNoLeader.
@Test
public void testChangeServersVotingStatusWithNoLeader() throws Exception {
new TestKit(getSystem()) {
{
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
ActorRef respondActor = actorFactory.createActor(Props.create(MockRespondActor.class, ChangeServersVotingStatus.class, new ServerChangeReply(ServerChangeStatus.NO_LEADER, null)), memberId);
ActorRef shardManager = getSystem().actorOf(newPropsShardMgrWithMockShardActor(respondActor));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), respondActor);
shardManager.tell(new RoleChangeNotification(memberId, null, RaftState.Follower.name()), respondActor);
shardManager.tell(new ChangeShardMembersVotingStatus("default", ImmutableMap.of("member-2", Boolean.TRUE)), getRef());
MessageCollectorActor.expectFirstMatching(respondActor, ChangeServersVotingStatus.class);
Status.Failure resp = expectMsgClass(duration("5 seconds"), Status.Failure.class);
assertEquals("Failure resposnse", true, resp.cause() instanceof NoShardLeaderException);
}
};
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardTest method testBatchedModificationsWithOperationFailure.
@Test
public void testBatchedModificationsWithOperationFailure() throws Exception {
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsWithOperationFailure");
waitUntilLeader(shard);
// Test merge with invalid data. An exception should occur when
// the merge is applied. Note that
// write will not validate the children for performance reasons.
final TransactionIdentifier transactionID = nextTransactionId();
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION);
batched.addModification(new MergeModification(TestModel.TEST_PATH, invalidData));
shard.tell(batched, getRef());
Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
final Throwable cause = failure.cause();
batched = new BatchedModifications(transactionID, DataStoreVersions.CURRENT_VERSION);
batched.setReady(true);
batched.setTotalMessagesSent(2);
shard.tell(batched, getRef());
failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
assertEquals("Failure cause", cause, failure.cause());
}
};
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardTest method testTransactionMessagesWithNoLeader.
@Test
public void testTransactionMessagesWithNoLeader() {
new ShardTestKit(getSystem()) {
{
dataStoreContextBuilder.customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName()).shardHeartbeatIntervalInMillis(50).shardElectionTimeoutFactor(1);
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testTransactionMessagesWithNoLeader");
waitUntilNoLeader(shard);
final TransactionIdentifier txId = nextTransactionId();
shard.tell(new BatchedModifications(txId, DataStoreVersions.CURRENT_VERSION), getRef());
Failure failure = expectMsgClass(Failure.class);
assertEquals("Failure cause type", NoShardLeaderException.class, failure.cause().getClass());
shard.tell(prepareForwardedReadyTransaction(shard, txId, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), true), getRef());
failure = expectMsgClass(Failure.class);
assertEquals("Failure cause type", NoShardLeaderException.class, failure.cause().getClass());
shard.tell(new ReadyLocalTransaction(txId, mock(DataTreeModification.class), true), getRef());
failure = expectMsgClass(Failure.class);
assertEquals("Failure cause type", NoShardLeaderException.class, failure.cause().getClass());
}
};
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardTransactionTest method testOnReceiveBatchedModificationsFailure.
@Test(expected = TestException.class)
public void testOnReceiveBatchedModificationsFailure() throws Exception {
new TestKit(getSystem()) {
{
ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class);
DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
ReadWriteShardDataTreeTransaction mockWriteTx = new ReadWriteShardDataTreeTransaction(parent, nextTransactionId(), mockModification);
final ActorRef transaction = newTransactionActor(RW, mockWriteTx, "testOnReceiveBatchedModificationsFailure");
TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
YangInstanceIdentifier path = TestModel.TEST_PATH;
ContainerNode node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
doThrow(new TestException()).when(mockModification).write(path, node);
final TransactionIdentifier tx1 = nextTransactionId();
BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.addModification(new WriteModification(path, node));
transaction.tell(batched, getRef());
expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
batched.setReady(true);
batched.setTotalMessagesSent(2);
transaction.tell(batched, getRef());
Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
if (failure != null) {
Throwables.propagateIfPossible(failure.cause(), Exception.class);
throw new RuntimeException(failure.cause());
}
}
};
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class DistributedEntityOwnershipIntegrationTest method testEntityOwnershipShardBootstrapping.
/**
* Tests bootstrapping the entity-ownership shard when there's no shards initially configured for local
* member. The entity-ownership shard is initially created as inactive (ie remains a follower), requiring
* an AddShardReplica request to join it to an existing leader.
*/
@Test
public void testEntityOwnershipShardBootstrapping() throws Exception {
String name = "testEntityOwnershipShardBootstrapping";
String moduleShardsConfig = MODULE_SHARDS_MEMBER_1_CONFIG;
MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(moduleShardsConfig).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
AbstractDataStore follower1DistributedDataStore = follower1Node.configDataStore();
follower1DistributedDataStore.waitTillReady();
leaderNode.waitForMembersUp("member-2");
follower1Node.waitForMembersUp("member-1");
DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1DistributedDataStore);
leaderEntityOwnershipService.registerListener(ENTITY_TYPE1, leaderMockListener);
// Register a candidate for follower1 - should get queued since follower1 has no leader
final DOMEntityOwnershipCandidateRegistration candidateReg = follower1EntityOwnershipService.registerCandidate(ENTITY1);
Uninterruptibles.sleepUninterruptibly(300, TimeUnit.MILLISECONDS);
verify(leaderMockListener, never()).ownershipChanged(ownershipChange(ENTITY1));
// Add replica in follower1
AddShardReplica addReplica = new AddShardReplica(ENTITY_OWNERSHIP_SHARD_NAME);
follower1DistributedDataStore.getActorContext().getShardManager().tell(addReplica, follower1Node.kit().getRef());
Object reply = follower1Node.kit().expectMsgAnyClassOf(follower1Node.kit().duration("5 sec"), Success.class, Failure.class);
if (reply instanceof Failure) {
throw new AssertionError("AddShardReplica failed", ((Failure) reply).cause());
}
// The queued candidate registration should proceed
verify(leaderMockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
reset(leaderMockListener);
candidateReg.close();
verify(leaderMockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, false));
reset(leaderMockListener);
// Restart follower1 and verify the entity ownership shard is re-instated by registering.
Cluster.get(leaderNode.kit().getSystem()).down(Cluster.get(follower1Node.kit().getSystem()).selfAddress());
follower1Node.cleanup();
follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(moduleShardsConfig).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
follower1EntityOwnershipService.registerCandidate(ENTITY1);
verify(leaderMockListener, timeout(20000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
verifyRaftState(follower1Node.configDataStore(), ENTITY_OWNERSHIP_SHARD_NAME, raftState -> {
assertNull("Custom RaftPolicy class name", raftState.getCustomRaftPolicyClassName());
assertEquals("Peer count", 1, raftState.getPeerAddresses().keySet().size());
assertThat("Peer Id", Iterables.<String>getLast(raftState.getPeerAddresses().keySet()), org.hamcrest.CoreMatchers.containsString("member-1"));
});
}
Aggregations