use of akka.actor.Status.Failure in project controller by opendaylight.
the class RemoteTransactionContextTest method testLimiterOnOverflowFailure.
/**
* OperationLimiter gives up throttling at some point -- {@link RemoteTransactionContext} needs to deal with that
* case, too.
*/
@Test
public void testLimiterOnOverflowFailure() throws TimeoutException, InterruptedException {
txContext.executeModification(DELETE);
txContext.executeModification(DELETE);
txContext.executeModification(DELETE);
txContext.executeModification(DELETE);
assertEquals(0, limiter.availablePermits());
txContext.executeModification(DELETE);
// Last acquire should have failed ...
assertEquals(0, limiter.availablePermits());
Future<Object> future = txContext.sendBatchedModifications();
assertEquals(0, limiter.availablePermits());
BatchedModifications msg = kit.expectMsgClass(BatchedModifications.class);
// ... so we are sending 5 modifications ...
assertEquals(5, msg.getModifications().size());
assertEquals(1, msg.getTotalMessagesSent());
sendReply(new Failure(new NullPointerException()));
assertFuture(future, new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object success) {
assertTrue(failure instanceof NullPointerException);
// ... but they account for only 4 permits.
assertEquals(4, limiter.availablePermits());
}
});
kit.expectNoMsg();
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class RaftActorTest method testGetSnapshot.
@Test
public void testGetSnapshot() throws Exception {
TEST_LOG.info("testGetSnapshot starting");
final TestKit kit = new TestKit(getSystem());
String persistenceId = factory.generateActorId("test-actor-");
DefaultConfigParamsImpl config = new DefaultConfigParamsImpl();
config.setCustomRaftPolicyImplementationClass(DisableElectionsRaftPolicy.class.getName());
long term = 3;
long seqN = 1;
InMemoryJournal.addEntry(persistenceId, seqN++, new UpdateElectionTerm(term, "member-1"));
InMemoryJournal.addEntry(persistenceId, seqN++, new SimpleReplicatedLogEntry(0, term, new MockRaftActorContext.MockPayload("A")));
InMemoryJournal.addEntry(persistenceId, seqN++, new SimpleReplicatedLogEntry(1, term, new MockRaftActorContext.MockPayload("B")));
InMemoryJournal.addEntry(persistenceId, seqN++, new ApplyJournalEntries(1));
InMemoryJournal.addEntry(persistenceId, seqN++, new SimpleReplicatedLogEntry(2, term, new MockRaftActorContext.MockPayload("C")));
TestActorRef<MockRaftActor> raftActorRef = factory.createTestActor(MockRaftActor.props(persistenceId, ImmutableMap.<String, String>builder().put("member1", "address").build(), config).withDispatcher(Dispatchers.DefaultDispatcherId()), persistenceId);
MockRaftActor mockRaftActor = raftActorRef.underlyingActor();
mockRaftActor.waitForRecoveryComplete();
mockRaftActor.snapshotCohortDelegate = mock(RaftActorSnapshotCohort.class);
raftActorRef.tell(GetSnapshot.INSTANCE, kit.getRef());
ArgumentCaptor<ActorRef> replyActor = ArgumentCaptor.forClass(ActorRef.class);
verify(mockRaftActor.snapshotCohortDelegate, timeout(5000)).createSnapshot(replyActor.capture(), eq(java.util.Optional.empty()));
byte[] stateSnapshot = new byte[] { 1, 2, 3 };
replyActor.getValue().tell(new CaptureSnapshotReply(ByteState.of(stateSnapshot), java.util.Optional.empty()), ActorRef.noSender());
GetSnapshotReply reply = kit.expectMsgClass(GetSnapshotReply.class);
assertEquals("getId", persistenceId, reply.getId());
Snapshot replySnapshot = reply.getSnapshot();
assertEquals("getElectionTerm", term, replySnapshot.getElectionTerm());
assertEquals("getElectionVotedFor", "member-1", replySnapshot.getElectionVotedFor());
assertEquals("getLastAppliedIndex", 1L, replySnapshot.getLastAppliedIndex());
assertEquals("getLastAppliedTerm", term, replySnapshot.getLastAppliedTerm());
assertEquals("getLastIndex", 2L, replySnapshot.getLastIndex());
assertEquals("getLastTerm", term, replySnapshot.getLastTerm());
assertEquals("getState", ByteState.of(stateSnapshot), replySnapshot.getState());
assertEquals("getUnAppliedEntries size", 1, replySnapshot.getUnAppliedEntries().size());
assertEquals("UnApplied entry index ", 2L, replySnapshot.getUnAppliedEntries().get(0).getIndex());
// Test with timeout
mockRaftActor.getSnapshotMessageSupport().setSnapshotReplyActorTimeout(Duration.create(200, TimeUnit.MILLISECONDS));
reset(mockRaftActor.snapshotCohortDelegate);
raftActorRef.tell(GetSnapshot.INSTANCE, kit.getRef());
Failure failure = kit.expectMsgClass(akka.actor.Status.Failure.class);
assertEquals("Failure cause type", TimeoutException.class, failure.cause().getClass());
mockRaftActor.getSnapshotMessageSupport().setSnapshotReplyActorTimeout(Duration.create(30, TimeUnit.SECONDS));
// Test with persistence disabled.
mockRaftActor.setPersistence(false);
reset(mockRaftActor.snapshotCohortDelegate);
raftActorRef.tell(GetSnapshot.INSTANCE, kit.getRef());
reply = kit.expectMsgClass(GetSnapshotReply.class);
verify(mockRaftActor.snapshotCohortDelegate, never()).createSnapshot(anyObject(), anyObject());
assertEquals("getId", persistenceId, reply.getId());
replySnapshot = reply.getSnapshot();
assertEquals("getElectionTerm", term, replySnapshot.getElectionTerm());
assertEquals("getElectionVotedFor", "member-1", replySnapshot.getElectionVotedFor());
assertEquals("getLastAppliedIndex", -1L, replySnapshot.getLastAppliedIndex());
assertEquals("getLastAppliedTerm", -1L, replySnapshot.getLastAppliedTerm());
assertEquals("getLastIndex", -1L, replySnapshot.getLastIndex());
assertEquals("getLastTerm", -1L, replySnapshot.getLastTerm());
assertEquals("getState type", EmptyState.INSTANCE, replySnapshot.getState());
assertEquals("getUnAppliedEntries size", 0, replySnapshot.getUnAppliedEntries().size());
TEST_LOG.info("testGetSnapshot ending");
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardManagerGetSnapshotReplyActorTest method testGetSnapshotFailureReply.
@Test
public void testGetSnapshotFailureReply() {
TestKit kit = new TestKit(getSystem());
ActorRef replyActor = getSystem().actorOf(ShardManagerGetSnapshotReplyActor.props(Arrays.asList("shard1", "shard2"), "config", null, kit.getRef(), "shard-manager", Duration.create(100, TimeUnit.SECONDS)), "testGetSnapshotFailureReply");
kit.watch(replyActor);
replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard1", MEMBER_1, "config").toString(), Snapshot.create(ByteState.of(new byte[] { 1, 2, 3 }), Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());
replyActor.tell(new Failure(new RuntimeException()), ActorRef.noSender());
kit.expectMsgClass(Failure.class);
kit.expectTerminated(replyActor);
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardManagerTest method testGetSnapshot.
@Test
public void testGetSnapshot() throws Exception {
LOG.info("testGetSnapshot starting");
TestKit kit = new TestKit(getSystem());
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("shard1", Arrays.asList("member-1")).put("shard2", Arrays.asList("member-1")).put("astronauts", Collections.<String>emptyList()).build());
TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newShardMgrProps(mockConfig).withDispatcher(Dispatchers.DefaultDispatcherId()));
shardManager.tell(GetSnapshot.INSTANCE, kit.getRef());
Failure failure = kit.expectMsgClass(Failure.class);
assertEquals("Failure cause type", IllegalStateException.class, failure.cause().getClass());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), ActorRef.noSender());
waitForShardInitialized(shardManager, "shard1", kit);
waitForShardInitialized(shardManager, "shard2", kit);
shardManager.tell(GetSnapshot.INSTANCE, kit.getRef());
DatastoreSnapshot datastoreSnapshot = expectMsgClassOrFailure(DatastoreSnapshot.class, kit, "GetSnapshot");
assertEquals("getType", shardMrgIDSuffix, datastoreSnapshot.getType());
assertNull("Expected null ShardManagerSnapshot", datastoreSnapshot.getShardManagerSnapshot());
Function<ShardSnapshot, String> shardNameTransformer = ShardSnapshot::getName;
assertEquals("Shard names", Sets.newHashSet("shard1", "shard2"), Sets.newHashSet(Lists.transform(datastoreSnapshot.getShardSnapshots(), shardNameTransformer)));
// Add a new replica
TestKit mockShardLeaderKit = new TestKit(getSystem());
TestShardManager shardManagerInstance = shardManager.underlyingActor();
shardManagerInstance.setMessageInterceptor(newFindPrimaryInterceptor(mockShardLeaderKit.getRef()));
shardManager.tell(new AddShardReplica("astronauts"), kit.getRef());
mockShardLeaderKit.expectMsgClass(AddServer.class);
mockShardLeaderKit.reply(new AddServerReply(ServerChangeStatus.OK, ""));
kit.expectMsgClass(Status.Success.class);
waitForShardInitialized(shardManager, "astronauts", kit);
// Send another GetSnapshot and verify
shardManager.tell(GetSnapshot.INSTANCE, kit.getRef());
datastoreSnapshot = expectMsgClassOrFailure(DatastoreSnapshot.class, kit, "GetSnapshot");
assertEquals("Shard names", Sets.newHashSet("shard1", "shard2", "astronauts"), Sets.newHashSet(Lists.transform(datastoreSnapshot.getShardSnapshots(), shardNameTransformer)));
ShardManagerSnapshot snapshot = datastoreSnapshot.getShardManagerSnapshot();
assertNotNull("Expected ShardManagerSnapshot", snapshot);
assertEquals("Shard names", Sets.newHashSet("shard1", "shard2", "astronauts"), Sets.newHashSet(snapshot.getShardList()));
LOG.info("testGetSnapshot ending");
}
use of akka.actor.Status.Failure in project controller by opendaylight.
the class ShardManagerTest method testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader.
@Test
public void testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader() throws Exception {
LOG.info("testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader starting");
new TestKit(getSystem()) {
{
TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newPropsShardMgrWithMockShardActor(), shardMgrID);
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
String leaderId = "leader-member-shard-default-" + shardMrgIDSuffix;
AddServerReply addServerReply = new AddServerReply(ServerChangeStatus.ALREADY_EXISTS, null);
ActorRef leaderShardActor = shardManager.underlyingActor().getContext().actorOf(Props.create(MockRespondActor.class, AddServer.class, addServerReply), leaderId);
MockClusterWrapper.sendMemberUp(shardManager, "leader-member", leaderShardActor.path().toString());
String newReplicaId = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.tell(new RoleChangeNotification(newReplicaId, RaftState.Candidate.name(), RaftState.Follower.name()), mockShardActor);
shardManager.tell(new ShardLeaderStateChanged(newReplicaId, leaderId, DataStoreVersions.CURRENT_VERSION), mockShardActor);
shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
MessageCollectorActor.expectFirstMatching(leaderShardActor, AddServer.class);
Failure resp = expectMsgClass(duration("5 seconds"), Failure.class);
assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
// Send message again to verify previous in progress state is
// cleared
shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
resp = expectMsgClass(duration("5 seconds"), Failure.class);
assertEquals("Failure cause", AlreadyExistsException.class, resp.cause().getClass());
// Send message again with an AddServer timeout to verify the
// pre-existing shard actor isn't terminated.
shardManager.tell(newDatastoreContextFactory(datastoreContextBuilder.shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build()), getRef());
leaderShardActor.tell(MockRespondActor.CLEAR_RESPONSE, ActorRef.noSender());
shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
expectMsgClass(duration("5 seconds"), Failure.class);
shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
}
};
LOG.info("testAddShardReplicaWithPreExistingReplicaInRemoteShardLeader ending");
}
Aggregations