Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
abh1nay committed Apr 23, 2013
1 parent 800d48f commit b245e3b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/common/voldemort/config/two-stores-replicated.xml
Expand Up @@ -36,4 +36,23 @@
<schema-info>UTF-8</schema-info>
</value-serializer>
</store>
<store>
<name>no-res</name>
<persistence>bdb</persistence>
<routing>client</routing>
<replication-factor>3</replication-factor>
<preferred-reads>2</preferred-reads>
<required-reads>2</required-reads>
<preferred-writes>2</preferred-writes>
<required-writes>2</required-writes>
<key-serializer>
<type>string</type>
<schema-info>UTF-8</schema-info>
</key-serializer>
<value-serializer>
<type>string</type>
<schema-info>UTF-8</schema-info>
</value-serializer>
</store>

</stores>
64 changes: 64 additions & 0 deletions test/unit/voldemort/utils/ClusterForkLiftToolTest.java
Expand Up @@ -6,6 +6,7 @@
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class ClusterForkLiftToolTest {
final static String STORES_XML = "test/common/voldemort/config/two-stores-replicated.xml";
final static String PRIMARY_RESOLVING_STORE_NAME = "test";
final static String GLOBALLY_RESOLVING_STORE_NAME = "best";
final static String MULTIPLE_VERSIONS_STORE_NAME = "no-res";

private String srcBootStrapUrl;
private String dstBootStrapUrl;
Expand All @@ -51,6 +53,7 @@ public class ClusterForkLiftToolTest {

private StoreDefinition primaryResolvingStoreDef;
private StoreDefinition globallyResolvingStoreDef;
private StoreDefinition nonResolvingStoreDef;

private HashMap<String, String> kvPairs;
private String firstKey;
Expand Down Expand Up @@ -124,6 +127,8 @@ public void setUpClusters() {
globallyResolvingStoreDef = StoreUtils.getStoreDef(storeDefs,
GLOBALLY_RESOLVING_STORE_NAME);

nonResolvingStoreDef = StoreUtils.getStoreDef(storeDefs, MULTIPLE_VERSIONS_STORE_NAME);

srcfactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(srcBootStrapUrl)
.setSelectors(1)
.setRoutingTimeout(1000,
Expand Down Expand Up @@ -286,6 +291,65 @@ public void testGloballyResolvingForkLift() throws Exception {
}
}

@Test
public void testNoresolutionForkLift() throws Exception {

int versions = 0;

StoreInstance srcStoreInstance = new StoreInstance(srcCluster, nonResolvingStoreDef);

// generate a conflict on the master partition
int masterNode = srcStoreInstance.getNodeIdForPartitionId(srcStoreInstance.getMasterPartitionId(conflictKey.getBytes("UTF-8")));
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,
new NodeValue<ByteArray, byte[]>(masterNode,
new ByteArray(conflictKey.getBytes("UTF-8")),
new Versioned<byte[]>("losing value".getBytes("UTF-8"),
losingClock)));
srcAdminClient.storeOps.putNodeKeyValue(MULTIPLE_VERSIONS_STORE_NAME,
new NodeValue<ByteArray, byte[]>(masterNode,
new ByteArray(conflictKey.getBytes("UTF-8")),
new Versioned<byte[]>("winning value".getBytes("UTF-8"),
winningClock)));
// perform the forklifting..
ClusterForkLiftTool forkLiftTool = new ClusterForkLiftTool(srcBootStrapUrl,
dstBootStrapUrl,
10000,
1,
1000,
Lists.newArrayList(MULTIPLE_VERSIONS_STORE_NAME),
null,
ClusterForkLiftTool.ForkLiftTaskMode.no_resolution);
forkLiftTool.run();

AdminClient dstAdminClient = new AdminClient(dstBootStrapUrl,
new AdminClientConfig(),
new ClientConfig());

for(Node node: dstAdminClient.getAdminClientCluster().getNodes()) {

Iterator<Pair<ByteArray, Versioned<byte[]>>> entryItr = srcAdminClient.bulkFetchOps.fetchEntries(node.getId(),
MULTIPLE_VERSIONS_STORE_NAME,
node.getPartitionIds(),
null,
true);

while(entryItr.hasNext()) {
Pair<ByteArray, Versioned<byte[]>> record = entryItr.next();
ByteArray key = record.getFirst();
Versioned<byte[]> versioned = record.getSecond();
versions++;

}

}
assertEquals("Both conflicting versions present", versions, 2);

}

@After
public void tearDownClusters() {

Expand Down

0 comments on commit b245e3b

Please sign in to comment.