OPERATION_TIMEOUT,
new VoldemortException());
start = System.nanoTime();
try {
s1.put(new ByteArray("test".getBytes()), versioned, null);
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
// Putting extra key to test getAll
s1.put(new ByteArray("test2".getBytes()), versioned, null);
start = System.nanoTime();
try {
s1.get(new ByteArray("test".getBytes()), null);
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
start = System.nanoTime();
try {
List<Version> versions = s1.getVersions(new ByteArray("test".getBytes()));
for(Version version: versions) {
assertEquals(version.compare(versioned.getVersion()), Occurred.BEFORE);
}
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
start = System.nanoTime();
try {
s1.delete(new ByteArray("test".getBytes()), versioned.getVersion());
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
// make sure sleepy stores processed the delete before checking,
// otherwise, we might be bailing
// out of the test too early for the delete to be processed.
Thread.sleep(SLEEPY_TIME * 2);
List<ByteArray> keys = Lists.newArrayList(new ByteArray("test".getBytes()),
new ByteArray("test2".getBytes()));
Map<ByteArray, List<Versioned<byte[]>>> values = s1.getAll(keys, null);
assertFalse("'test' did not get deleted.",
values.containsKey(new ByteArray("test".getBytes())));
ByteUtils.compare(values.get(new ByteArray("test2".getBytes())).get(0).getValue(),
new byte[] { 1 });
// Basic put with zone read = 1, zone write = 1
Store<ByteArray, byte[], byte[]> s2 = getStore(cluster,
1,
1,
1,
1,
8,
null,
Sets.newHashSet(4, 5, 6, 7),
zoneReplicationFactor,
RoutingStrategyType.ZONE_STRATEGY,
SLEEPY_TIME,
BANNAGE_PERIOD,
new VoldemortException());
start = System.nanoTime();
try {
s2.put(new ByteArray("test".getBytes()), versioned, null);
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " > " + SLEEPY_TIME, elapsed >= SLEEPY_TIME);
}
s2.put(new ByteArray("test2".getBytes()), versioned, null);
try {
s2.get(new ByteArray("test".getBytes()), null);
fail("Should have shown exception");
} catch(InsufficientZoneResponsesException e) {
/*
* Why would you want responses from two zones and wait for only one
* response...
*/
}
try {
s2.getVersions(new ByteArray("test".getBytes()));
fail("Should have shown exception");
} catch(InsufficientZoneResponsesException e) {
/*
* Why would you want responses from two zones and wait for only one
* response...
*/
}
try {
s2.delete(new ByteArray("test".getBytes()), null);
} catch(InsufficientZoneResponsesException e) {
/*
* Why would you want responses from two zones and wait for only one
* response...
*/
}
values = s2.getAll(keys, null);
assertFalse("'test' did not get deleted.",
values.containsKey(new ByteArray("test".getBytes())));
ByteUtils.compare(values.get(new ByteArray("test2".getBytes())).get(0).getValue(),
new byte[] { 1 });
// Basic put with zone read = 0, zone write = 0 and failures in other
// dc, but should still work
Store<ByteArray, byte[], byte[]> s3 = getStore(cluster,
1,
1,
0,
0,
8,
Sets.newHashSet(4, 5, 6, 7),
null,
zoneReplicationFactor,
RoutingStrategyType.ZONE_STRATEGY,
SLEEPY_TIME,
BANNAGE_PERIOD,
new VoldemortException());
start = System.nanoTime();
try {
s3.put(new ByteArray("test".getBytes()), versioned, null);
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
// Putting extra key to test getAll
s3.put(new ByteArray("test2".getBytes()), versioned, null);
start = System.nanoTime();
try {
List<Version> versions = s3.getVersions(new ByteArray("test".getBytes()));
for(Version version: versions) {
assertEquals(version.compare(versioned.getVersion()), Occurred.BEFORE);
}
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
start = System.nanoTime();
try {
s3.get(new ByteArray("test".getBytes()), null);
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
start = System.nanoTime();
try {
s3.delete(new ByteArray("test".getBytes()), versioned.getVersion());
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
// Basic put with zone read = 1, zone write = 1 and failures in other
// dc, should not work
Store<ByteArray, byte[], byte[]> s4 = getStore(cluster,
2,
2,
1,
1,
8,
Sets.newHashSet(4, 5, 6, 7),
null,
zoneReplicationFactor,
RoutingStrategyType.ZONE_STRATEGY,
SLEEPY_TIME,
BANNAGE_PERIOD,
new VoldemortException());
try {
s4.put(new ByteArray("test".getBytes()), new Versioned<byte[]>(new byte[] { 1 }), null);
fail("Should have shown exception");
} catch(InsufficientZoneResponsesException e) {
/*
* The other zone is down and you expect a result from both zones
*/
}
try {
s4.getVersions(new ByteArray("test".getBytes()));
fail("Should have shown exception");
} catch(InsufficientZoneResponsesException e) {
/*
* The other zone is down and you expect a result from both zones
*/
}
try {
s4.get(new ByteArray("test".getBytes()), null);
fail("Should have shown exception");
} catch(InsufficientZoneResponsesException e) {
/*
* The other zone is down and you expect a result from both zones
*/
}
try {
s4.delete(new ByteArray("test".getBytes()), versioned.getVersion());
fail("Should have shown exception");
} catch(InsufficientZoneResponsesException e) {
/*
* The other zone is down and you expect a result from both zones
*/