Created
March 9, 2009 20:13
-
-
Save etrepum/76446 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Eclipse Workspace Patch 1.0 | |
#P voldemort | |
Index: test/unit/voldemort/versioning/VectorClockTest.java | |
=================================================================== | |
--- test/unit/voldemort/versioning/VectorClockTest.java (revision 168) | |
+++ test/unit/voldemort/versioning/VectorClockTest.java (working copy) | |
@@ -50,8 +50,8 @@ | |
getClock(1).merge(getClock(2)), | |
getClock(1, 2)); | |
assertEquals("Merging two clocks should be the same as taking the max of their event counts.", | |
- getClock(1, 1, 1, 2, 3).merge(getClock(1, 2, 2, 4)), | |
- getClock(1, 1, 1, 2, 2, 3, 4)); | |
+ getClock(1, 1, 1, 2, 3, 5).merge(getClock(1, 2, 2, 4)), | |
+ getClock(1, 1, 1, 2, 2, 3, 4, 5)); | |
} | |
public void testSerialization() { | |
@@ -71,4 +71,11 @@ | |
assertEquals("Clock does not serialize to itself.", clock, new VectorClock(clock.toBytes())); | |
} | |
+ public void testIncrement() { | |
+ VectorClock clock1 = getClock(5, 1, 2, 3, 2, 3, 1); | |
+ VectorClock clock2 = getClock(5, 1, 1, 2, 2, 3, 3); | |
+ assertEquals("Clock Strings not equal", clock1.toString(), clock2.toString()); | |
+ assertEquals("Clocks not equal", clock1, clock2); | |
+ } | |
+ | |
} | |
Index: src/java/voldemort/versioning/VectorClock.java | |
=================================================================== | |
--- src/java/voldemort/versioning/VectorClock.java (revision 168) | |
+++ src/java/voldemort/versioning/VectorClock.java (working copy) | |
@@ -155,14 +155,19 @@ | |
boolean found = false; | |
int index = 0; | |
for(; index < versions.size(); index++) { | |
- if(versions.get(index).getNodeId() >= node) { | |
+ if(versions.get(index).getNodeId() == node) { | |
found = true; | |
break; | |
+ } else if(versions.get(index).getNodeId() > node) { | |
+ found = false; | |
+ break; | |
} | |
} | |
if(found) { | |
versions.set(index, versions.get(index).incremented()); | |
+ } else if(index < versions.size() - 1) { | |
+ versions.add(index, new ClockEntry((short) node, (short) 1)); | |
} else { | |
// we don't already have a version for this, so add it | |
if(versions.size() > MAX_NUMBER_OF_VERSIONS) | |
@@ -254,13 +259,14 @@ | |
i++; | |
} else { | |
newClock.versions.add(v2.clone()); | |
+ j++; | |
} | |
} | |
// Okay now there may be leftovers on one or the other list remaining | |
for(int k = i; k < this.versions.size(); k++) | |
newClock.versions.add(this.versions.get(k).clone()); | |
- for(int k = j; k < this.versions.size(); k++) | |
+ for(int k = j; k < clock.versions.size(); k++) | |
newClock.versions.add(clock.versions.get(k).clone()); | |
return newClock; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment