use of org.opendaylight.controller.cluster.datastore.messages.FindLocalShard in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindLocalShardForNonExistentShard.
@Test
public void testOnReceiveFindLocalShardForNonExistentShard() throws Exception {
new TestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new FindLocalShard("non-existent", false), getRef());
LocalShardNotFound notFound = expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
assertEquals("getShardName", "non-existent", notFound.getShardName());
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.FindLocalShard in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindLocalShardWaitForShardInitialized.
@Test
public void testOnReceiveFindLocalShardWaitForShardInitialized() throws Exception {
LOG.info("testOnReceiveFindLocalShardWaitForShardInitialized starting");
new TestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
// We're passing waitUntilInitialized = true to FindLocalShard
// so the response should be
// delayed until we send ActorInitialized.
Future<Object> future = Patterns.ask(shardManager, new FindLocalShard(Shard.DEFAULT_NAME, true), new Timeout(5, TimeUnit.SECONDS));
shardManager.tell(new ActorInitialized(), mockShardActor);
Object resp = Await.result(future, duration("5 seconds"));
assertTrue("Expected: LocalShardFound, Actual: " + resp, resp instanceof LocalShardFound);
}
};
LOG.info("testOnReceiveFindLocalShardWaitForShardInitialized starting");
}
use of org.opendaylight.controller.cluster.datastore.messages.FindLocalShard in project controller by opendaylight.
the class ShardManagerTest method waitForShardInitialized.
private static void waitForShardInitialized(final ActorRef shardManager, final String shardName, final TestKit kit) {
AssertionError last = null;
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
try {
shardManager.tell(new FindLocalShard(shardName, true), kit.getRef());
kit.expectMsgClass(LocalShardFound.class);
return;
} catch (AssertionError e) {
last = e;
}
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
throw last;
}
use of org.opendaylight.controller.cluster.datastore.messages.FindLocalShard 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");
}
use of org.opendaylight.controller.cluster.datastore.messages.FindLocalShard in project controller by opendaylight.
the class ShardManagerTest method testAddShardReplicaWithPreExistingLocalReplicaLeader.
@Test
public void testAddShardReplicaWithPreExistingLocalReplicaLeader() throws Exception {
LOG.info("testAddShardReplicaWithPreExistingLocalReplicaLeader starting");
new TestKit(getSystem()) {
{
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mock(DataTree.class), DataStoreVersions.CURRENT_VERSION), getRef());
shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor);
shardManager.tell(new AddShardReplica(Shard.DEFAULT_NAME), getRef());
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);
}
};
LOG.info("testAddShardReplicaWithPreExistingLocalReplicaLeader ending");
}
Aggregations