Skip to content

Commit

Permalink
NoopEngine and RemoteTest : tweak to be able to return data values
Browse files Browse the repository at this point in the history
Allow the NoopEngine to return data if so configured - useful for testing
as you can hand it a value, which will be returned for all subsequent
get() (and as part of delete())

I'm not utterly convinced this is the right way to go, but it's useful and switched off by default
  • Loading branch information
Geir Magnusson Jr committed Jun 8, 2009
1 parent 641b1e0 commit 5d7c818
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
15 changes: 14 additions & 1 deletion test/integration/voldemort/performance/RemoteTest.java
Expand Up @@ -139,6 +139,15 @@ public static void main(String[] args) throws Exception {
final String value = new String(TestUtils.randomBytes(valueSize));
ExecutorService service = Executors.newFixedThreadPool(numThreads);

/*
* send the store a value and then delete it - useful for the NOOP store which will then use that value for
* other queries
*/

String key = new KeyProvider(startNum, keys).next();
store.put(key, new Versioned<String>(value));
store.delete(key);

for (int loopCount=0; loopCount < numIterations; loopCount++) {

System.out.println("======================= iteration = " + loopCount + " ======================================");
Expand Down Expand Up @@ -206,7 +215,11 @@ public void run() {

public void run() {
try {
store.get(keyProvider2.next());
Versioned<String> v = store.get(keyProvider2.next());
if (!v.getValue().equals(value)) {
throw new Exception("value returned isn't same as set value");
}

} catch(Exception e) {
e.printStackTrace();
} finally {
Expand Down
Expand Up @@ -41,7 +41,7 @@ public class NoopStorageConfiguration implements StorageConfiguration {
public NoopStorageConfiguration(VoldemortConfig config) {}

public StorageEngine<ByteArray, byte[]> getStore(String name) {
return new NoopStorageEngine(name);
return new NoopStorageEngine(name, false);
}

public String getType() {
Expand Down
40 changes: 33 additions & 7 deletions test/integration/voldemort/store/noop/NoopStorageEngine.java
Expand Up @@ -29,42 +29,50 @@
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;


/**
* Implementation of a store that does the least amount possible.
* Implementation of a store that does the least amount possible. It will
* 'reflect' values sent to it so that it can be tested with real values.
* It's being done this way to avoid coupling the engine or it's configuration
* with knowledge of the serializer being used
*
*/
public class NoopStorageEngine implements StorageEngine<ByteArray, byte[]> {

protected String _name;
protected ArrayList<Versioned<byte[]>> _data = new ArrayList<Versioned<byte[]>>(0);
protected String name;
protected Versioned<byte[]> value;
protected List<Versioned<byte[]>> dataList = new MyList();
protected Map<ByteArray, List<Versioned<byte[]>>> dataMap = new MyMap();

public NoopStorageEngine(String name) {
_name = name;
this.name = name;
}

public ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> entries() {
return null;
}

public List<Versioned<byte[]>> get(ByteArray key) throws VoldemortException {
return _data;
return dataList;
}

public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys) throws VoldemortException {
return null;
return dataMap;
}

public void put(ByteArray key, Versioned<byte[]> value) throws VoldemortException {

this.value = value;
}

public boolean delete(ByteArray key, Version version) throws VoldemortException {
return true;
}

public String getName() {
return _name;
return name;
}

public void close() throws VoldemortException {
Expand All @@ -73,4 +81,22 @@ public void close() throws VoldemortException {
public Object getCapability(StoreCapabilityType capability) {
throw new NoSuchCapabilityException(capability, getName());
}

class MyMap extends HashMap<ByteArray, List<Versioned<byte[]>>> {

public List<Versioned<byte[]>> get(Object key) {
return dataList;
}
}

class MyList extends ArrayList<Versioned<byte[]>> {

public Versioned<byte[]> get(int index) {
return value;
}

public int size() {
return value == null ? 0 : 1;
}
}
}

0 comments on commit 5d7c818

Please sign in to comment.