protected void assertConsistencyAwareGetEquals(final Map<String, V> map, final String key, final Object equals) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { assertEquals(map.get(key), equals); } }); }
@Test(groups = { "integration", "live" }) public void testContainsKey() throws InterruptedException, ExecutionException, TimeoutException, IOException { String containerNameName = getContainerName(); try { Map<String, V> map = createMap(view, containerNameName); assertConsistencyAwareDoesntContainKey(map); putStringWithMD5(map, "one", "apple"); assertConsistencyAwareContainsKey(map); } finally { returnContainer(containerNameName); } }
@Test(groups = { "integration", "live" }) public void testIsEmpty() throws InterruptedException, ExecutionException, TimeoutException, IOException { String containerNameName = getContainerName(); try { Map<String, V> map = createMap(view, containerNameName); assertConsistencyAwareEmpty(map); putStringWithMD5(map, "one", "apple"); assertConsistencyAwareNotEmpty(map); } finally { returnContainer(containerNameName); } }
@Test(groups = { "integration", "live" }) public void testKeySet() throws InterruptedException, ExecutionException, TimeoutException, IOException { String containerNameName = getContainerName(); try { Map<String, V> map = createMap(view, containerNameName); assertConsistencyAwareKeySize(map, 0); putStringWithMD5(map, "one", "two"); assertConsistencyAwareKeySize(map, 1); assertConsistencyAwareKeySetEquals(map, ImmutableSet.of("one")); } finally { returnContainer(containerNameName); } }
@Test(groups = { "integration", "live" }) public void testClear() throws InterruptedException, ExecutionException, TimeoutException, IOException { String containerNameName = getContainerName(); try { Map<String, V> map = createMap(view, containerNameName); assertConsistencyAwareMapSize(map, 0); putStringWithMD5(map, "one", "apple"); assertConsistencyAwareMapSize(map, 1); map.clear(); assertConsistencyAwareMapSize(map, 0); } finally { returnContainer(containerNameName); } }
@Test(groups = { "integration", "live" }) public void testDirectory() throws InterruptedException { String containerName = getContainerName(); String directory = "apps"; Map<String, V> rootMap = createMap(view, containerName); Map<String, V> rootRecursiveMap = createMap(view, containerName, recursive()); Map<String, V> inDirectoryMap = createMap(view, containerName, inDirectory(directory)); Map<String, V> inDirectoryRecursiveMap = createMap(view, containerName, inDirectory(directory).recursive()); try { addTenObjectsUnderRoot(containerName); assertEquals(rootMap.size(), 10); assertEquals(ImmutableSortedSet.copyOf(rootMap.keySet()), assertEquals(inDirectoryRecursiveMap.size(), 0); addTenObjectsUnderPrefix(containerName, directory); assertEquals(rootMap.size(), 10); assertEquals(ImmutableSortedSet.copyOf(rootMap.keySet()), returnContainer(containerName);
@Test(groups = { "integration", "live" }) public void testListContainer() throws InterruptedException, ExecutionException, TimeoutException { String containerNameName = getContainerName(); try { ListableMap<?, ?> map = (ListableMap<?, ?>) createMap(view, containerNameName); assertConsistencyAwareListContainer(map, containerNameName); } finally { returnContainer(containerNameName); } }
protected void fourLeftRemovingOne(Map<String, V> map) throws InterruptedException { map.remove("one"); assertConsistencyAwareMapSize(map, 4); assertConsistencyAwareKeySetEquals(map, new TreeSet<String>(ImmutableSet.of("two", "three", "four", "five"))); }
protected void assertConsistencyAwareKeySize(final Map<String, V> map, final int size) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { assertEquals(map.keySet().size(), size); } }); }
protected void assertConsistencyAwareListContainer(final ListableMap<?, ?> map, final String containerNameName) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { assertTrue(Iterables.size(map.list()) >= 0); } }); }
protected void assertConsistencyAwareRemoveEquals(final Map<String, V> map, final String key, final Object equals) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { assertEquals(map.remove(key), equals); } }); }
protected void assertConsistencyAwareDoesntContainKey(final Map<String, V> map) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { assert !map.containsKey("one"); } }); }
protected void assertConsistencyAwareMapSize(final Map<String, V> map, final int size) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { assertEquals(map.size(), size); } }); }
/** * containsValue() uses eTag comparison to containerName contents, so this can be subject to * eventual consistency problems. */ protected void assertConsistencyAwareContainsValue(final Map<String, V> map, final Object value) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { assert map.containsValue(value); } }); }
protected void assertConsistencyAwareContainsKey(final Map<String, V> map) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { assert map.containsKey("one"); } }); }
protected void assertConsistencyAwareNotEmpty(final Map<String, V> map) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { assert !map.isEmpty(); } }); }
protected void assertConsistencyAwareEmpty(final Map<String, V> map) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { assert map.isEmpty(); } }); }
protected void assertConsistencyAwareKeySetEquals(final Map<String, V> map, final Set<String> expected) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { Set<String> toMatch = map.keySet(); Set<String> shouldBeEmpty = Sets.difference(expected, toMatch); assert shouldBeEmpty.size() == 0 : "toMatch has less keys than expected. missing: " + shouldBeEmpty; shouldBeEmpty = Sets.difference(toMatch, expected); assert shouldBeEmpty.size() == 0 : "toMatch has more keys than expected. extras: " + shouldBeEmpty; assertEquals(Sets.newTreeSet(toMatch), Sets.newTreeSet(expected)); } }); }