use of org.opendaylight.controller.cluster.datastore.messages.FindLocalShard in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindLocalShardForExistentShard.
@Test
public void testOnReceiveFindLocalShardForExistentShard() throws Exception {
new TestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), mockShardActor);
shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
LocalShardFound found = expectMsgClass(duration("5 seconds"), LocalShardFound.class);
assertTrue("Found path contains " + found.getPath().path().toString(), found.getPath().path().toString().contains("member-1-shard-default-config"));
}
};
}
use of org.opendaylight.controller.cluster.datastore.messages.FindLocalShard in project controller by opendaylight.
the class ShardManagerTest method testOnCreateShardWithLocalMemberNotInShardConfig.
@Test
public void testOnCreateShardWithLocalMemberNotInShardConfig() {
LOG.info("testOnCreateShardWithLocalMemberNotInShardConfig starting");
new TestKit(getSystem()) {
{
datastoreContextBuilder.shardInitializationTimeout(1, TimeUnit.MINUTES).persistent(true);
ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), ActorRef.noSender());
Shard.Builder shardBuilder = Shard.builder();
ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-5", "member-6"));
shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
expectMsgClass(duration("5 seconds"), Success.class);
shardManager.tell(new FindLocalShard("foo", true), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
assertEquals("peerMembers size", 0, shardBuilder.getPeerAddresses().size());
assertEquals("schemaContext", DisableElectionsRaftPolicy.class.getName(), shardBuilder.getDatastoreContext().getShardRaftConfig().getCustomRaftPolicyImplementationClass());
}
};
LOG.info("testOnCreateShardWithLocalMemberNotInShardConfig ending");
}
use of org.opendaylight.controller.cluster.datastore.messages.FindLocalShard in project controller by opendaylight.
the class ShardManagerTest method testOnCreateShardWithNoInitialSchemaContext.
@Test
public void testOnCreateShardWithNoInitialSchemaContext() {
LOG.info("testOnCreateShardWithNoInitialSchemaContext starting");
new TestKit(getSystem()) {
{
ActorRef shardManager = actorFactory.createActor(newShardMgrProps(new ConfigurationImpl(new EmptyModuleShardConfigProvider())).withDispatcher(Dispatchers.DefaultDispatcherId()));
Shard.Builder shardBuilder = Shard.builder();
ModuleShardConfiguration config = new ModuleShardConfiguration(URI.create("foo-ns"), "foo-module", "foo", null, members("member-1"));
shardManager.tell(new CreateShard(config, shardBuilder, null), getRef());
expectMsgClass(duration("5 seconds"), Success.class);
SchemaContext schemaContext = TestModel.createTestContext();
shardManager.tell(new UpdateSchemaContext(schemaContext), ActorRef.noSender());
shardManager.tell(new FindLocalShard("foo", true), getRef());
expectMsgClass(duration("5 seconds"), LocalShardFound.class);
assertSame("schemaContext", schemaContext, shardBuilder.getSchemaContext());
assertNotNull("schemaContext is null", shardBuilder.getDatastoreContext());
}
};
LOG.info("testOnCreateShardWithNoInitialSchemaContext ending");
}
use of org.opendaylight.controller.cluster.datastore.messages.FindLocalShard in project controller by opendaylight.
the class ShardManagerTest method testServerRemovedShardActorNotRunning.
@Test
public void testServerRemovedShardActorNotRunning() throws Exception {
LOG.info("testServerRemovedShardActorNotRunning starting");
new TestKit(getSystem()) {
{
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("default", Arrays.asList("member-1", "member-2")).put("astronauts", Arrays.asList("member-2")).put("people", Arrays.asList("member-1", "member-2")).build());
TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newShardMgrProps(mockConfig).withDispatcher(Dispatchers.DefaultDispatcherId()));
shardManager.underlyingActor().waitForRecoveryComplete();
shardManager.tell(new FindLocalShard("people", false), getRef());
expectMsgClass(duration("5 seconds"), NotInitializedException.class);
shardManager.tell(new FindLocalShard("default", false), getRef());
expectMsgClass(duration("5 seconds"), NotInitializedException.class);
// Removed the default shard replica from member-1
ShardIdentifier.Builder builder = new ShardIdentifier.Builder();
ShardIdentifier shardId = builder.shardName("default").memberName(MEMBER_1).type(shardMrgIDSuffix).build();
shardManager.tell(new ServerRemoved(shardId.toString()), getRef());
shardManager.underlyingActor().verifySnapshotPersisted(Sets.newHashSet("people"));
}
};
LOG.info("testServerRemovedShardActorNotRunning ending");
}
use of org.opendaylight.controller.cluster.datastore.messages.FindLocalShard in project controller by opendaylight.
the class ShardManagerTest method testAddShardReplicaWithAddServerReplyFailure.
@Test
public void testAddShardReplicaWithAddServerReplyFailure() throws Exception {
LOG.info("testAddShardReplicaWithAddServerReplyFailure starting");
new TestKit(getSystem()) {
{
TestKit mockShardLeaderKit = new TestKit(getSystem());
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder().put("astronauts", Arrays.asList("member-2")).build());
ActorRef mockNewReplicaShardActor = newMockShardActor(getSystem(), "astronauts", "member-1");
final TestActorRef<TestShardManager> shardManager = actorFactory.createTestActor(newTestShardMgrBuilder(mockConfig).shardActor(mockNewReplicaShardActor).props().withDispatcher(Dispatchers.DefaultDispatcherId()), shardMgrID);
shardManager.underlyingActor().setMessageInterceptor(newFindPrimaryInterceptor(mockShardLeaderKit.getRef()));
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
TestKit terminateWatcher = new TestKit(getSystem());
terminateWatcher.watch(mockNewReplicaShardActor);
shardManager.tell(new AddShardReplica("astronauts"), getRef());
AddServer addServerMsg = mockShardLeaderKit.expectMsgClass(AddServer.class);
assertEquals("AddServer serverId", "member-1-shard-astronauts-" + shardMrgIDSuffix, addServerMsg.getNewServerId());
mockShardLeaderKit.reply(new AddServerReply(ServerChangeStatus.TIMEOUT, null));
Failure failure = expectMsgClass(duration("5 seconds"), Failure.class);
assertEquals("Failure cause", TimeoutException.class, failure.cause().getClass());
shardManager.tell(new FindLocalShard("astronauts", false), getRef());
expectMsgClass(duration("5 seconds"), LocalShardNotFound.class);
terminateWatcher.expectTerminated(mockNewReplicaShardActor);
shardManager.tell(new AddShardReplica("astronauts"), getRef());
mockShardLeaderKit.expectMsgClass(AddServer.class);
mockShardLeaderKit.reply(new AddServerReply(ServerChangeStatus.NO_LEADER, null));
failure = expectMsgClass(duration("5 seconds"), Failure.class);
assertEquals("Failure cause", NoShardLeaderException.class, failure.cause().getClass());
}
};
LOG.info("testAddShardReplicaWithAddServerReplyFailure ending");
}
Aggregations