@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)); }
@Override public void addMemberReplicaForShard(final String shardName, final MemberName newMemberName) { checkNotNullShardName(shardName); requireNonNull(newMemberName, "MemberName should not be null"); for (ModuleConfig moduleConfig: moduleConfigMap.values()) { ShardConfig shardConfig = moduleConfig.getShardConfig(shardName); if (shardConfig != null) { Set<MemberName> replicas = new HashSet<>(shardConfig.getReplicas()); replicas.add(newMemberName); updateModuleConfigMap(ModuleConfig.builder(moduleConfig).shardConfig(shardName, replicas).build()); return; } } }
ConfigurationImpl implements Configuration { @Override public void addMemberReplicaForShard(final String shardName, final MemberName newMemberName) { checkNotNullShardName(shardName); requireNonNull(newMemberName, "MemberName should not be null"); for (ModuleConfig moduleConfig: moduleConfigMap.values()) { ShardConfig shardConfig = moduleConfig.getShardConfig(shardName); if (shardConfig != null) { Set<MemberName> replicas = new HashSet<>(shardConfig.getReplicas()); replicas.add(newMemberName); updateModuleConfigMap(ModuleConfig.builder(moduleConfig).shardConfig(shardName, replicas).build()); return; } } } }
ConfigurationImpl implements Configuration { @Override public void addMemberReplicaForShard(final String shardName, final MemberName newMemberName) { checkNotNullShardName(shardName); requireNonNull(newMemberName, "MemberName should not be null"); for (ModuleConfig moduleConfig: moduleConfigMap.values()) { ShardConfig shardConfig = moduleConfig.getShardConfig(shardName); if (shardConfig != null) { Set<MemberName> replicas = new HashSet<>(shardConfig.getReplicas()); replicas.add(newMemberName); updateModuleConfigMap(ModuleConfig.builder(moduleConfig).shardConfig(shardName, replicas).build()); return; } } } ConfigurationImpl(final String moduleShardsConfigPath, final String modulesConfigPath);  ConfigurationImpl(final ModuleShardConfigProvider provider); }
ConfigurationImpl implements Configuration { @Override public void addMemberReplicaForShard(final String shardName, final MemberName newMemberName) { checkNotNullShardName(shardName); requireNonNull(newMemberName, "MemberName should not be null"); for (ModuleConfig moduleConfig: moduleConfigMap.values()) { ShardConfig shardConfig = moduleConfig.getShardConfig(shardName); if (shardConfig != null) { Set<MemberName> replicas = new HashSet<>(shardConfig.getReplicas()); replicas.add(newMemberName); updateModuleConfigMap(ModuleConfig.builder(moduleConfig).shardConfig(shardName, replicas).build()); return; } } } ConfigurationImpl(final String moduleShardsConfigPath, final String modulesConfigPath);  ConfigurationImpl(final ModuleShardConfigProvider provider); @Override Collection<String> getMemberShardNames(final MemberName memberName); @Override String getModuleNameFromNameSpace(final String nameSpace); @Override ShardStrategy getStrategyForModule(final String moduleName); @Override String getShardNameForModule(final String moduleName); @Override String getShardNameForPrefix(final DOMDataTreeIdentifier prefix); @Override Collection<MemberName> getMembersFromShardName(final String shardName); @Override Set<String> getAllShardNames(); @Override Collection<MemberName> getUniqueMemberNamesForAllShards(); @Override synchronized void addModuleShardConfiguration(final ModuleShardConfiguration config); @Override void addPrefixShardConfiguration(final PrefixShardConfiguration config); @Override void removePrefixShardConfiguration(final DOMDataTreeIdentifier prefix); @Override Map<DOMDataTreeIdentifier, PrefixShardConfiguration> getAllPrefixShardConfigurations(); @Override boolean isShardConfigured(final String shardName); @Override void addMemberReplicaForShard(final String shardName, final MemberName newMemberName); @Override void removeMemberReplicaForShard(final String shardName, final MemberName newMemberName); @Override ShardStrategy getStrategyForPrefix(final DOMDataTreeIdentifier prefix); }
ConfigurationImpl implements Configuration { @Override public void addMemberReplicaForShard(final String shardName, final MemberName newMemberName) { checkNotNullShardName(shardName); requireNonNull(newMemberName, "MemberName should not be null"); for (ModuleConfig moduleConfig: moduleConfigMap.values()) { ShardConfig shardConfig = moduleConfig.getShardConfig(shardName); if (shardConfig != null) { Set<MemberName> replicas = new HashSet<>(shardConfig.getReplicas()); replicas.add(newMemberName); updateModuleConfigMap(ModuleConfig.builder(moduleConfig).shardConfig(shardName, replicas).build()); return; } } } ConfigurationImpl(final String moduleShardsConfigPath, final String modulesConfigPath);  ConfigurationImpl(final ModuleShardConfigProvider provider); @Override Collection<String> getMemberShardNames(final MemberName memberName); @Override String getModuleNameFromNameSpace(final String nameSpace); @Override ShardStrategy getStrategyForModule(final String moduleName); @Override String getShardNameForModule(final String moduleName); @Override String getShardNameForPrefix(final DOMDataTreeIdentifier prefix); @Override Collection<MemberName> getMembersFromShardName(final String shardName); @Override Set<String> getAllShardNames(); @Override Collection<MemberName> getUniqueMemberNamesForAllShards(); @Override synchronized void addModuleShardConfiguration(final ModuleShardConfiguration config); @Override void addPrefixShardConfiguration(final PrefixShardConfiguration config); @Override void removePrefixShardConfiguration(final DOMDataTreeIdentifier prefix); @Override Map<DOMDataTreeIdentifier, PrefixShardConfiguration> getAllPrefixShardConfigurations(); @Override boolean isShardConfigured(final String shardName); @Override void addMemberReplicaForShard(final String shardName, final MemberName newMemberName); @Override void removeMemberReplicaForShard(final String shardName, final MemberName newMemberName); @Override ShardStrategy getStrategyForPrefix(final DOMDataTreeIdentifier prefix);  }