Search in sources :

Example 1 with ReplicatedConsistentHashFactory

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);
    }
}
Also used : ReplicatedConsistentHashFactory(org.infinispan.distribution.ch.impl.ReplicatedConsistentHashFactory) TestAddress(org.infinispan.distribution.TestAddress) Address(org.infinispan.remoting.transport.Address) TestAddress(org.infinispan.distribution.TestAddress) ReplicatedConsistentHash(org.infinispan.distribution.ch.impl.ReplicatedConsistentHash)

Example 2 with ReplicatedConsistentHashFactory

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);
}
Also used : ReplicatedConsistentHashFactory(org.infinispan.distribution.ch.impl.ReplicatedConsistentHashFactory) Address(org.infinispan.remoting.transport.Address) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 3 with ReplicatedConsistentHashFactory

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);
    }
}
Also used : ConsistentHash(org.infinispan.distribution.ch.ConsistentHash) ReplicatedConsistentHashFactory(org.infinispan.distribution.ch.impl.ReplicatedConsistentHashFactory) CacheTopology(org.infinispan.topology.CacheTopology) JGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddress) Address(org.infinispan.remoting.transport.Address) ArrayList(java.util.ArrayList) ClusteredGetCommand(org.infinispan.commands.remote.ClusteredGetCommand) DistributionManager(org.infinispan.distribution.DistributionManager) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ReplicatedConsistentHashFactory (org.infinispan.distribution.ch.impl.ReplicatedConsistentHashFactory)3 Address (org.infinispan.remoting.transport.Address)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)1 ClusteredGetCommand (org.infinispan.commands.remote.ClusteredGetCommand)1 DistributionManager (org.infinispan.distribution.DistributionManager)1 TestAddress (org.infinispan.distribution.TestAddress)1 ConsistentHash (org.infinispan.distribution.ch.ConsistentHash)1 ReplicatedConsistentHash (org.infinispan.distribution.ch.impl.ReplicatedConsistentHash)1 JGroupsAddress (org.infinispan.remoting.transport.jgroups.JGroupsAddress)1 CacheTopology (org.infinispan.topology.CacheTopology)1