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 2020/11/19 02:04:27 UTC

[accumulo] branch main updated: Fix warning and simplify ScannerBaseTest

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 74afbab  Fix warning and simplify ScannerBaseTest
74afbab is described below

commit 74afbabb06ba319cbb3968f30dcca58aa67fa070
Author: Christopher Tubbs <ct...@apache.org>
AuthorDate: Wed Nov 18 20:41:16 2020 -0500

    Fix warning and simplify ScannerBaseTest
    
    This simplifies the test added in #1765 and fixes the generics warning
    that was previously present there.
---
 .../accumulo/core/clientImpl/ScannerBaseTest.java  | 125 ++++-----------------
 1 file changed, 21 insertions(+), 104 deletions(-)

diff --git a/core/src/test/java/org/apache/accumulo/core/clientImpl/ScannerBaseTest.java b/core/src/test/java/org/apache/accumulo/core/clientImpl/ScannerBaseTest.java
index 3f62522..9761937 100644
--- a/core/src/test/java/org/apache/accumulo/core/clientImpl/ScannerBaseTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/clientImpl/ScannerBaseTest.java
@@ -18,123 +18,40 @@
  */
 package org.apache.accumulo.core.clientImpl;
 
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.partialMockBuilder;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
 
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
 
-import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.client.ScannerBase;
-import org.apache.accumulo.core.client.sample.SamplerConfiguration;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.security.Authorizations;
-import org.apache.hadoop.io.Text;
 import org.junit.Test;
 
 public class ScannerBaseTest {
 
   @Test
   public void testScannerBaseForEach() throws Exception {
-
-    // This subclass of ScannerBase contains a List that ScannerBase.forEach() can
-    // iterate over for testing purposes.
-    class MockScanner implements ScannerBase {
-
-      Map<Key,Value> map;
-
-      MockScanner(Map<Key,Value> map) {
-        this.map = map;
-      }
-
-      @Override
-      public void addScanIterator(IteratorSetting cfg) {}
-
-      @Override
-      public void removeScanIterator(String iteratorName) {}
-
-      @Override
-      public void updateScanIteratorOption(String iteratorName, String key, String value) {}
-
-      @Override
-      public void fetchColumnFamily(Text col) {}
-
-      @Override
-      public void fetchColumn(Text colFam, Text colQual) {}
-
-      @Override
-      public void fetchColumn(IteratorSetting.Column column) {}
-
-      @Override
-      public void clearColumns() {}
-
-      @Override
-      public void clearScanIterators() {}
-
-      @Override
-      public Iterator<Map.Entry<Key,Value>> iterator() {
-        return this.map.entrySet().iterator();
-      }
-
-      @Override
-      public void setTimeout(long timeOut, TimeUnit timeUnit) {}
-
-      @Override
-      public long getTimeout(TimeUnit timeUnit) {
-        return 0;
-      }
-
-      @Override
-      public void close() {}
-
-      @Override
-      public Authorizations getAuthorizations() {
-        return null;
-      }
-
-      @Override
-      public void setSamplerConfiguration(SamplerConfiguration samplerConfig) {}
-
-      @Override
-      public SamplerConfiguration getSamplerConfiguration() {
-        return null;
-      }
-
-      @Override
-      public void clearSamplerConfiguration() {}
-
-      @Override
-      public void setBatchTimeout(long timeOut, TimeUnit timeUnit) {}
-
-      @Override
-      public long getBatchTimeout(TimeUnit timeUnit) {
-        return 0;
-      }
-
-      @Override
-      public void setClassLoaderContext(String classLoaderContext) {}
-
-      @Override
-      public void clearClassLoaderContext() {}
-
-      @Override
-      public String getClassLoaderContext() {
-        return null;
-      }
-    }
-
-    Map<Key,Value> map = new HashMap<>();
-    MockScanner ms = new MockScanner(Map
-        .of(new Key(new Text("a"), new Text("cf1"), new Text("cq1")), new Value(new Text("v1"))));
-    Map.Entry entry = ms.iterator().next();
-    // Test forEach from ScannerBase
-    ms.forEach((k, v) -> map.put(k, v));
-
-    for (Map.Entry<Key,Value> e : map.entrySet()) {
-      assertEquals(entry.getKey(), e.getKey());
-      assertEquals(entry.getValue(), e.getValue());
-    }
+    Map<Key,Value> expected =
+        Map.of(new Key("row1", "cf1", "cq1"), new Value("v1"), new Key("row2", "cf1", "cq1"),
+            new Value("v2"), new Key("row3", "cf1", "cq1"), new Value("v3"));
+
+    // mock ScannerOptions subclass, because EasyMock can't mock ScannerBase, an interface;
+    // only the iterator method is mocked, because the forEach method should only call iterator()
+    ScannerBase scanner =
+        partialMockBuilder(ScannerOptions.class).addMockedMethod("iterator").createMock();
+    expect(scanner.iterator()).andReturn(expected.entrySet().iterator()).once();
+    replay(scanner);
+
+    // check the results from forEach; they should match what iterator() returns
+    Map<Key,Value> actual = new HashMap<>();
+    scanner.forEach((k, v) -> actual.put(k, v));
+    assertEquals(expected, actual);
+
+    verify(scanner);
   }
 }