Search in sources :

Example 1 with ShardStrategy

use of org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy in project controller by opendaylight.

the class ConfigurationImplTest method testGetStrategyForModule.

@Test
public void testGetStrategyForModule() {
    ShardStrategy strategy = configuration.getStrategyForModule("cars");
    assertNotNull("getStrategyForModule null", strategy);
    assertEquals("getStrategyForModule type", ModuleShardStrategy.class, strategy.getClass());
    strategy = configuration.getStrategyForModule("people");
    assertNotNull("getStrategyForModule null", strategy);
    assertEquals("getStrategyForModule type", ModuleShardStrategy.class, strategy.getClass());
    strategy = configuration.getStrategyForModule("default");
    assertNull("getStrategyForModule - expected null", strategy);
    strategy = configuration.getStrategyForModule("non-existent");
    assertNull("getStrategyForModule - expected null", strategy);
}
Also used : ShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy) ModuleShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ModuleShardStrategy) Test(org.junit.Test)

Example 2 with ShardStrategy

use of org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy in project controller by opendaylight.

the class ConfigurationImplTest method testRemoveMemberReplicaForShard.

@Test
public void testRemoveMemberReplicaForShard() {
    configuration.removeMemberReplicaForShard("default", MEMBER_2);
    String shardName = configuration.getShardNameForModule("default");
    assertEquals("ModuleShardName", "default", shardName);
    ShardStrategy shardStrategy = configuration.getStrategyForModule("default");
    assertNull("ModuleStrategy", shardStrategy);
    Collection<MemberName> members = configuration.getMembersFromShardName("default");
    assertEquals("Members", ImmutableSortedSet.of(MEMBER_1, MEMBER_3), ImmutableSortedSet.copyOf(members));
    configuration.removeMemberReplicaForShard("non-existent", MEMBER_2);
    Set<String> shardNames = configuration.getAllShardNames();
    assertEquals("ShardNames", ImmutableSortedSet.of("people-1", "cars-1", "test-1", "default"), ImmutableSortedSet.copyOf(shardNames));
}
Also used : ShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy) ModuleShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ModuleShardStrategy) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) Test(org.junit.Test)

Example 3 with ShardStrategy

use of org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy in project controller by opendaylight.

the class ConfigurationImplTest method testAddModuleShardConfiguration.

@Test
public void testAddModuleShardConfiguration() throws Exception {
    URI namespace = new URI("urn:opendaylight:test:oven");
    String moduleName = "oven";
    String shardName = "oven-shard";
    String shardStrategyName = ModuleShardStrategy.NAME;
    Collection<MemberName> shardMemberNames = ImmutableSortedSet.of(MEMBER_1, MEMBER_4, MEMBER_5);
    configuration.addModuleShardConfiguration(new ModuleShardConfiguration(namespace, moduleName, shardName, shardStrategyName, shardMemberNames));
    assertEquals("getMemberShardNames", ImmutableSortedSet.of("people-1", "cars-1", "test-1", "default", shardName), ImmutableSortedSet.copyOf(configuration.getMemberShardNames(MEMBER_1)));
    assertEquals("getMemberShardNames", ImmutableSortedSet.of(shardName), ImmutableSortedSet.copyOf(configuration.getMemberShardNames(MEMBER_4)));
    assertEquals("getMemberShardNames", ImmutableSortedSet.of(shardName), ImmutableSortedSet.copyOf(configuration.getMemberShardNames(MEMBER_5)));
    assertEquals("getMembersFromShardName", shardMemberNames, ImmutableSortedSet.copyOf(configuration.getMembersFromShardName(shardName)));
    assertEquals("getShardNameForModule", shardName, configuration.getShardNameForModule(moduleName));
    assertEquals("getModuleNameFromNameSpace", moduleName, configuration.getModuleNameFromNameSpace(namespace.toASCIIString()));
    assertEquals("getAllShardNames", ImmutableSortedSet.of("people-1", "cars-1", "test-1", "default", shardName), ImmutableSortedSet.copyOf(configuration.getAllShardNames()));
    ShardStrategy strategy = configuration.getStrategyForModule("cars");
    assertNotNull("getStrategyForModule null", strategy);
    assertEquals("getStrategyForModule type", ModuleShardStrategy.class, strategy.getClass());
}
Also used : ShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy) ModuleShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ModuleShardStrategy) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) URI(java.net.URI) Test(org.junit.Test)

Example 4 with ShardStrategy

use of org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy in project controller by opendaylight.

the class ConfigurationImplTest method testAddMemberReplicaForShard.

@Test
public void testAddMemberReplicaForShard() {
    configuration.addMemberReplicaForShard("people-1", MEMBER_2);
    String shardName = configuration.getShardNameForModule("people");
    assertEquals("ModuleShardName", "people-1", shardName);
    ShardStrategy shardStrategy = configuration.getStrategyForModule("people");
    assertEquals("ModuleStrategy", ModuleShardStrategy.class, shardStrategy.getClass());
    Collection<MemberName> members = configuration.getMembersFromShardName("people-1");
    assertEquals("Members", ImmutableSortedSet.of(MEMBER_1, MEMBER_2), ImmutableSortedSet.copyOf(members));
    configuration.addMemberReplicaForShard("non-existent", MEMBER_2);
    Set<String> shardNames = configuration.getAllShardNames();
    assertEquals("ShardNames", ImmutableSortedSet.of("people-1", "cars-1", "test-1", "default"), ImmutableSortedSet.copyOf(shardNames));
}
Also used : ShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy) ModuleShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ModuleShardStrategy) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) Test(org.junit.Test)

Example 5 with ShardStrategy

use of org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy in project controller by opendaylight.

the class DistributedDataStoreClientBehaviorTest method createBehavior.

@Override
protected AbstractDataStoreClientBehavior createBehavior(final ClientActorContext clientContext, final ActorContext context) {
    final ShardStrategyFactory factory = mock(ShardStrategyFactory.class);
    final ShardStrategy strategy = mock(ShardStrategy.class);
    when(strategy.findShard(any())).thenReturn(SHARD);
    when(factory.getStrategy(any())).thenReturn(strategy);
    when(context.getShardStrategyFactory()).thenReturn(factory);
    return new DistributedDataStoreClientBehavior(clientContext, context);
}
Also used : ShardStrategy(org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy) ShardStrategyFactory(org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory)

Aggregations

ShardStrategy (org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategy)5 Test (org.junit.Test)4 ModuleShardStrategy (org.opendaylight.controller.cluster.datastore.shardstrategy.ModuleShardStrategy)4 MemberName (org.opendaylight.controller.cluster.access.concepts.MemberName)3 URI (java.net.URI)1 ShardStrategyFactory (org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory)1