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);
}
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);
}
}
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)));
}
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);
}
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);
}
}
}
}
}
}
Aggregations