This is an automated email from the ASF dual-hosted git repository.

ringles pushed a commit to branch WIP-GEODE-9892
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/WIP-GEODE-9892 by this push:
     new 2f6032d  clean up lpop verification logic
2f6032d is described below

commit 2f6032dc1ebfe99a053e675f09dddbb669bb092c
Author: Ray Ingles <[email protected]>
AuthorDate: Fri Feb 11 17:42:15 2022 -0500

    clean up lpop verification logic
---
 .../commands/executor/list/LPopDUnitTest.java      | 64 +++++++---------------
 1 file changed, 21 insertions(+), 43 deletions(-)

diff --git 
a/geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java
 
b/geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java
index 46cfa2c..119b3f2 100644
--- 
a/geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java
+++ 
b/geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/LPopDUnitTest.java
@@ -154,58 +154,36 @@ public class LPopDUnitTest {
   }
 
   private void lpopPerformAndVerify(String key, List<String> elementList, 
AtomicLong runningCount) {
-    int iterationCount = 0;
-    List<String> poppedList = new ArrayList<>();
-    String previousElement = "";
-    int duplicateCount = 0;
     logger.info(key + ": length is " + jedis.llen(key));
     assertThat(jedis.llen(key)).isGreaterThanOrEqualTo(MINIMUM_ITERATIONS);
+
+    // while stuff still in list, and test still running
+    // figure out what we expect
+    // pop an element
+    // if not what we expect
+    // how different is it?
+    // if within threshold, update expected
+
+    int elementCount = MINIMUM_ITERATIONS - 1;
     while (jedis.llen(key) > 0 && runningCount.get() > 0) {
-      iterationCount++;
-      String expected = elementList.get(elementList.size() - iterationCount);
+      String expected = key + "-" + (elementCount - 1) + "-";
+      String element = expected;
       try {
-        String element = jedis.lpop(key);
-        if (element.equals(previousElement)) {
-          if (duplicateCount > 0) {
-            fail("LPOP found more than one duplicate list entry in a row: " + 
element);
-          }
-          // Sometimes operations can get duplicated when buckets are moved or 
servers
-          // crash.
-          logger.info(key + ": found duplicate " + element + " at iteration " 
+ iterationCount);
-          duplicateCount++;
-          continue;
-        } else {
-          if (!previousElement.equals("")) {
-            String[] chunks = element.split("-");
-            int elementCount = Integer.parseInt(chunks[4]);
-            chunks = expected.split("-");
-            int expectedCount = Integer.parseInt(chunks[4]);
-            int elementDiff = expectedCount - elementCount;
-            if (elementDiff > 1) {
-              fail("LPOP repeated more than once for: " + element + " xc: " + 
expectedCount
-                  + " ec: " + elementCount + " ic: " + iterationCount + " 
prev: "
-                  + previousElement);
-            } else {
-              previousElement = element;
-              continue;
-            }
+        element = jedis.lpop(key);
+        if (!element.equals(expected)) {
+          int expectedCount = elementCount - 1;
+          String[] chunks = element.split("-");
+          elementCount = Integer.parseInt(chunks[4]);
+          int elementDiff = expectedCount - elementCount;
+          if (elementDiff > 1) {
+            fail("LPOP repeated more than once for: " + element + " xc: " + 
expectedCount
+                + " ec: " + elementCount);
           }
         }
-        assertThat(poppedList).as(
-            "LPOP returned duplicate element from key %s at iteration %s (%s)",
-            key, iterationCount, element)
-            .doesNotContain(element);
-        assertThat(element)
-            .as("LPOP returned unexpected element from key %s at iteration %s 
(was %s, expected %s, previous: %s)",
-                key, iterationCount, element, expected, previousElement)
-            .isEqualTo(expected);
-        poppedList.add(element);
-        previousElement = element;
-        duplicateCount = 0;
       } catch (Exception ex) {
         runningCount.set(0); // test is over
         throw new RuntimeException("Exception performing LPOP for list '"
-            + key + "' at iteration " + iterationCount + ": " + 
ex.getMessage());
+            + key + "' at element " + element + ": " + ex.getMessage());
       }
     }
     if (runningCount.get() > 0) {

Reply via email to