Skip to content

Instantly share code, notes, and snippets.

@afeinberg
Created October 16, 2009 22:21
Show Gist options
  • Save afeinberg/212117 to your computer and use it in GitHub Desktop.
Save afeinberg/212117 to your computer and use it in GitHub Desktop.
diff --git a/src/java/voldemort/client/DefaultStoreClient.java b/src/java/voldemort/client/DefaultStoreClient.java
index 5f5b72f..3b08228 100644
--- a/src/java/voldemort/client/DefaultStoreClient.java
+++ b/src/java/voldemort/client/DefaultStoreClient.java
@@ -94,7 +94,7 @@ public class DefaultStoreClient<K, V> implements StoreClient<K, V> {
public V getValue(K key, V defaultValue) {
Versioned<V> versioned = get(key);
if(versioned == null)
- return null;
+ return defaultValue;
else
return versioned.getValue();
}
diff --git a/test/unit/voldemort/client/DefaultStoreClientTest.java b/test/unit/voldemort/client/DefaultStoreClientTest.java
index a63a744..8c8b149 100644
--- a/test/unit/voldemort/client/DefaultStoreClientTest.java
+++ b/test/unit/voldemort/client/DefaultStoreClientTest.java
@@ -54,13 +54,13 @@ public class DefaultStoreClientTest extends TestCase {
assertNotNull(client.get("k").getVersion());
}
- public void getUnversioned() {
+ public void testGetUnversioned() {
assertEquals("GET of non-existant key should be null.", null, client.getValue("k"));
client.put("k", "v");
assertEquals("GET of k should return v, if v is there.", "v", client.getValue("k"));
}
- public void getUnversionedWithDefault() {
+ public void testGetUnversionedWithDefault() {
assertEquals("GET of non-existant key should return default.", "v", client.getValue("k",
"v"));
assertEquals("null should be an acceptable default", null, client.getValue("k", null));
@@ -88,6 +88,10 @@ public class DefaultStoreClientTest extends TestCase {
new Versioned<String>("v2",
new VectorClock().incremented(nodeId + 1,
time.getMilliseconds())));
+ assertEquals("GET should return the new value set by PUT.", "v2", client.getValue("k"));
+ assertEquals("GET should return the new version set by PUT.", expected.incremented(nodeId + 1,
+ time.getMilliseconds()),
+ client.get("k").getVersion());
}
public void testPutUnversioned() {
@@ -112,7 +116,7 @@ public class DefaultStoreClientTest extends TestCase {
}
public void testDeleteVersion() {
- assertFalse("Delete of non-existant key should be false.", client.delete("k"));
+ assertFalse("Delete of non-existant key should be false.", client.delete("k", new VectorClock()));
client.put("k", new Versioned<String>("v"));
assertFalse("Delete of a lesser version should be false.", client.delete("k",
new VectorClock()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment