Search in sources :

Example 1 with TestAddress

use of org.infinispan.distribution.TestAddress in project infinispan by infinispan.

the class DefaultConsistentHashFactoryTest method testNullCapacityFactors.

public void testNullCapacityFactors() {
    ConsistentHashFactory<DefaultConsistentHash> chf = createConsistentHashFactory();
    TestAddress A = new TestAddress(0, "A");
    TestAddress B = new TestAddress(1, "B");
    TestAddress C = new TestAddress(2, "C");
    TestAddress D = new TestAddress(3, "D");
    Map<Address, Float> cf = new HashMap<>();
    cf.put(A, 1f);
    cf.put(B, 1f);
    cf.put(C, 1f);
    cf.put(D, 1f);
    DefaultConsistentHash ch1 = chf.create(2, 60, Arrays.asList(A), cf);
    DefaultConsistentHash ch1NoCF = chf.create(2, 60, Arrays.asList(A), null);
    assertEquals(ch1, ch1NoCF);
    DefaultConsistentHash ch2 = chf.updateMembers(ch1, Arrays.asList(A, B), cf);
    ch2 = chf.rebalance(ch2);
    DefaultConsistentHash ch2NoCF = chf.updateMembers(ch1, Arrays.asList(A, B), null);
    ch2NoCF = chf.rebalance(ch2NoCF);
    assertEquals(ch2, ch2NoCF);
    DefaultConsistentHash ch3 = chf.updateMembers(ch2, Arrays.asList(A, B, C), cf);
    ch3 = chf.rebalance(ch3);
    DefaultConsistentHash ch3NoCF = chf.updateMembers(ch2, Arrays.asList(A, B, C), null);
    ch3NoCF = chf.rebalance(ch3NoCF);
    assertEquals(ch3, ch3NoCF);
    DefaultConsistentHash ch4 = chf.updateMembers(ch3, Arrays.asList(A, B, C, D), cf);
    ch4 = chf.rebalance(ch4);
    DefaultConsistentHash ch4NoCF = chf.updateMembers(ch3, Arrays.asList(A, B, C, D), null);
    ch4NoCF = chf.rebalance(ch4NoCF);
    assertEquals(ch4, ch4NoCF);
}
Also used : TestAddress(org.infinispan.distribution.TestAddress) Address(org.infinispan.remoting.transport.Address) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestAddress(org.infinispan.distribution.TestAddress)

Example 2 with TestAddress

use of org.infinispan.distribution.TestAddress 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 3 with TestAddress

use of org.infinispan.distribution.TestAddress in project infinispan by infinispan.

the class CrashedMemberDetectorTest method testDetectCrashedMembers.

public void testDetectCrashedMembers() {
    Cache<Address, ServerAddress> cache = cacheManager.getCache();
    cache.put(new TestAddress(1), ServerAddress.forAddress("a", 123, true));
    cache.put(new TestAddress(2), ServerAddress.forAddress("b", 456, true));
    cache.put(new TestAddress(3), ServerAddress.forAddress("c", 789, true));
    CrashedMemberDetectorListener detector = new CrashedMemberDetectorListener(cache, null);
    List<Address> oldMembers = new ArrayList<>();
    oldMembers.add(new TestAddress(1));
    oldMembers.add(new TestAddress(3));
    oldMembers.add(new TestAddress(2));
    List<Address> newMembers = new ArrayList<>();
    newMembers.add(new TestAddress(1));
    newMembers.add(new TestAddress(2));
    EventImpl e = new EventImpl("", cacheManager, Type.VIEW_CHANGED, newMembers, oldMembers, new TestAddress(1), 99);
    detector.detectCrashedMember(e);
    assertTrue(cache.containsKey(new TestAddress(1)));
    assertTrue(cache.containsKey(new TestAddress(2)));
}
Also used : TestAddress(org.infinispan.distribution.TestAddress) Address(org.infinispan.remoting.transport.Address) EventImpl(org.infinispan.notifications.cachemanagerlistener.event.impl.EventImpl) TestAddress(org.infinispan.distribution.TestAddress) ArrayList(java.util.ArrayList)

Example 4 with TestAddress

use of org.infinispan.distribution.TestAddress in project infinispan by infinispan.

the class DefaultConsistentHashFactoryTest method testDifferentCapacityFactors.

public void testDifferentCapacityFactors() {
    ConsistentHashFactory<DefaultConsistentHash> chf = createConsistentHashFactory();
    TestAddress A = new TestAddress(0, "A");
    TestAddress B = new TestAddress(1, "B");
    TestAddress C = new TestAddress(2, "C");
    TestAddress D = new TestAddress(3, "D");
    Map<Address, Float> cf = new HashMap<>();
    cf.put(A, 1f);
    cf.put(B, 1f);
    cf.put(C, 1f);
    cf.put(D, 100f);
    DefaultConsistentHash ch1 = chf.create(2, 60, Arrays.asList(A), cf);
    checkDistribution(ch1, cf);
    DefaultConsistentHash ch2 = chf.updateMembers(ch1, Arrays.asList(A, B), cf);
    ch2 = chf.rebalance(ch2);
    checkDistribution(ch2, cf);
    DefaultConsistentHash ch3 = chf.updateMembers(ch2, Arrays.asList(A, B, C), cf);
    ch3 = chf.rebalance(ch3);
    checkDistribution(ch3, cf);
    DefaultConsistentHash ch4 = chf.updateMembers(ch3, Arrays.asList(A, B, C, D), cf);
    ch4 = chf.rebalance(ch4);
    checkDistribution(ch4, cf);
}
Also used : TestAddress(org.infinispan.distribution.TestAddress) Address(org.infinispan.remoting.transport.Address) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestAddress(org.infinispan.distribution.TestAddress)

Example 5 with TestAddress

use of org.infinispan.distribution.TestAddress in project infinispan by infinispan.

the class DefaultConsistentHashFactoryTest method testConsistentHashDistribution.

public void testConsistentHashDistribution() {
    ConsistentHashFactory<DefaultConsistentHash> chf = createConsistentHashFactory();
    for (int nn : NUM_NODES) {
        List<Address> nodes = new ArrayList<>(nn);
        for (int j = 0; j < nn; j++) {
            nodes.add(new TestAddress(j, "TA"));
        }
        for (int ns : NUM_SEGMENTS) {
            if (nn < ns) {
                for (int no : NUM_OWNERS) {
                    for (float[] lf : CAPACITY_FACTORS) {
                        Map<Address, Float> lfMap = null;
                        if (lf != null) {
                            lfMap = new HashMap<>();
                            for (int i = 0; i < nn; i++) {
                                lfMap.put(nodes.get(i), lf[i % lf.length]);
                            }
                        }
                        testConsistentHashModifications(chf, nodes, ns, no, lfMap);
                    }
                }
            }
        }
    }
}
Also used : TestAddress(org.infinispan.distribution.TestAddress) Address(org.infinispan.remoting.transport.Address) ArrayList(java.util.ArrayList) TestAddress(org.infinispan.distribution.TestAddress)

Aggregations

TestAddress (org.infinispan.distribution.TestAddress)9 Address (org.infinispan.remoting.transport.Address)9 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 DefaultConsistentHashFactory (org.infinispan.distribution.ch.impl.DefaultConsistentHashFactory)2 PersistentUUIDManager (org.infinispan.topology.PersistentUUIDManager)2 PersistentUUIDManagerImpl (org.infinispan.topology.PersistentUUIDManagerImpl)2 Flowable (io.reactivex.rxjava3.core.Flowable)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentSkipListSet (java.util.concurrent.ConcurrentSkipListSet)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1