Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of github.com:voldemort/voldemort

  • Loading branch information...
commit 34c9c1d03ff0e1e0cf990b73534ce9f47af2f2b0 2 parents b470708 + 4957e95
vinoth chandar vinothchandar authored
9 src/java/voldemort/versioning/TimeBasedInconsistencyResolver.java
@@ -33,21 +33,24 @@
33 33 } else {
34 34 Versioned<T> max = items.get(0);
35 35 long maxTime = ((VectorClock) items.get(0).getVersion()).getTimestamp();
  36 + VectorClock maxClock = ((VectorClock) items.get(0).getVersion());
36 37 for(Versioned<T> versioned: items) {
37 38 VectorClock clock = (VectorClock) versioned.getVersion();
38 39 if(clock.getTimestamp() > maxTime) {
39 40 max = versioned;
40 41 maxTime = ((VectorClock) versioned.getVersion()).getTimestamp();
41 42 }
  43 + maxClock = maxClock.merge(clock);
42 44 }
43   - return Collections.singletonList(max);
  45 + Versioned<T> maxTimeClockVersioned = new Versioned<T>(max.getValue(), maxClock);
  46 + return Collections.singletonList(maxTimeClockVersioned);
44 47 }
45 48 }
46 49
47   -
48 50 @Override
49 51 public boolean equals(Object o) {
50   - if (this == o) return true;
  52 + if(this == o)
  53 + return true;
51 54 return (o != null && getClass() == o.getClass());
52 55 }
53 56
142 test/unit/voldemort/versioning/ChainedInconsistencyResolverTest.java
... ... @@ -0,0 +1,142 @@
  1 +package voldemort.versioning;
  2 +
  3 +import java.io.IOException;
  4 +import java.util.ArrayList;
  5 +import java.util.List;
  6 +import java.util.Properties;
  7 +
  8 +import junit.framework.TestCase;
  9 +
  10 +import org.junit.After;
  11 +import org.junit.Test;
  12 +
  13 +import voldemort.ServerTestUtils;
  14 +import voldemort.TestUtils;
  15 +import voldemort.VoldemortTestConstants;
  16 +import voldemort.client.ClientConfig;
  17 +import voldemort.client.SocketStoreClientFactory;
  18 +import voldemort.client.StoreClient;
  19 +import voldemort.client.StoreClientFactory;
  20 +import voldemort.client.protocol.RequestFormatType;
  21 +import voldemort.cluster.Cluster;
  22 +import voldemort.cluster.Node;
  23 +import voldemort.server.VoldemortServer;
  24 +import voldemort.store.Store;
  25 +import voldemort.store.socket.SocketStoreFactory;
  26 +import voldemort.store.socket.clientrequest.ClientRequestExecutorPool;
  27 +import voldemort.utils.ByteArray;
  28 +
  29 +/*
  30 + * Test to ensure that the TimeBasedInconsistencyResolver returns a max Vector
  31 + * clock with the max timestamp.
  32 + */
  33 +public class ChainedInconsistencyResolverTest extends TestCase {
  34 +
  35 + private static final String KEY = "XYZ";
  36 + private Versioned<String> v1, v2;
  37 + private Versioned<String> conflict1, conflict2, conflict3, conflict4, conflict5, conflict6;
  38 +
  39 + private Node node;
  40 + private Cluster cluster;
  41 + private StoreClient<String, String> defaultStoreClient;
  42 + private Store<ByteArray, byte[], byte[]> socketStore;
  43 + private List<VoldemortServer> servers;
  44 + private final SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2,
  45 + 10000,
  46 + 100000,
  47 + 32 * 1024);
  48 + private final boolean useNio = false;
  49 + private static final String STORES_XML = "test/common/voldemort/config/single-store.xml";
  50 +
  51 + @Override
  52 + public void setUp() throws IOException {
  53 + VoldemortTestConstants.getSingleStoreDefinitionsXml();
  54 + this.cluster = ServerTestUtils.getLocalCluster(2);
  55 + this.node = cluster.getNodes().iterator().next();
  56 + String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
  57 + StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
  58 + servers = new ArrayList<VoldemortServer>();
  59 + servers.add(ServerTestUtils.startVoldemortServer(socketStoreFactory,
  60 + ServerTestUtils.createServerConfig(useNio,
  61 + 0,
  62 + TestUtils.createTempDir()
  63 + .getAbsolutePath(),
  64 + null,
  65 + STORES_XML,
  66 + new Properties()),
  67 + cluster));
  68 + servers.add(ServerTestUtils.startVoldemortServer(socketStoreFactory,
  69 + ServerTestUtils.createServerConfig(useNio,
  70 + 1,
  71 + TestUtils.createTempDir()
  72 + .getAbsolutePath(),
  73 + null,
  74 + STORES_XML,
  75 + new Properties()),
  76 + cluster));
  77 +
  78 + // Initialize versioned puts for basic test
  79 + v1 = getVersioned(0, 1, 1, 1, 1, 1);
  80 + v2 = getVersioned(0, 0, 1, 1, 1, 1);
  81 +
  82 + // Initialize versioned puts for > 1 conflicts
  83 + conflict1 = getVersioned(0, 1, 1, 1, 1, 1, 1, 1, 1, 1);
  84 + conflict2 = getVersioned(0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
  85 + conflict3 = getVersioned(0, 0, 0, 1, 1, 1, 1, 1, 1, 1);
  86 + conflict4 = getVersioned(0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
  87 + conflict5 = getVersioned(0, 0, 0, 0, 0, 1, 1, 1, 1, 1);
  88 + conflict6 = getVersioned(0, 0, 0, 0, 0, 0, 1, 1, 1, 1);
  89 +
  90 + defaultStoreClient = storeClientFactory.getStoreClient("test");
  91 + socketStore = ServerTestUtils.getSocketStore(socketStoreFactory,
  92 + "test",
  93 + node.getSocketPort(),
  94 + RequestFormatType.VOLDEMORT_V1);
  95 + }
  96 +
  97 + @Override
  98 + @After
  99 + public void tearDown() throws Exception {
  100 + socketStore.close();
  101 + socketStoreFactory.close();
  102 + }
  103 +
  104 + private Versioned<String> getVersioned(int... nodes) {
  105 + return new Versioned<String>("my-value", TestUtils.getClock(nodes));
  106 + }
  107 +
  108 + @Test
  109 + public void testVersionedPut() {
  110 + defaultStoreClient.put(KEY, v1);
  111 + defaultStoreClient.put(KEY, v2);
  112 + Versioned<String> res = defaultStoreClient.get(KEY);
  113 + defaultStoreClient.put(KEY, res);
  114 + List<Versioned<byte[]>> resList = socketStore.get(new ByteArray(KEY.getBytes()), null);
  115 + assertEquals(1, resList.size());
  116 + }
  117 +
  118 + @Test
  119 + public void testNormalPut() {
  120 + defaultStoreClient.put(KEY, v1);
  121 + defaultStoreClient.put(KEY, v2);
  122 + defaultStoreClient.put(KEY, "my-value2");
  123 + List<Versioned<byte[]>> resList = socketStore.get(new ByteArray(KEY.getBytes()), null);
  124 + assertEquals(1, resList.size());
  125 + }
  126 +
  127 + @Test
  128 + public void testMoreConflicts() {
  129 + defaultStoreClient.put(KEY, conflict1);
  130 + defaultStoreClient.put(KEY, conflict2);
  131 + defaultStoreClient.put(KEY, conflict3);
  132 + defaultStoreClient.put(KEY, conflict4);
  133 + defaultStoreClient.put(KEY, conflict5);
  134 + defaultStoreClient.put(KEY, conflict6);
  135 + List<Versioned<byte[]>> resList = socketStore.get(new ByteArray(KEY.getBytes()), null);
  136 + assertEquals(6, resList.size());
  137 + Versioned<String> res = defaultStoreClient.get(KEY);
  138 + defaultStoreClient.put(KEY, res);
  139 + resList = socketStore.get(new ByteArray(KEY.getBytes()), null);
  140 + assertEquals(1, resList.size());
  141 + }
  142 +}

0 comments on commit 34c9c1d

Please sign in to comment.
Something went wrong with that request. Please try again.