ACCUMULO-4634 : Appropriately implement the mocked out methods of MockIteratorEnvironment per the interface specifications.
Closes #258 Signed-off-by: Josh Elser <els...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/54c82dc9 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/54c82dc9 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/54c82dc9 Branch: refs/heads/master Commit: 54c82dc90b028d829d0dd8fce7b7deaef7becee8 Parents: c093b56 Author: Ivan Bella <i...@bella.name> Authored: Mon May 15 12:43:26 2017 -0400 Committer: Josh Elser <els...@apache.org> Committed: Mon May 15 16:53:57 2017 -0400 ---------------------------------------------------------------------- .../core/client/mock/MockScannerBase.java | 7 +- .../core/client/mock/MockScannerTest.java | 103 +++++++++++++++++++ 2 files changed, 107 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/54c82dc9/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java b/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java index ad79ec0..7c8f5cc 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java +++ b/core/src/main/java/org/apache/accumulo/core/client/mock/MockScannerBase.java @@ -23,6 +23,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Map.Entry; +import org.apache.accumulo.core.client.SampleNotPresentException; import org.apache.accumulo.core.client.impl.ScannerOptions; import org.apache.accumulo.core.client.sample.SamplerConfiguration; import org.apache.accumulo.core.conf.AccumuloConfiguration; @@ -115,17 +116,17 @@ public class MockScannerBase extends ScannerOptions { @Override public boolean isSamplingEnabled() { - throw new UnsupportedOperationException(); + return false; } @Override public SamplerConfiguration getSamplerConfiguration() { - throw new UnsupportedOperationException(); + return null; } @Override public IteratorEnvironment cloneWithSamplingEnabled() { - throw new UnsupportedOperationException(); + throw new SampleNotPresentException(); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/54c82dc9/core/src/test/java/org/apache/accumulo/core/client/mock/MockScannerTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/client/mock/MockScannerTest.java b/core/src/test/java/org/apache/accumulo/core/client/mock/MockScannerTest.java new file mode 100644 index 0000000..be77a2d --- /dev/null +++ b/core/src/test/java/org/apache/accumulo/core/client/mock/MockScannerTest.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.core.client.mock; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.accumulo.core.client.BatchScanner; +import org.apache.accumulo.core.client.BatchWriter; +import org.apache.accumulo.core.client.BatchWriterConfig; +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.core.client.IteratorSetting; +import org.apache.accumulo.core.client.SampleNotPresentException; +import org.apache.accumulo.core.client.security.tokens.PasswordToken; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Mutation; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.iterators.IteratorEnvironment; +import org.apache.accumulo.core.iterators.SortedKeyValueIterator; +import org.apache.accumulo.core.iterators.WrappingIterator; +import org.apache.accumulo.core.security.Authorizations; +import org.junit.Test; + +@Deprecated +public class MockScannerTest { + + public static final String ROOT = "root"; + public static final String TEST = "test"; + public static final String SEP = ","; + public static final String A_B_C_D = 'A' + SEP + 'B' + SEP + 'C' + SEP + 'D'; + public static final String CF = "cf"; + public static final String CQ = "cq"; + + public static class DeepCopyIterator extends WrappingIterator { + + @Override + public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { + super.init(source.deepCopy(env), options, env); + } + } + + @Test + public void testDeepCopy() throws Exception { + MockInstance inst = new MockInstance(); + Connector conn = inst.getConnector(ROOT, new PasswordToken("")); + conn.tableOperations().create(TEST); + BatchWriter bw = conn.createBatchWriter(TEST, new BatchWriterConfig()); + for (String row : A_B_C_D.split(SEP)) { + Mutation m = new Mutation(row); + m.put(CF, CQ, ""); + bw.addMutation(m); + } + bw.flush(); + BatchScanner bs = conn.createBatchScanner(TEST, Authorizations.EMPTY, 1); + IteratorSetting cfg = new IteratorSetting(100, DeepCopyIterator.class); + bs.addScanIterator(cfg); + bs.setRanges(Collections.singletonList(new Range("A", "Z"))); + StringBuilder sb = new StringBuilder(); + String comma = ""; + for (Entry<Key,Value> entry : bs) { + sb.append(comma); + sb.append(entry.getKey().getRow()); + comma = SEP; + } + assertEquals(A_B_C_D, sb.toString()); + } + + @Test + public void testEnvironment() throws Exception { + MockScannerBase.MockIteratorEnvironment env = new MockScannerBase.MockIteratorEnvironment(Authorizations.EMPTY); + assertFalse(env.isSamplingEnabled()); + assertNull(env.getSamplerConfiguration()); + try { + env.cloneWithSamplingEnabled(); + fail("cloneWithSamplingEnabled should have thrown SampleNotPresentException"); + } catch (SampleNotPresentException se) { + // expected + } + } + +}