dschneider-pivotal commented on a change in pull request #6768:
URL: https://github.com/apache/geode/pull/6768#discussion_r697727929



##########
File path: 
geode-apis-compatible-with-redis/src/test/java/org/apache/geode/redis/internal/collections/SizeableBytes2ObjectOpenCustomHashMapWithCursorTest.java
##########
@@ -111,108 +134,115 @@ public void 
twoScansWithNoModifications_ReturnsExpectedElements() {
 
   @Test
   public void scanWithConcurrentRemoves_ReturnsExpectedElements() {
-    Integer2StringMap map = new Integer2StringMap();
-    IntStream.range(0, 10).forEach(i -> map.put(i, "value-" + i));
+    final int MAP_SIZE = 10;
+    Bytes2StringMap map = new Bytes2StringMap(MAP_SIZE * 2); // *2 to prevent 
rehash
+    fillMapWithUniqueHashKeys(map, MAP_SIZE);
+    Map<byte[], String> scanned = new 
Object2ObjectOpenCustomHashMap<>(ByteArrays.HASH_STRATEGY);
 
-    Map<Integer, String> scanned = new HashMap<>();
-    int cursor = map.scan(0, 5, Map::put, scanned);
-    assertThat(scanned).hasSize(5);
+    int cursor = map.scan(0, MAP_SIZE / 2, Map::put, scanned);
+    assertThat(scanned).hasSize(MAP_SIZE / 2);
 
     // Remove some of the elements
-    map.remove(2);
-    map.remove(4);
-    map.remove(5);
-    map.remove(7);
+    Iterator<Map.Entry<byte[], String>> iterator = map.entrySet().iterator();
+    int removeCount = MAP_SIZE / 2 - 1;
+    while (removeCount > 0 && iterator.hasNext()) {
+      iterator.next();
+      iterator.remove();
+      removeCount--;
+    }
 
-    cursor = map.scan(cursor, 5, Map::put, scanned);
+    cursor = map.scan(cursor, MAP_SIZE / 2, Map::put, scanned);
     assertThat(cursor).isEqualTo(0);
 
-    assertThat(scanned).containsKeys(0, 1, 3, 6, 8, 9);
+    assertThat(scanned.values()).containsAll(map.values());
   }
 
   @Test
   public void scanWithHashcodeCollisions_ReturnsExpectedElements() {
-    Integer2StringMap map = new Integer2StringMap(COLLIDING_HASH);
-    IntStream.range(0, 10).forEach(i -> map.put(i, "value-" + i));
+    final int MAP_SIZE = 10;
+    Bytes2StringMap map = new Bytes2StringMap(MAP_SIZE * 2); // *2 to prevent 
rehash
+    fillMapWithCollidingHashKeys(map, MAP_SIZE);
+    Map<byte[], String> scanned = new 
Object2ObjectOpenCustomHashMap<>(ByteArrays.HASH_STRATEGY);
 
-    // The colliding hash is just key % 5. So 0 and 5 will have the same 
hashcode, etc.
-    Map<Integer, String> scanned = new HashMap<>();
     int cursor = map.scan(0, 1, Map::put, scanned);
 
     // The scan had to ignore the count and return all of the elements with 
the same hash
-    assertThat(scanned).hasSize(2);
-
-    cursor = map.scan(cursor, 1, Map::put, scanned);
-    assertThat(scanned).hasSize(4);
-    cursor = map.scan(cursor, 1, Map::put, scanned);
-    assertThat(scanned).hasSize(6);
-    cursor = map.scan(cursor, 1, Map::put, scanned);
-    assertThat(scanned).hasSize(8);
-    cursor = map.scan(cursor, 1, Map::put, scanned);
-    assertThat(scanned).hasSize(10);
+    assertThat(scanned).hasSize(MAP_SIZE);
+    assertThat(scanned).isEqualTo(map);
     cursor = map.scan(cursor, 1, Map::put, scanned);
-    assertThat(scanned).hasSize(10);
-
-    assertThat(cursor).isEqualTo(0);
+    assertThat(cursor).isZero();
+    assertThat(scanned).hasSize(MAP_SIZE);
     assertThat(scanned).isEqualTo(map);
   }
 
   @Test
   public void 
scanWithHashcodeCollisionsAndConcurrentRemoves_ReturnsExpectedElements() {
-    Integer2StringMap map = new Integer2StringMap(COLLIDING_HASH);
-    IntStream.range(0, 10).forEach(i -> map.put(i, "value-" + i));
+    final int MAP_SIZE = 10;
+    Bytes2StringMap map = new Bytes2StringMap(MAP_SIZE * 2); // *2 to prevent 
rehash
+    fillMapWithCollidingHashKeys(map, MAP_SIZE);
+    Map<byte[], String> scanned = new 
Object2ObjectOpenCustomHashMap<>(ByteArrays.HASH_STRATEGY);
 
-    Map<Integer, String> scanned = new HashMap<>();
-    int cursor = map.scan(0, 5, Map::put, scanned);
-    assertThat(scanned).hasSize(6);
+    int cursor = map.scan(0, MAP_SIZE / 2, Map::put, scanned);
+    assertThat(scanned).hasSize(MAP_SIZE);
 
     // Remove some of the elements
-    map.remove(2);
-    map.remove(4);
-    map.remove(5);
-    map.remove(7);
+    Iterator<Map.Entry<byte[], String>> iterator = map.entrySet().iterator();
+    int removeCount = MAP_SIZE / 2 - 1;
+    while (removeCount > 0 && iterator.hasNext()) {
+      iterator.next();
+      iterator.remove();
+      removeCount--;
+    }
 
-    cursor = map.scan(cursor, 5, Map::put, scanned);
+    cursor = map.scan(cursor, MAP_SIZE / 2, Map::put, scanned);
 
     assertThat(cursor).isEqualTo(0);
-    assertThat(scanned).containsKeys(0, 1, 3, 6, 8, 9);
+    assertThat(scanned).hasSize(MAP_SIZE);
   }
 
   @Test
   public void scanWithGrowingTable_DoesNotMissElements() {
-    Integer2StringMap map = new Integer2StringMap();
-    IntStream.range(0, 10).forEach(i -> map.put(i, "value-" + i));
-
-    Map<Integer, String> scanned = new HashMap<>();
-    int cursor = map.scan(0, 5, Map::put, scanned);
-    assertThat(scanned).hasSize(5);
+    final int MAP_SIZE = 10;
+    Bytes2StringMap map = new Bytes2StringMap(MAP_SIZE * 2); // *2 to prevent 
rehash
+    fillMapWithUniqueHashKeys(map, MAP_SIZE);
+    Map<byte[], String> scanned = new 
Object2ObjectOpenCustomHashMap<>(ByteArrays.HASH_STRATEGY);
+    ArrayList<byte[]> initialKeys = new ArrayList<>(map.keySet());

Review comment:
       yes




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to