Search in sources :

Example 1 with HashedValue

use of voldemort.utils.ConsistencyCheck.HashedValue in project voldemort by voldemort.

the class ConsistencyCheckTest method testDetermineConsistencyHashValue.

@Test
public void testDetermineConsistencyHashValue() {
    Map<ConsistencyCheck.Value, Set<ConsistencyCheck.ClusterNode>> versionNodeSetMap = new HashMap<ConsistencyCheck.Value, Set<ConsistencyCheck.ClusterNode>>();
    int replicationFactor = 4;
    // vector clocks
    Version v1 = new VectorClock();
    ((VectorClock) v1).incrementVersion(1, 100000001);
    ((VectorClock) v1).incrementVersion(2, 100000003);
    Version v2 = new VectorClock();
    ((VectorClock) v2).incrementVersion(1, 100000001);
    ((VectorClock) v2).incrementVersion(3, 100000002);
    Version v3 = new VectorClock();
    ((VectorClock) v3).incrementVersion(1, 100000001);
    ((VectorClock) v3).incrementVersion(4, 100000001);
    // Version is HashedValue
    Versioned<byte[]> versioned1 = new Versioned<byte[]>(value1, v1);
    Versioned<byte[]> versioned2 = new Versioned<byte[]>(value2, v2);
    Versioned<byte[]> versioned3 = new Versioned<byte[]>(value3, v3);
    ConsistencyCheck.Value hv1 = new ConsistencyCheck.HashedValue(versioned1);
    ConsistencyCheck.Value hv2 = new ConsistencyCheck.HashedValue(versioned2);
    ConsistencyCheck.Value hv3 = new ConsistencyCheck.HashedValue(versioned3);
    // FULL
    // one version
    versionNodeSetMap.clear();
    versionNodeSetMap.put(hv1, setFourNodes);
    assertEquals(ConsistencyCheck.ConsistencyLevel.FULL, ConsistencyCheck.determineConsistency(versionNodeSetMap, replicationFactor));
    // three versions
    versionNodeSetMap.clear();
    versionNodeSetMap.put(hv1, setFourNodes);
    versionNodeSetMap.put(hv2, setFourNodes);
    versionNodeSetMap.put(hv3, setFourNodes);
    assertEquals(ConsistencyCheck.ConsistencyLevel.FULL, ConsistencyCheck.determineConsistency(versionNodeSetMap, replicationFactor));
    // LATEST_CONSISTENT: not possible since timestamp is ignored
    // INCONSISTENT
    versionNodeSetMap.clear();
    versionNodeSetMap.put(hv1, setThreeNodes);
    assertEquals(ConsistencyCheck.ConsistencyLevel.INCONSISTENT, ConsistencyCheck.determineConsistency(versionNodeSetMap, replicationFactor));
    versionNodeSetMap.clear();
    versionNodeSetMap.put(hv1, setFourNodes);
    versionNodeSetMap.put(hv2, setThreeNodes);
    assertEquals(ConsistencyCheck.ConsistencyLevel.LATEST_CONSISTENT, ConsistencyCheck.determineConsistency(versionNodeSetMap, replicationFactor));
}
Also used : ClusterNode(voldemort.utils.ConsistencyCheck.ClusterNode) HashSet(java.util.HashSet) Set(java.util.Set) Versioned(voldemort.versioning.Versioned) HashMap(java.util.HashMap) HashedValue(voldemort.utils.ConsistencyCheck.HashedValue) VectorClock(voldemort.versioning.VectorClock) Version(voldemort.versioning.Version) HashedValue(voldemort.utils.ConsistencyCheck.HashedValue) Test(org.junit.Test)

Example 2 with HashedValue

use of voldemort.utils.ConsistencyCheck.HashedValue 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));
}
Also used : ClusterNode(voldemort.utils.ConsistencyCheck.ClusterNode) HashSet(java.util.HashSet) Set(java.util.Set) Versioned(voldemort.versioning.Versioned) HashMap(java.util.HashMap) HashedValue(voldemort.utils.ConsistencyCheck.HashedValue) VectorClock(voldemort.versioning.VectorClock) HashedValue(voldemort.utils.ConsistencyCheck.HashedValue) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Test (org.junit.Test)2 ClusterNode (voldemort.utils.ConsistencyCheck.ClusterNode)2 HashedValue (voldemort.utils.ConsistencyCheck.HashedValue)2 VectorClock (voldemort.versioning.VectorClock)2 Versioned (voldemort.versioning.Versioned)2 Version (voldemort.versioning.Version)1