use of voldemort.utils.ConsistencyCheck.ClusterNode in project voldemort by voldemort.
the class ConsistencyCheckTest method testKeyVersionToString.
@Test
public void testKeyVersionToString() {
byte[] keyBytes = { 0, 1, 2, 17, 4 };
ByteArray key = new ByteArray(keyBytes);
long now = System.currentTimeMillis();
VectorClock vc1 = new VectorClock(now);
VectorClock vc2 = new VectorClock(now + 1);
Versioned<byte[]> versioned = new Versioned<byte[]>(value1, vc1);
ConsistencyCheck.Value v1 = new ConsistencyCheck.VersionValue(new Versioned<byte[]>(value1, vc1));
ConsistencyCheck.Value v2 = new ConsistencyCheck.VersionValue(new Versioned<byte[]>(value2, vc2));
// make Prefix Nodes
Set<ClusterNode> set = new HashSet<ClusterNode>();
set.add(cn0_1);
set.add(cn1_2);
set.add(cn0_3);
// test vector clock
Map<ConsistencyCheck.Value, Set<ClusterNode>> mapVector = new HashMap<ConsistencyCheck.Value, Set<ClusterNode>>();
mapVector.put(v1, set);
vc1.incrementVersion(1, now);
v1 = new ConsistencyCheck.VersionValue(new Versioned<byte[]>(value1, vc1));
String sVector = ConsistencyCheck.keyVersionToString(key, mapVector, "testStore", 99);
assertEquals("BAD_KEY,testStore,99,0001021104," + set.toString().replace(", ", ";") + "," + now + ",[1:1]", sVector);
// test two lines
vc2.incrementVersion(1, now);
vc2.incrementVersion(1, now + 1);
v2 = new ConsistencyCheck.VersionValue(new Versioned<byte[]>(value2, vc2));
mapVector.put(v2, set);
String sVector2 = ConsistencyCheck.keyVersionToString(key, mapVector, "testStore", 99);
String s1 = "BAD_KEY,testStore,99,0001021104," + set.toString().replace(", ", ";") + "," + now + ",[1:1]";
String s2 = "BAD_KEY,testStore,99,0001021104," + set.toString().replace(", ", ";") + "," + (now + 1) + ",[1:2]";
assertTrue(sVector2.equals(s1 + s2) || sVector2.equals(s2 + s1));
// test value hash
ConsistencyCheck.Value v3 = new HashedValue(versioned);
Map<ConsistencyCheck.Value, Set<ClusterNode>> mapHashed = new HashMap<ConsistencyCheck.Value, Set<ClusterNode>>();
mapHashed.put(v3, set);
assertEquals("BAD_KEY,testStore,99,0001021104," + set.toString().replace(", ", ";") + "," + now + ",[1:1],-1172398097", ConsistencyCheck.keyVersionToString(key, mapHashed, "testStore", 99));
}
use of voldemort.utils.ConsistencyCheck.ClusterNode in project voldemort by voldemort.
the class ConsistencyCheckTest method testCleanIneligibleKeys.
@Test
public void testCleanIneligibleKeys() {
// versions
VectorClock vc1 = new VectorClock();
vc1.incrementVersion(1, 100000001);
vc1.incrementVersion(2, 100000003);
VectorClock vc2 = new VectorClock();
vc2.incrementVersion(1, 100000002);
ConsistencyCheck.Value v1 = new ConsistencyCheck.VersionValue(new Versioned<byte[]>(value1, vc1));
ConsistencyCheck.Value v2 = new ConsistencyCheck.VersionValue(new Versioned<byte[]>(value2, vc2));
// setup
Map<ByteArray, Map<ConsistencyCheck.Value, Set<ClusterNode>>> map = new HashMap<ByteArray, Map<ConsistencyCheck.Value, Set<ClusterNode>>>();
Map<ConsistencyCheck.Value, Set<ClusterNode>> nodeSetMap = new HashMap<ConsistencyCheck.Value, Set<ClusterNode>>();
Set<ClusterNode> oneNodeSet = new HashSet<ClusterNode>();
oneNodeSet.add(cn0_1);
Set<ClusterNode> twoNodeSet = new HashSet<ClusterNode>();
twoNodeSet.add(cn0_1);
twoNodeSet.add(cn0_2);
int requiredWrite = 2;
ByteArray key1 = new ByteArray(value1);
// delete one key
map.clear();
nodeSetMap.clear();
nodeSetMap.put(v1, oneNodeSet);
map.put(key1, nodeSetMap);
assertEquals(1, map.size());
ConsistencyCheck.cleanIneligibleKeys(map, requiredWrite);
assertEquals(0, map.size());
// delete one version out of two versions
map.clear();
nodeSetMap.clear();
nodeSetMap.put(v1, oneNodeSet);
nodeSetMap.put(v2, twoNodeSet);
map.put(key1, nodeSetMap);
assertEquals(2, map.get(key1).size());
ConsistencyCheck.cleanIneligibleKeys(map, requiredWrite);
assertEquals(1, map.size());
assertEquals(1, map.get(key1).size());
}
Aggregations