public ClockEntry incremented() { return new ClockEntry(nodeId, version + 1); }
@Deprecated public List<ClockEntry> getEntries() { List<ClockEntry> clocks = new ArrayList<ClockEntry>(versionMap.size()); for(Map.Entry<Short, Long> entry: versionMap.entrySet()) { clocks.add(new ClockEntry(entry.getKey(), entry.getValue())); } return Collections.unmodifiableList(clocks); }
/** * Generates a vector clock with the provided values * * @param serverIds servers in the clock * @param clockValue value of the clock for each server entry * @param timestamp ts value to be set for the clock * @return */ public static VectorClock makeClock(Set<Integer> serverIds, long clockValue, long timestamp) { List<ClockEntry> clockEntries = new ArrayList<ClockEntry>(serverIds.size()); for(Integer serverId: serverIds) { clockEntries.add(new ClockEntry(serverId.shortValue(), clockValue)); } return new VectorClock(clockEntries, timestamp); }
private VectorClock makeSuperClock(long time) { List<ClockEntry> clockEntries = new ArrayList<ClockEntry>(); clockEntries.add(new ClockEntry((short) 0, time)); clockEntries.add(new ClockEntry((short) 1, time)); clockEntries.add(new ClockEntry((short) 2, time)); return new VectorClock(clockEntries, time); }
long version = Long.parseLong(parsedClockEntry[1]); logger.trace("clock entry parsed: <" + nodeId + "> : <" + version + ">"); versions.add(new ClockEntry(nodeId, version));
/** * Constructs a vector clock as in versioned put based on timestamp * * @param timeMs timestamp to use in the clock value * @param master node for the put. the master's versions will be timeMs+1, * if master > -1 * @return */ @SuppressWarnings("deprecation") public static VectorClock getVersionedPutClock(long timeMs, int master, int... nodes) { List<ClockEntry> clockEntries = Lists.newArrayList(); for(int node: nodes) { if(master >= 0 && node == master) { clockEntries.add(new ClockEntry((short) node, timeMs + 1)); } else { clockEntries.add(new ClockEntry((short) node, timeMs)); } } return new VectorClock(clockEntries, timeMs); }
public static VectorClock decodeClock(VProto.VectorClock encoded) { List<ClockEntry> entries = new ArrayList<ClockEntry>(encoded.getEntriesCount()); for(VProto.ClockEntry entry: encoded.getEntriesList()) entries.add(new ClockEntry((short) entry.getNodeId(), entry.getVersion())); return new VectorClock(entries, encoded.getTimestamp()); }
public void testEquality() { ClockEntry v1 = new ClockEntry((short) 0, 1); ClockEntry v2 = new ClockEntry((short) 0, 1); assertTrue(v1.equals(v1)); assertTrue(!v1.equals(null)); assertEquals(v1, v2); v1 = new ClockEntry((short) 0, 1); v2 = new ClockEntry((short) 0, 2); assertTrue(!v1.equals(v2)); v1 = new ClockEntry(Short.MAX_VALUE, 256); v2 = new ClockEntry(Short.MAX_VALUE, 256); assertEquals(v1, v2); }
/** * See github issue #25: Incorrect coercion of version to short before * passing to ClockEntry constructor */ @Test public void testMergeWithLargeVersion() { VectorClock clock1 = getClock(1); VectorClock clock2 = new VectorClock(Lists.newArrayList(new ClockEntry((short) 1, Short.MAX_VALUE + 1)), System.currentTimeMillis()); VectorClock mergedClock = clock1.merge(clock2); assertEquals(mergedClock.getMaxVersion(), Short.MAX_VALUE + 1); }
@Test public void testNodeLess0NotAcceptable() { try { ClockEntry clockEntry = new ClockEntry(); clockEntry.setNodeId((short) -1); fail("Did not throw IllegalArgumentException"); } catch(IllegalArgumentException e) {} } }
@Test public void testVersion0NotAcceptable() { try { ClockEntry clockEntry = new ClockEntry(); clockEntry.setVersion(0); fail("Did not throw IllegalArgumentException"); } catch(IllegalArgumentException e) {} }
/** * A test for comparing vector clocks that nodes of clock entries are not * sorted In case people insert clock entries without using increment we * need to test although it has been deprecated */ @Test public void testNodeClockEntryDeprecate() { VectorClock vc1 = new VectorClock(); try { vc1.getEntries().add(new ClockEntry((short) 2, 2)); fail("Did not throw UnsupportedOperationException"); } catch(UnsupportedOperationException e) { } }
VectorClock losingClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 0, 5)), System.currentTimeMillis()); VectorClock winningClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 1, 5)), losingClock.getTimestamp() + 1); srcAdminClient.storeOps.putNodeKeyValue(GLOBALLY_RESOLVING_STORE_NAME,
VectorClock losingClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 0, 5)), System.currentTimeMillis()); VectorClock winningClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 1, 5)), losingClock.getTimestamp() + 1); srcAdminClient.storeOps.putNodeKeyValue(PRIMARY_RESOLVING_STORE_NAME,
VectorClock losingClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 0, 5)), System.currentTimeMillis()); VectorClock winningClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 1, 5)), losingClock.getTimestamp() + 1); srcAdminClient.storeOps.putNodeKeyValue(GLOBALLY_RESOLVING_STORE_NAME,
clockEntries.add(new ClockEntry(nodeid.shortValue(), System.currentTimeMillis())); VectorClock clusterXmlClock = new VectorClock(clockEntries, System.currentTimeMillis()); for(Integer nodeid: serverList)
clockEntries.add(new ClockEntry(nodeid.shortValue(), System.currentTimeMillis())); VectorClock clusterXmlClock = new VectorClock(clockEntries, System.currentTimeMillis()); for(Integer nodeid: serverList)
clockEntries.add(new ClockEntry(nodeid.shortValue(), System.currentTimeMillis())); VectorClock clusterXmlClock = new VectorClock(clockEntries, System.currentTimeMillis()); for(Integer nodeid: serverList)
VectorClock losingClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 0, 5)), System.currentTimeMillis()); VectorClock winningClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 1, 5)), losingClock.getTimestamp() + 1); srcAdminClient.storeOps.putNodeKeyValue(MULTIPLE_VERSIONS_STORE_NAME,
public void testIncrement() { ClockEntry v = new ClockEntry((short) 0, 1); assertEquals(v.getNodeId(), 0); assertEquals(v.getVersion(), 1); ClockEntry v2 = v.incremented(); assertEquals(v.getVersion(), 1); assertEquals(v2.getVersion(), 2); }