From commits-return-24346-archive-asf-public=cust-asf.ponee.io@accumulo.apache.org Thu Nov 19 02:04:28 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mxout1-ec2-va.apache.org (mxout1-ec2-va.apache.org [3.227.148.255]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id C086B18063D for ; Thu, 19 Nov 2020 03:04:28 +0100 (CET) Received: from mail.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mxout1-ec2-va.apache.org (ASF Mail Server at mxout1-ec2-va.apache.org) with SMTP id 1182649B16 for ; Thu, 19 Nov 2020 02:04:28 +0000 (UTC) Received: (qmail 40423 invoked by uid 500); 19 Nov 2020 02:04:27 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 40414 invoked by uid 99); 19 Nov 2020 02:04:27 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Nov 2020 02:04:27 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 83DF08087B; Thu, 19 Nov 2020 02:04:27 +0000 (UTC) Date: Thu, 19 Nov 2020 02:04:27 +0000 To: "commits@accumulo.apache.org" Subject: [accumulo] branch main updated: Fix warning and simplify ScannerBaseTest MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <160575146735.2745.15233539848944097298@gitbox.apache.org> From: ctubbsii@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: accumulo X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Oldrev: 6f75eea4c0a823680aa0205e7d941fe2710a2692 X-Git-Newrev: 74afbabb06ba319cbb3968f30dcca58aa67fa070 X-Git-Rev: 74afbabb06ba319cbb3968f30dcca58aa67fa070 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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 map; - - MockScanner(Map 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> 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 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 e : map.entrySet()) { - assertEquals(entry.getKey(), e.getKey()); - assertEquals(entry.getValue(), e.getValue()); - } + Map 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 actual = new HashMap<>(); + scanner.forEach((k, v) -> actual.put(k, v)); + assertEquals(expected, actual); + + verify(scanner); } }