You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2022/02/01 23:00:53 UTC

[accumulo] branch main updated: Simplify and fix broken AgeOffFilterTest (#2452)

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

ctubbsii pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/main by this push:
     new 7f082d5  Simplify and fix broken AgeOffFilterTest (#2452)
7f082d5 is described below

commit 7f082d5fe21da65123c2e3897bb79ae48264e2cd
Author: Christopher Tubbs <ct...@apache.org>
AuthorDate: Tue Feb 1 18:00:42 2022 -0500

    Simplify and fix broken AgeOffFilterTest (#2452)
    
    This fixes #2449
---
 .../junit4/BaseJUnit4IteratorTest.java             |   4 +-
 .../accumulo/test/iterator/AgeOffFilterTest.java   | 119 ++++++++-------------
 2 files changed, 47 insertions(+), 76 deletions(-)

diff --git a/iterator-test-harness/src/main/java/org/apache/accumulo/iteratortest/junit4/BaseJUnit4IteratorTest.java b/iterator-test-harness/src/main/java/org/apache/accumulo/iteratortest/junit4/BaseJUnit4IteratorTest.java
index 7bbaa5c..3c52151 100644
--- a/iterator-test-harness/src/main/java/org/apache/accumulo/iteratortest/junit4/BaseJUnit4IteratorTest.java
+++ b/iterator-test-harness/src/main/java/org/apache/accumulo/iteratortest/junit4/BaseJUnit4IteratorTest.java
@@ -96,9 +96,9 @@ public class BaseJUnit4IteratorTest {
     IteratorTestReport report = reports.get(0);
     assertNotNull(report);
 
-    assertTrue(report.getSummary(), report.didTestSucceed());
-
     // Present for manual verification
     log.trace("Expected: {}, Actual: {}", report.getExpectedOutput(), report.getActualOutput());
+
+    assertTrue(report.getSummary(), report.didTestSucceed());
   }
 }
diff --git a/test/src/test/java/org/apache/accumulo/test/iterator/AgeOffFilterTest.java b/test/src/test/java/org/apache/accumulo/test/iterator/AgeOffFilterTest.java
index 44a951d..90233eb 100644
--- a/test/src/test/java/org/apache/accumulo/test/iterator/AgeOffFilterTest.java
+++ b/test/src/test/java/org/apache/accumulo/test/iterator/AgeOffFilterTest.java
@@ -18,8 +18,9 @@
  */
 package org.apache.accumulo.test.iterator;
 
-import java.util.List;
-import java.util.Map.Entry;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Map;
 import java.util.TreeMap;
 
 import org.apache.accumulo.core.client.IteratorSetting;
@@ -34,94 +35,64 @@ import org.apache.accumulo.iteratortest.junit4.BaseJUnit4IteratorTest;
 import org.apache.accumulo.iteratortest.testcases.IteratorTestCase;
 import org.junit.runners.Parameterized.Parameters;
 
-import com.google.common.collect.Iterables;
-
 /**
  * Iterator test harness tests for AgeOffFilter
  */
 public class AgeOffFilterTest extends BaseJUnit4IteratorTest {
-  public static long NOW;
-  public static long TTL;
+  private static final long NOW = 12345678; // arbitrary base time
+  private static final long TTL = 30_000; // 30 seconds
 
   @Parameters
   public static Object[][] parameters() {
-    // Test ageoff after 30 seconds.
-    NOW = System.currentTimeMillis();
-    TTL = 30 * 1000;
+    var opts = createOpts();
+    var input = createInputData(opts);
+    var output = createOutputData(input);
+    assertEquals(15, input.getInput().size());
+    assertEquals(10, output.getOutput().size());
 
-    IteratorTestInput input = getIteratorInput();
-    IteratorTestOutput output = getIteratorOutput();
-    List<IteratorTestCase> tests = IteratorTestCaseFinder.findAllTestCases();
+    var tests = IteratorTestCaseFinder.findAllTestCases();
     return BaseJUnit4IteratorTest.createParameters(input, output, tests);
   }
 
-  private static final TreeMap<Key,Value> INPUT_DATA = createInputData();
-  private static final TreeMap<Key,Value> OUTPUT_DATA = createOutputData();
-
-  private static TreeMap<Key,Value> createInputData() {
-    TreeMap<Key,Value> data = new TreeMap<>();
-    final Value value = new Value(new byte[] {'a'});
-
-    data.put(new Key("1", "a", "a", nowDelta(25)), value);
-    data.put(new Key("2", "a", "a", nowDelta(35)), value);
-    data.put(new Key("3", "a", "a", nowDelta(55)), value);
-    data.put(new Key("4", "a", "a", nowDelta(0)), value);
-    data.put(new Key("5", "a", "a", nowDelta(-29)), value);
-    data.put(new Key("6", "a", "a", nowDelta(-28)), value);
-    // Dropped
-    data.put(new Key("7", "a", "a", nowDelta(-40)), value);
-    // Dropped (comparison is not inclusive)
-    data.put(new Key("8", "a", "a", nowDelta(-30)), value);
-    // Dropped
-    data.put(new Key("9", "a", "a", nowDelta(-31)), value);
-
-    // Dropped
-    data.put(new Key("a", "", "", nowDelta(-50)), value);
-    data.put(new Key("a", "a", "", nowDelta(-20)), value);
-    data.put(new Key("a", "a", "a", nowDelta(50)), value);
-    data.put(new Key("a", "a", "b", nowDelta(-15)), value);
-    // Dropped
-    data.put(new Key("a", "a", "c", nowDelta(-32)), value);
-    // Dropped
-    data.put(new Key("a", "a", "d", nowDelta(-32)), value);
-
-    return data;
-  }
-
-  /**
-   * Compute a timestamp (milliseconds) based on {@link #NOW} plus the <code>seconds</code>
-   * argument.
-   *
-   * @param seconds
-   *          The number of seconds to add to <code>NOW</code> .
-   * @return A Key timestamp the provided number of seconds after <code>NOW</code>.
-   */
-  private static long nowDelta(long seconds) {
-    return NOW + (seconds * 1000);
-  }
-
-  private static TreeMap<Key,Value> createOutputData() {
-    TreeMap<Key,Value> data = new TreeMap<>();
-
-    Iterable<Entry<Key,Value>> filtered =
-        Iterables.filter(data.entrySet(), input -> NOW - input.getKey().getTimestamp() > TTL);
-
-    for (Entry<Key,Value> entry : filtered) {
-      data.put(entry.getKey(), entry.getValue());
-    }
-
-    return data;
-  }
-
-  private static IteratorTestInput getIteratorInput() {
+  // set up the iterator
+  private static Map<String,String> createOpts() {
     IteratorSetting setting = new IteratorSetting(50, AgeOffFilter.class);
     AgeOffFilter.setCurrentTime(setting, NOW);
     AgeOffFilter.setTTL(setting, TTL);
-    return new IteratorTestInput(AgeOffFilter.class, setting.getOptions(), new Range(), INPUT_DATA);
+    return setting.getOptions();
+  }
+
+  // create data with timestamps greater than, equal to, and less than NOW
+  // the ones that would be dropped are ones that are older than NOW - TTL
+  private static IteratorTestInput createInputData(Map<String,String> opts) {
+    TreeMap<Key,Value> data = new TreeMap<>();
+    final Value value = new Value("a");
+
+    data.put(new Key("1", "a", "a", NOW + 25_000), value);
+    data.put(new Key("2", "a", "a", NOW + 35_000), value);
+    data.put(new Key("3", "a", "a", NOW + 55_000), value);
+    data.put(new Key("4", "a", "a", NOW + 00_000), value);
+    data.put(new Key("5", "a", "a", NOW - 29_000), value);
+    data.put(new Key("6", "a", "a", NOW - 28_000), value);
+    data.put(new Key("7", "a", "a", NOW - 40_000), value); // Will drop
+    data.put(new Key("8", "a", "a", NOW - 30_000), value); // Not aged out (exclusive comparison)
+    data.put(new Key("9", "a", "a", NOW - 31_000), value); // Will drop
+    data.put(new Key("a", "-", "-", NOW - 50_000), value); // Will drop
+    data.put(new Key("a", "a", "-", NOW - 20_000), value);
+    data.put(new Key("a", "a", "a", NOW + 50_000), value);
+    data.put(new Key("a", "a", "b", NOW - 15_000), value); // Will drop
+    data.put(new Key("a", "a", "c", NOW - 32_000), value); // Will drop
+    data.put(new Key("a", "a", "d", NOW - 32_000), value);
+
+    return new IteratorTestInput(AgeOffFilter.class, opts, new Range(), data);
   }
 
-  private static IteratorTestOutput getIteratorOutput() {
-    return new IteratorTestOutput(OUTPUT_DATA);
+  // create expected output data
+  // data should include all input data except those older than the time at NOW - TTL
+  private static IteratorTestOutput createOutputData(IteratorTestInput input) {
+    var data = new TreeMap<Key,Value>(input.getInput());
+    data.entrySet().removeIf(e -> e.getKey().getTimestamp() < NOW - TTL);
+    return new IteratorTestOutput(data);
   }
 
   public AgeOffFilterTest(IteratorTestInput input, IteratorTestOutput expectedOutput,