use of org.infinispan.distribution.ch.impl.ReplicatedConsistentHashFactory in project infinispan by infinispan.
the class ReplicatedConsistentHashFactoryTest method test1.
public void test1() {
int[] testSegments = { 1, 2, 4, 8, 16, 31, 32, 33, 67, 128 };
ReplicatedConsistentHashFactory factory = new ReplicatedConsistentHashFactory();
Address A = new TestAddress(0, "A");
Address B = new TestAddress(1, "B");
Address C = new TestAddress(2, "C");
Address D = new TestAddress(3, "D");
List<Address> a = Arrays.asList(A);
List<Address> ab = Arrays.asList(A, B);
List<Address> abc = Arrays.asList(A, B, C);
List<Address> abcd = Arrays.asList(A, B, C, D);
List<Address> bcd = Arrays.asList(B, C, D);
List<Address> c = Arrays.asList(C);
for (int segments : testSegments) {
ReplicatedConsistentHash ch = factory.create(0, segments, a, null);
checkDistribution(ch);
ch = factory.updateMembers(ch, ab, null);
ch = factory.rebalance(ch);
checkDistribution(ch);
ch = factory.updateMembers(ch, abc, null);
ch = factory.rebalance(ch);
checkDistribution(ch);
ch = factory.updateMembers(ch, abcd, null);
ch = factory.rebalance(ch);
checkDistribution(ch);
ch = factory.updateMembers(ch, bcd, null);
ch = factory.rebalance(ch);
checkDistribution(ch);
ch = factory.updateMembers(ch, c, null);
ch = factory.rebalance(ch);
checkDistribution(ch);
}
}
use of org.infinispan.distribution.ch.impl.ReplicatedConsistentHashFactory in project infinispan by infinispan.
the class ReplicatedConsistentHashPersistenceTest method createConsistentHash.
@Override
public ConsistentHash createConsistentHash() {
List<Address> members = new ArrayList<>();
members.add(Generator.generateAddress());
members.add(Generator.generateAddress());
members.add(Generator.generateAddress());
Map<Address, Float> capacityFactors = new HashMap<>();
for (Address member : members) {
capacityFactors.put(member, 1.0f);
}
ReplicatedConsistentHashFactory hashFactory = new ReplicatedConsistentHashFactory();
return hashFactory.create(2, 100, members, capacityFactors);
}
use of org.infinispan.distribution.ch.impl.ReplicatedConsistentHashFactory in project infinispan by infinispan.
the class RpcManagerTest method testInvokeCommandOnAllSuspect.
public void testInvokeCommandOnAllSuspect() throws Exception {
DistributionManager distributionManager = cache(0).getAdvancedCache().getDistributionManager();
CacheTopology initialTopology = distributionManager.getCacheTopology();
assertEquals(CacheTopology.Phase.NO_REBALANCE, initialTopology.getPhase());
try {
ClusteredGetCommand command = TestingUtil.extractCommandsFactory(cache(0)).buildClusteredGetCommand("key", 0, 0L);
RpcManager rpcManager0 = cache(0).getAdvancedCache().getRpcManager();
// Add a node to the cache topology, but not to the JGroups cluster view
List<Address> newMembers = new ArrayList<>(initialTopology.getMembers());
newMembers.add(SUSPECT);
ConsistentHash newCH = new ReplicatedConsistentHashFactory().create(1, 1, newMembers, null);
CacheTopology suspectTopology = new CacheTopology(initialTopology.getTopologyId(), initialTopology.getRebalanceId(), newCH, null, null, CacheTopology.Phase.NO_REBALANCE, newCH.getMembers(), null);
distributionManager.setCacheTopology(suspectTopology);
command.setTopologyId(rpcManager0.getTopologyId());
CompletionStage<Map<Address, Response>> stage1 = rpcManager0.invokeCommandOnAll(command, MapResponseCollector.validOnly(), rpcManager0.getSyncRpcOptions());
Exceptions.expectExecutionException(SuspectException.class, stage1.toCompletableFuture());
} finally {
distributionManager.setCacheTopology(initialTopology);
}
}
Aggregations