ACCUMULO-2994 Add explicit prefixes for iterator scopes and remove unnecessary configuration parsing.
When reading the Accumulo configuration, all configuration entries for all scopes were read. This is highly unnecessary as all that was done was to warn against invalid table properties. Instead, we can use the provided IteratorScope to explicitly pull out just the data that is needed from the configuration, to reduce this processing. Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/b2fbc06e Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/b2fbc06e Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/b2fbc06e Branch: refs/heads/1.6.1-SNAPSHOT Commit: b2fbc06e7bb3f3718ec0c85710fd28736490e9d3 Parents: 37af867 Author: Josh Elser <els...@apache.org> Authored: Tue Jul 15 14:44:53 2014 -0400 Committer: Josh Elser <els...@apache.org> Committed: Fri Jul 18 15:08:27 2014 -0400 ---------------------------------------------------------------------- .../org/apache/accumulo/core/conf/Property.java | 4 + .../accumulo/core/iterators/IteratorUtil.java | 84 ++--- .../accumulo/core/iterators/IterUtilTest.java | 279 ----------------- .../core/iterators/IteratorUtilTest.java | 306 +++++++++++++++++++ 4 files changed, 354 insertions(+), 319 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/b2fbc06e/core/src/main/java/org/apache/accumulo/core/conf/Property.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/conf/Property.java b/core/src/main/java/org/apache/accumulo/core/conf/Property.java index d8f9beb..7f48184 100644 --- a/core/src/main/java/org/apache/accumulo/core/conf/Property.java +++ b/core/src/main/java/org/apache/accumulo/core/conf/Property.java @@ -25,6 +25,7 @@ import java.util.Set; import org.apache.accumulo.core.client.security.tokens.PasswordToken; import org.apache.accumulo.core.file.rfile.RFile; +import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope; import org.apache.accumulo.core.util.format.DefaultFormatter; import org.apache.accumulo.core.util.interpret.DefaultScanInterpreter; import org.apache.accumulo.start.classloader.AccumuloClassLoader; @@ -332,6 +333,9 @@ public enum Property { + "These iterators can take options if additional properties are set that look like this property, " + "but are suffixed with a period, followed by 'opt' followed by another period, and a property name.<br />" + "For example, table.iterator.minc.vers.opt.maxVersions = 3"), + TABLE_ITERATOR_SCAN_PREFIX(TABLE_ITERATOR_PREFIX.getKey() + IteratorScope.scan.name() + ".", null, PropertyType.PREFIX, "Convenience prefix to find options for the scan iterator scope"), + TABLE_ITERATOR_MINC_PREFIX(TABLE_ITERATOR_PREFIX.getKey() + IteratorScope.minc.name() + ".", null, PropertyType.PREFIX, "Convenience prefix to find options for the minc iterator scope"), + TABLE_ITERATOR_MAJC_PREFIX(TABLE_ITERATOR_PREFIX.getKey() + IteratorScope.majc.name() + ".", null, PropertyType.PREFIX, "Convenience prefix to find options for the majc iterator scope"), TABLE_LOCALITY_GROUP_PREFIX("table.group.", null, PropertyType.PREFIX, "Properties in this category are per-table properties that define locality groups in a table. These properties start " + "with the category prefix, followed by a name, followed by a period, and followed by a property for that group.<br />" http://git-wip-us.apache.org/repos/asf/accumulo/blob/b2fbc06e/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java b/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java index 1d58c2f..997ccdf 100644 --- a/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/iterators/IteratorUtil.java @@ -47,12 +47,32 @@ import org.apache.thrift.TDeserializer; import org.apache.thrift.TException; import org.apache.thrift.TSerializer; import org.apache.thrift.protocol.TBinaryProtocol; + +import com.google.common.base.Preconditions; public class IteratorUtil { private static final Logger log = Logger.getLogger(IteratorUtil.class); public static enum IteratorScope { majc, minc, scan; + + /** + * Fetch the correct configuration key prefix for the given scope. Throws an + * IllegalArgumentException if no property exists for the given scope. + */ + public static Property getProperty(IteratorScope scope) { + Preconditions.checkNotNull(scope); + switch (scope) { + case scan: + return Property.TABLE_ITERATOR_SCAN_PREFIX; + case minc: + return Property.TABLE_ITERATOR_MINC_PREFIX; + case majc: + return Property.TABLE_ITERATOR_MAJC_PREFIX; + default: + throw new IllegalStateException("Could not find configuration property for IteratorScope"); + } + } } public static class IterInfoComparator implements Comparator<IterInfo>, Serializable { @@ -98,49 +118,33 @@ public class IteratorUtil { return max; } - private static void parseIterConf(IteratorScope scope, List<IterInfo> iters, Map<String,Map<String,String>> allOptions, AccumuloConfiguration conf) { - for (Entry<String,String> entry : conf) { - if (entry.getKey().startsWith(Property.TABLE_ITERATOR_PREFIX.getKey())) { - - String suffix = entry.getKey().substring(Property.TABLE_ITERATOR_PREFIX.getKey().length()); - String suffixSplit[] = suffix.split("\\.", 4); + protected static void parseIterConf(IteratorScope scope, List<IterInfo> iters, Map<String,Map<String,String>> allOptions, AccumuloConfiguration conf) { + final Property scopeProperty = IteratorScope.getProperty(scope); + final String scopePropertyKey = scopeProperty.getKey(); + + for (Entry<String,String> entry : conf.getAllPropertiesWithPrefix(scopeProperty).entrySet()) { + String suffix = entry.getKey().substring(scopePropertyKey.length()); + String suffixSplit[] = suffix.split("\\.", 3); + + if (suffixSplit.length == 1) { + String sa[] = entry.getValue().split(","); + int prio = Integer.parseInt(sa[0]); + String className = sa[1]; + iters.add(new IterInfo(prio, className, suffixSplit[0])); + } else if (suffixSplit.length == 3 && suffixSplit[1].equals("opt")) { + String iterName = suffixSplit[0]; + String optName = suffixSplit[2]; - if (!suffixSplit[0].equals(scope.name())) { - - // do a sanity check to see if this is a valid scope - boolean found = false; - IteratorScope[] scopes = IteratorScope.values(); - for (IteratorScope s : scopes) { - found = found || suffixSplit[0].equals(s.name()); - } - - if (!found) { - log.warn("Option contains unknown scope: " + entry.getKey()); - } - - continue; + Map<String,String> options = allOptions.get(iterName); + if (options == null) { + options = new HashMap<String,String>(); + allOptions.put(iterName, options); } - if (suffixSplit.length == 2) { - String sa[] = entry.getValue().split(","); - int prio = Integer.parseInt(sa[0]); - String className = sa[1]; - iters.add(new IterInfo(prio, className, suffixSplit[1])); - } else if (suffixSplit.length == 4 && suffixSplit[2].equals("opt")) { - String iterName = suffixSplit[1]; - String optName = suffixSplit[3]; - - Map<String,String> options = allOptions.get(iterName); - if (options == null) { - options = new HashMap<String,String>(); - allOptions.put(iterName, options); - } - - options.put(optName, entry.getValue()); - - } else { - log.warn("Unrecognizable option: " + entry.getKey()); - } + options.put(optName, entry.getValue()); + + } else { + log.warn("Unrecognizable option: " + entry.getKey()); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/b2fbc06e/core/src/test/java/org/apache/accumulo/core/iterators/IterUtilTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/IterUtilTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/IterUtilTest.java deleted file mode 100644 index e569ea4..0000000 --- a/core/src/test/java/org/apache/accumulo/core/iterators/IterUtilTest.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * 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.iterators; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; -import java.util.TreeMap; - -import org.apache.accumulo.core.conf.AccumuloConfiguration; -import org.apache.accumulo.core.conf.ConfigurationCopy; -import org.apache.accumulo.core.conf.Property; -import org.apache.accumulo.core.data.ByteSequence; -import org.apache.accumulo.core.data.Key; -import org.apache.accumulo.core.data.KeyExtent; -import org.apache.accumulo.core.data.Range; -import org.apache.accumulo.core.data.Value; -import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope; -import org.apache.accumulo.core.iterators.system.MultiIteratorTest; -import org.apache.accumulo.core.iterators.user.AgeOffFilter; -import org.apache.hadoop.io.Text; -import org.junit.Test; - -public class IterUtilTest { - - private static final Collection<ByteSequence> EMPTY_COL_FAMS = new ArrayList<ByteSequence>(); - - static class WrappedIter implements SortedKeyValueIterator<Key,Value> { - - protected SortedKeyValueIterator<Key,Value> source; - - public WrappedIter deepCopy(IteratorEnvironment env) { - throw new UnsupportedOperationException(); - } - - public Key getTopKey() { - return source.getTopKey(); - } - - public Value getTopValue() { - return source.getTopValue(); - } - - public boolean hasTop() { - return source.hasTop(); - } - - public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { - this.source = source; - } - - public void next() throws IOException { - source.next(); - } - - @Override - public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException { - source.seek(range, columnFamilies, inclusive); - } - } - - static class AddingIter extends WrappedIter { - - int amount = 1; - - public Value getTopValue() { - Value val = super.getTopValue(); - - int orig = Integer.parseInt(val.toString()); - - return new Value(((orig + amount) + "").getBytes()); - } - - public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { - super.init(source, options, env); - - String amount = options.get("amount"); - - if (amount != null) { - this.amount = Integer.parseInt(amount); - } - } - } - - static class SquaringIter extends WrappedIter { - public Value getTopValue() { - Value val = super.getTopValue(); - - int orig = Integer.parseInt(val.toString()); - - return new Value(((orig * orig) + "").getBytes()); - } - } - - @Test - public void test1() throws IOException { - ConfigurationCopy conf = new ConfigurationCopy(); - - // create an iterator that adds 1 and then squares - conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".addIter", "1," + AddingIter.class.getName()); - conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".sqIter", "2," + SquaringIter.class.getName()); - - TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); - - MultiIteratorTest.nkv(tm, 1, 0, false, "1"); - MultiIteratorTest.nkv(tm, 2, 0, false, "2"); - - SortedMapIterator source = new SortedMapIterator(tm); - - SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Text("tab"), null, null), conf, - new DefaultIteratorEnvironment(conf)); - iter.seek(new Range(), EMPTY_COL_FAMS, false); - - assertTrue(iter.hasTop()); - assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(1, 0))); - assertTrue(iter.getTopValue().toString().equals("4")); - - iter.next(); - - assertTrue(iter.hasTop()); - assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(2, 0))); - assertTrue(iter.getTopValue().toString().equals("9")); - - iter.next(); - - assertFalse(iter.hasTop()); - } - - @Test - public void test4() throws IOException { - - // try loading for a different scope - AccumuloConfiguration conf = new ConfigurationCopy(); - - TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); - - MultiIteratorTest.nkv(tm, 1, 0, false, "1"); - MultiIteratorTest.nkv(tm, 2, 0, false, "2"); - - SortedMapIterator source = new SortedMapIterator(tm); - - SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.majc, source, new KeyExtent(new Text("tab"), null, null), conf, - new DefaultIteratorEnvironment(conf)); - iter.seek(new Range(), EMPTY_COL_FAMS, false); - - assertTrue(iter.hasTop()); - assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(1, 0))); - assertTrue(iter.getTopValue().toString().equals("1")); - - iter.next(); - - assertTrue(iter.hasTop()); - assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(2, 0))); - assertTrue(iter.getTopValue().toString().equals("2")); - - iter.next(); - - assertFalse(iter.hasTop()); - - } - - @Test - public void test3() throws IOException { - // change the load order, so it squares and then adds - - ConfigurationCopy conf = new ConfigurationCopy(); - - TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); - - MultiIteratorTest.nkv(tm, 1, 0, false, "1"); - MultiIteratorTest.nkv(tm, 2, 0, false, "2"); - - SortedMapIterator source = new SortedMapIterator(tm); - - conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".addIter", "2," + AddingIter.class.getName()); - conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".sqIter", "1," + SquaringIter.class.getName()); - - SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Text("tab"), null, null), conf, - new DefaultIteratorEnvironment(conf)); - iter.seek(new Range(), EMPTY_COL_FAMS, false); - - assertTrue(iter.hasTop()); - assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(1, 0))); - assertTrue(iter.getTopValue().toString().equals("2")); - - iter.next(); - - assertTrue(iter.hasTop()); - assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(2, 0))); - assertTrue(iter.getTopValue().toString().equals("5")); - - iter.next(); - - assertFalse(iter.hasTop()); - } - - @Test - public void test2() throws IOException { - - ConfigurationCopy conf = new ConfigurationCopy(); - - // create an iterator that adds 1 and then squares - conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".addIter", "1," + AddingIter.class.getName()); - conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".addIter.opt.amount", "7"); - conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".sqIter", "2," + SquaringIter.class.getName()); - - TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); - - MultiIteratorTest.nkv(tm, 1, 0, false, "1"); - MultiIteratorTest.nkv(tm, 2, 0, false, "2"); - - SortedMapIterator source = new SortedMapIterator(tm); - - SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Text("tab"), null, null), conf, - new DefaultIteratorEnvironment(conf)); - iter.seek(new Range(), EMPTY_COL_FAMS, false); - - assertTrue(iter.hasTop()); - assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(1, 0))); - assertTrue(iter.getTopValue().toString().equals("64")); - - iter.next(); - - assertTrue(iter.hasTop()); - assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(2, 0))); - assertTrue(iter.getTopValue().toString().equals("81")); - - iter.next(); - - assertFalse(iter.hasTop()); - - } - - @Test - public void test5() throws IOException { - ConfigurationCopy conf = new ConfigurationCopy(); - - // create an iterator that ages off - conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".filter", "1," + AgeOffFilter.class.getName()); - conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".filter.opt.ttl", "100"); - conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".filter.opt.currentTime", "1000"); - - TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); - - MultiIteratorTest.nkv(tm, 1, 850, false, "1"); - MultiIteratorTest.nkv(tm, 2, 950, false, "2"); - - SortedMapIterator source = new SortedMapIterator(tm); - - SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Text("tab"), null, null), conf, - new DefaultIteratorEnvironment(conf)); - iter.seek(new Range(), EMPTY_COL_FAMS, false); - - assertTrue(iter.hasTop()); - assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(2, 950))); - iter.next(); - - assertFalse(iter.hasTop()); - - } -} http://git-wip-us.apache.org/repos/asf/accumulo/blob/b2fbc06e/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java new file mode 100644 index 0000000..4d843d3 --- /dev/null +++ b/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java @@ -0,0 +1,306 @@ +/* + * 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.iterators; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.accumulo.core.conf.AccumuloConfiguration; +import org.apache.accumulo.core.conf.ConfigurationCopy; +import org.apache.accumulo.core.conf.Property; +import org.apache.accumulo.core.data.ByteSequence; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.KeyExtent; +import org.apache.accumulo.core.data.Range; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.data.thrift.IterInfo; +import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope; +import org.apache.accumulo.core.iterators.system.MultiIteratorTest; +import org.apache.accumulo.core.iterators.user.AgeOffFilter; +import org.apache.accumulo.core.iterators.user.SummingCombiner; +import org.apache.hadoop.io.Text; +import org.junit.Assert; +import org.junit.Test; + +public class IteratorUtilTest { + + private static final Collection<ByteSequence> EMPTY_COL_FAMS = new ArrayList<ByteSequence>(); + + static class WrappedIter implements SortedKeyValueIterator<Key,Value> { + + protected SortedKeyValueIterator<Key,Value> source; + + public WrappedIter deepCopy(IteratorEnvironment env) { + throw new UnsupportedOperationException(); + } + + public Key getTopKey() { + return source.getTopKey(); + } + + public Value getTopValue() { + return source.getTopValue(); + } + + public boolean hasTop() { + return source.hasTop(); + } + + public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { + this.source = source; + } + + public void next() throws IOException { + source.next(); + } + + @Override + public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean inclusive) throws IOException { + source.seek(range, columnFamilies, inclusive); + } + } + + static class AddingIter extends WrappedIter { + + int amount = 1; + + public Value getTopValue() { + Value val = super.getTopValue(); + + int orig = Integer.parseInt(val.toString()); + + return new Value(((orig + amount) + "").getBytes()); + } + + public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { + super.init(source, options, env); + + String amount = options.get("amount"); + + if (amount != null) { + this.amount = Integer.parseInt(amount); + } + } + } + + static class SquaringIter extends WrappedIter { + public Value getTopValue() { + Value val = super.getTopValue(); + + int orig = Integer.parseInt(val.toString()); + + return new Value(((orig * orig) + "").getBytes()); + } + } + + @Test + public void test1() throws IOException { + ConfigurationCopy conf = new ConfigurationCopy(); + + // create an iterator that adds 1 and then squares + conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".addIter", "1," + AddingIter.class.getName()); + conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".sqIter", "2," + SquaringIter.class.getName()); + + TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); + + MultiIteratorTest.nkv(tm, 1, 0, false, "1"); + MultiIteratorTest.nkv(tm, 2, 0, false, "2"); + + SortedMapIterator source = new SortedMapIterator(tm); + + SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Text("tab"), null, null), conf, + new DefaultIteratorEnvironment(conf)); + iter.seek(new Range(), EMPTY_COL_FAMS, false); + + assertTrue(iter.hasTop()); + assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(1, 0))); + assertTrue(iter.getTopValue().toString().equals("4")); + + iter.next(); + + assertTrue(iter.hasTop()); + assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(2, 0))); + assertTrue(iter.getTopValue().toString().equals("9")); + + iter.next(); + + assertFalse(iter.hasTop()); + } + + @Test + public void test4() throws IOException { + + // try loading for a different scope + AccumuloConfiguration conf = new ConfigurationCopy(); + + TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); + + MultiIteratorTest.nkv(tm, 1, 0, false, "1"); + MultiIteratorTest.nkv(tm, 2, 0, false, "2"); + + SortedMapIterator source = new SortedMapIterator(tm); + + SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.majc, source, new KeyExtent(new Text("tab"), null, null), conf, + new DefaultIteratorEnvironment(conf)); + iter.seek(new Range(), EMPTY_COL_FAMS, false); + + assertTrue(iter.hasTop()); + assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(1, 0))); + assertTrue(iter.getTopValue().toString().equals("1")); + + iter.next(); + + assertTrue(iter.hasTop()); + assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(2, 0))); + assertTrue(iter.getTopValue().toString().equals("2")); + + iter.next(); + + assertFalse(iter.hasTop()); + + } + + @Test + public void test3() throws IOException { + // change the load order, so it squares and then adds + + ConfigurationCopy conf = new ConfigurationCopy(); + + TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); + + MultiIteratorTest.nkv(tm, 1, 0, false, "1"); + MultiIteratorTest.nkv(tm, 2, 0, false, "2"); + + SortedMapIterator source = new SortedMapIterator(tm); + + conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".addIter", "2," + AddingIter.class.getName()); + conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".sqIter", "1," + SquaringIter.class.getName()); + + SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Text("tab"), null, null), conf, + new DefaultIteratorEnvironment(conf)); + iter.seek(new Range(), EMPTY_COL_FAMS, false); + + assertTrue(iter.hasTop()); + assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(1, 0))); + assertTrue(iter.getTopValue().toString().equals("2")); + + iter.next(); + + assertTrue(iter.hasTop()); + assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(2, 0))); + assertTrue(iter.getTopValue().toString().equals("5")); + + iter.next(); + + assertFalse(iter.hasTop()); + } + + @Test + public void test2() throws IOException { + + ConfigurationCopy conf = new ConfigurationCopy(); + + // create an iterator that adds 1 and then squares + conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".addIter", "1," + AddingIter.class.getName()); + conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".addIter.opt.amount", "7"); + conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".sqIter", "2," + SquaringIter.class.getName()); + + TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); + + MultiIteratorTest.nkv(tm, 1, 0, false, "1"); + MultiIteratorTest.nkv(tm, 2, 0, false, "2"); + + SortedMapIterator source = new SortedMapIterator(tm); + + SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Text("tab"), null, null), conf, + new DefaultIteratorEnvironment(conf)); + iter.seek(new Range(), EMPTY_COL_FAMS, false); + + assertTrue(iter.hasTop()); + assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(1, 0))); + assertTrue(iter.getTopValue().toString().equals("64")); + + iter.next(); + + assertTrue(iter.hasTop()); + assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(2, 0))); + assertTrue(iter.getTopValue().toString().equals("81")); + + iter.next(); + + assertFalse(iter.hasTop()); + + } + + @Test + public void test5() throws IOException { + ConfigurationCopy conf = new ConfigurationCopy(); + + // create an iterator that ages off + conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".filter", "1," + AgeOffFilter.class.getName()); + conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".filter.opt.ttl", "100"); + conf.set(Property.TABLE_ITERATOR_PREFIX + IteratorScope.minc.name() + ".filter.opt.currentTime", "1000"); + + TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); + + MultiIteratorTest.nkv(tm, 1, 850, false, "1"); + MultiIteratorTest.nkv(tm, 2, 950, false, "2"); + + SortedMapIterator source = new SortedMapIterator(tm); + + SortedKeyValueIterator<Key,Value> iter = IteratorUtil.loadIterators(IteratorScope.minc, source, new KeyExtent(new Text("tab"), null, null), conf, + new DefaultIteratorEnvironment(conf)); + iter.seek(new Range(), EMPTY_COL_FAMS, false); + + assertTrue(iter.hasTop()); + assertTrue(iter.getTopKey().equals(MultiIteratorTest.nk(2, 950))); + iter.next(); + + assertFalse(iter.hasTop()); + + } + + @Test + public void onlyReadsRelevantIteratorScopeConfigurations() throws Exception { + Map<String,String> data = new HashMap<String,String>(); + + // Make some configuration items, one with a bogus scope + data.put(Property.TABLE_ITERATOR_SCAN_PREFIX + "foo", "50," + SummingCombiner.class.getName()); + data.put(Property.TABLE_ITERATOR_SCAN_PREFIX + "foo.opt." + SummingCombiner.ALL_OPTION, "true"); + data.put(Property.TABLE_ITERATOR_PREFIX + ".fakescope.bar", "50," + SummingCombiner.class.getName()); + data.put(Property.TABLE_ITERATOR_SCAN_PREFIX + "foo.opt.fakeopt", "fakevalue"); + + AccumuloConfiguration conf = new ConfigurationCopy(data); + + List<IterInfo> iterators = new ArrayList<IterInfo>(); + Map<String,Map<String,String>> options = new HashMap<String,Map<String,String>>(); + + IteratorUtil.parseIterConf(IteratorScope.scan, iterators, options, conf); + + Assert.assertEquals(1, iterators.size()); + IterInfo ii = iterators.get(0); + Assert.assertEquals(new IterInfo(50, SummingCombiner.class.getName(), "foo"), ii); + } +}