Permalink
Browse files

Unit tests

  • Loading branch information...
1 parent f82b9e9 commit 799b25fd10fb084d2040a419b7015e23b00c2c77 @rsumbaly committed Sep 15, 2012
@@ -59,19 +59,29 @@ public CompressingStore(Store<ByteArray, byte[], byte[]> innerStore,
this.innerStore = Utils.notNull(innerStore);
}
- private List<ByteArray> deflateKeys(Iterable<ByteArray> keys) {
- List<ByteArray> deflatedKeys = Lists.newArrayList();
+ public Map<ByteArray, Boolean> hasKeys(Iterable<ByteArray> keys, boolean exact) {
+ StoreUtils.assertValidKeys(keys);
+ Map<ByteArray, ByteArray> deflatedToOriginalKeys = Maps.newHashMap();
for(ByteArray key: keys)
- deflatedKeys.add(deflateKey(key));
- return deflatedKeys;
+ deflatedToOriginalKeys.put(deflateKey(key), key);
+ Map<ByteArray, Boolean> deflatedToBoolean = innerStore.hasKeys(deflatedToOriginalKeys.keySet(),
+ exact);
+ Map<ByteArray, Boolean> originalToBoolean = Maps.newHashMapWithExpectedSize(deflatedToBoolean.size());
+ for(Map.Entry<ByteArray, Boolean> entry: deflatedToBoolean.entrySet()) {
+ originalToBoolean.put(deflatedToOriginalKeys.get(entry.getKey()), entry.getValue());
+ }
+ return originalToBoolean;
}
public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys,
Map<ByteArray, byte[]> transforms)
throws VoldemortException {
StoreUtils.assertValidKeys(keys);
Iterable<ByteArray> processedKeys = keys;
- processedKeys = deflateKeys(keys);
+ List<ByteArray> deflatedKeys = Lists.newArrayList();
+ for(ByteArray key: keys)
+ deflatedKeys.add(deflateKey(key));
+ processedKeys = deflatedKeys;
Map<ByteArray, byte[]> newTransforms = Maps.newHashMap();
if(transforms != null) {
for(Map.Entry<ByteArray, byte[]> transform: transforms.entrySet()) {
@@ -173,9 +183,4 @@ public boolean delete(ByteArray key, Version version) throws VoldemortException
StoreUtils.assertValidKey(key);
return innerStore.delete(deflateKey(key), version);
}
-
- public Map<ByteArray, Boolean> hasKeys(Iterable<ByteArray> keys, boolean exact) {
- StoreUtils.assertValidKeys(keys);
- return innerStore.hasKeys(deflateKeys(keys), exact);
- }
}
@@ -17,6 +17,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Random;
import java.util.Set;
import org.junit.After;
@@ -52,6 +53,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
@RunWith(Parameterized.class)
public class ReadOnlyStorageEngineTest {
@@ -145,6 +147,9 @@ public void canGetGoodValues() throws Exception {
+ " for node " + node.getId() + ".", 1, found.size());
Versioned<String> obj = found.get(0);
assertEquals(entry.getValue(), obj.getValue());
+ assertEquals(store.hasKeys(Lists.newArrayList(entry.getKey()), true)
+ .get(entry.getKey()),
+ true);
}
}
}
@@ -173,6 +178,9 @@ public void canGetGoodCompressedValues() throws Exception {
+ " for node " + node.getId() + ".", 1, found.size());
Versioned<String> obj = found.get(0);
assertEquals(entry.getValue(), obj.getValue());
+ assertEquals(store.hasKeys(Lists.newArrayList(entry.getKey()), true)
+ .get(entry.getKey()),
+ true);
}
}
}
@@ -201,6 +209,9 @@ public void canGetGoodCompressedKeys() throws Exception {
+ " for node " + node.getId() + ".", 1, found.size());
Versioned<String> obj = found.get(0);
assertEquals(entry.getValue(), obj.getValue());
+ assertEquals(store.hasKeys(Lists.newArrayList(entry.getKey()), true)
+ .get(entry.getKey()),
+ true);
}
}
}
@@ -264,6 +275,24 @@ public void canMultigetGoodValues() throws Exception {
assertEquals(testData.getData().get(returned.getKey()), val.getValue());
gotten.add(returned.getKey());
}
+ // hasKeys all good keys
+ Map<String, Boolean> found = entry.getValue().hasKeys(queryKeys, true);
+ for(String key: queryKeys) {
+ assertEquals(found.get(key), true);
+ }
+ // hasKeys some bad keys
+ Random r = new Random();
+ Set<String> badKeys = Sets.newHashSet(r.nextInt() + "", r.nextInt() + "");
+ Set<String> both = Sets.newHashSet(queryKeys);
+ both.addAll(badKeys);
+ found = entry.getValue().hasKeys(both, true);
+ for(String key: queryKeys) {
+ assertEquals(found.get(key), true);
+ }
+ for(String key: badKeys) {
+ assertEquals(!found.containsKey(key), true);
+ }
+
}
assertEquals(keys, gotten);
testData.delete();
@@ -613,10 +642,12 @@ private void createStoreFiles(File dir, int indexBytes, int dataBytes, Node node
case READONLY_V1: {
for(Integer partitionId: node.getPartitionIds()) {
for(int chunkId = 0; chunkId < numChunks; chunkId++) {
- File index = createFile(dir, Integer.toString(partitionId) + "_"
- + Integer.toString(chunkId) + ".index");
- File data = createFile(dir, Integer.toString(partitionId) + "_"
- + Integer.toString(chunkId) + ".data");
+ File index = createFile(dir,
+ Integer.toString(partitionId) + "_"
+ + Integer.toString(chunkId) + ".index");
+ File data = createFile(dir,
+ Integer.toString(partitionId) + "_"
+ + Integer.toString(chunkId) + ".data");
// write some random crap for index and data
FileOutputStream dataOs = new FileOutputStream(data);
for(int i = 0; i < dataBytes; i++)
@@ -637,8 +668,9 @@ private void createStoreFiles(File dir, int indexBytes, int dataBytes, Node node
for(int chunkId = 0; chunkId < numChunks; chunkId++) {
File index = createFile(dir, Integer.toString(partitionId) + "_0_"
+ Integer.toString(chunkId) + ".index");
- File data = createFile(dir, Integer.toString(partitionId) + "_0_"
- + Integer.toString(chunkId) + ".data");
+ File data = createFile(dir,
+ Integer.toString(partitionId) + "_0_"
+ + Integer.toString(chunkId) + ".data");
// write some random crap for index and data
FileOutputStream dataOs = new FileOutputStream(data);
for(int i = 0; i < dataBytes; i++)

0 comments on commit 799b25f

Please sign in to comment.