Return-Path: X-Original-To: apmail-incubator-accumulo-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-accumulo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5C4D99833 for ; Thu, 19 Jan 2012 19:33:33 +0000 (UTC) Received: (qmail 88794 invoked by uid 500); 19 Jan 2012 19:33:33 -0000 Delivered-To: apmail-incubator-accumulo-commits-archive@incubator.apache.org Received: (qmail 88756 invoked by uid 500); 19 Jan 2012 19:33:33 -0000 Mailing-List: contact accumulo-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: accumulo-dev@incubator.apache.org Delivered-To: mailing list accumulo-commits@incubator.apache.org Received: (qmail 88749 invoked by uid 99); 19 Jan 2012 19:33:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jan 2012 19:33:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 19 Jan 2012 19:33:30 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 72828238899C; Thu, 19 Jan 2012 19:33:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1233547 - in /incubator/accumulo/branches/1.4/src/core/src: main/java/org/apache/accumulo/core/iterators/ main/java/org/apache/accumulo/core/iterators/user/ test/java/org/apache/accumulo/core/iterators/user/ Date: Thu, 19 Jan 2012 19:33:09 -0000 To: accumulo-commits@incubator.apache.org From: billie@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120119193310.72828238899C@eris.apache.org> Author: billie Date: Thu Jan 19 19:33:09 2012 New Revision: 1233547 URL: http://svn.apache.org/viewvc?rev=1233547&view=rev Log: ACCUMULO-307 reworked deepCopy for Combiners and Filters in 1.4 Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/Combiner.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/TypedValueCombiner.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/VersioningIterator.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/AgeOffFilter.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnAgeOffFilter.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/RegExFilter.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/VersioningIterator.java incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/VersioningIteratorTest.java Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/Combiner.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/Combiner.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/Combiner.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/Combiner.java Thu Jan 19 19:33:09 2012 @@ -228,6 +228,20 @@ public abstract class Combiner extends W } @Override + public SortedKeyValueIterator deepCopy(IteratorEnvironment env) { + Combiner newInstance; + try { + newInstance = this.getClass().newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + newInstance.setSource(getSource().deepCopy(env)); + newInstance.combiners = combiners; + newInstance.combineAllColumns = combineAllColumns; + return newInstance; + } + + @Override public IteratorOptions describeOptions() { IteratorOptions io = new IteratorOptions("comb", "Combiners apply reduce functions to values with identical keys", null, null); io.addNamedOption(ALL_OPTION, "set to true to apply Combiner to every column, otherwise leave blank. if true, " + COLUMNS_OPTION Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/TypedValueCombiner.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/TypedValueCombiner.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/TypedValueCombiner.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/TypedValueCombiner.java Thu Jan 19 19:33:09 2012 @@ -145,6 +145,14 @@ public abstract class TypedValueCombiner } } + @SuppressWarnings("unchecked") + @Override + public SortedKeyValueIterator deepCopy(IteratorEnvironment env) { + TypedValueCombiner newInstance = (TypedValueCombiner) super.deepCopy(env); + newInstance.setEncoder(encoder); + return newInstance; + } + @Override public Value reduce(Key key, Iterator iter) { return new Value(encoder.encode(typedReduce(key, new VIterator(iter, encoder)))); Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/VersioningIterator.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/VersioningIterator.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/VersioningIterator.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/VersioningIterator.java Thu Jan 19 19:33:09 2012 @@ -29,6 +29,8 @@ public class VersioningIterator extends public VersioningIterator() {} public VersioningIterator(SortedKeyValueIterator iterator, int maxVersions) { - super(iterator, maxVersions); + super(); + this.setSource(iterator); + this.maxVersions = maxVersions; } } Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/AgeOffFilter.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/AgeOffFilter.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/AgeOffFilter.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/AgeOffFilter.java Thu Jan 19 19:33:09 2012 @@ -37,26 +37,6 @@ public class AgeOffFilter extends Filter private long threshold; private long currentTime; - public AgeOffFilter() {} - - /** - * Constructs a filter that omits entries read from a source iterator if the Key's timestamp is less than currentTime - threshold. - * - * @param iterator - * The source iterator. - * - * @param threshold - * Maximum age in milliseconds of data to keep. - * - * @param threshold - * Current time in milliseconds. - */ - private AgeOffFilter(SortedKeyValueIterator iterator, long threshold, long currentTime) { - setSource(iterator); - this.threshold = threshold; - this.currentTime = currentTime; - } - /** * Accepts entries whose timestamps are less than currentTime - threshold. * @@ -93,7 +73,10 @@ public class AgeOffFilter extends Filter @Override public SortedKeyValueIterator deepCopy(IteratorEnvironment env) { - return new AgeOffFilter(getSource(), threshold, currentTime); + AgeOffFilter copy = (AgeOffFilter) super.deepCopy(env); + copy.currentTime = currentTime; + copy.threshold = threshold; + return copy; } @Override Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnAgeOffFilter.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnAgeOffFilter.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnAgeOffFilter.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/ColumnAgeOffFilter.java Thu Jan 19 19:33:09 2012 @@ -36,15 +36,6 @@ import org.apache.hadoop.io.Text; * Different thresholds are set for each column. */ public class ColumnAgeOffFilter extends Filter { - - public ColumnAgeOffFilter() {} - - private ColumnAgeOffFilter(SortedKeyValueIterator iterator, TTLSet ttls, long currentTime) { - setSource(iterator); - this.ttls = ttls; - this.currentTime = currentTime; - } - public static class TTLSet extends ColumnToClassMapping { public TTLSet(Map objectStrings) { super(); @@ -87,7 +78,10 @@ public class ColumnAgeOffFilter extends @Override public SortedKeyValueIterator deepCopy(IteratorEnvironment env) { - return new ColumnAgeOffFilter(getSource(), ttls, currentTime); + ColumnAgeOffFilter copy = (ColumnAgeOffFilter) super.deepCopy(env); + copy.currentTime = currentTime; + copy.ttls = ttls; + return copy; } public void overrideCurrentTime(long ts) { @@ -123,7 +117,7 @@ public class ColumnAgeOffFilter extends public static void addTTL(IteratorSetting is, IteratorSetting.Column column, Long ttl) { is.addOption(ColumnSet.encodeColumns(column.getFirst(), column.getSecond()), Long.toString(ttl)); } - + /** * A convenience method for removing an age off threshold for a column. * Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/RegExFilter.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/RegExFilter.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/RegExFilter.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/RegExFilter.java Thu Jan 19 19:33:09 2012 @@ -37,8 +37,7 @@ public class RegExFilter extends Filter @Override public SortedKeyValueIterator deepCopy(IteratorEnvironment env) { - RegExFilter result = new RegExFilter(); - result.setSource(getSource().deepCopy(env)); + RegExFilter result = (RegExFilter) super.deepCopy(env); result.rowMatcher = copyMatcher(rowMatcher); result.colfMatcher = copyMatcher(colfMatcher); result.colqMatcher = copyMatcher(colqMatcher); Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/TimestampFilter.java Thu Jan 19 19:33:09 2012 @@ -54,17 +54,6 @@ public class TimestampFilter extends Fil public TimestampFilter() {} - private TimestampFilter(SortedKeyValueIterator iterator, boolean hasStart, long start, boolean startInclusive, boolean hasEnd, long end, - boolean endInclusive) { - setSource(iterator); - this.start = start; - this.startInclusive = startInclusive; - this.hasStart = true; - this.end = end; - this.endInclusive = endInclusive; - this.hasEnd = true; - } - @Override public boolean accept(Key k, Value v) { long ts = k.getTimestamp(); @@ -112,7 +101,14 @@ public class TimestampFilter extends Fil @Override public SortedKeyValueIterator deepCopy(IteratorEnvironment env) { - return new TimestampFilter(getSource(), hasStart, start, startInclusive, hasEnd, end, endInclusive); + TimestampFilter copy = (TimestampFilter) super.deepCopy(env); + copy.hasStart = hasStart; + copy.start = start; + copy.startInclusive = startInclusive; + copy.hasEnd = hasEnd; + copy.end = end; + copy.endInclusive = endInclusive; + return copy; } @Override Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/VersioningIterator.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/VersioningIterator.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/VersioningIterator.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/iterators/user/VersioningIterator.java Thu Jan 19 19:33:09 2012 @@ -37,25 +37,14 @@ public class VersioningIterator extends private Key currentKey = new Key(); private int numVersions; - private int maxVersions; + protected int maxVersions; @Override public VersioningIterator deepCopy(IteratorEnvironment env) { - return new VersioningIterator(this, env); - } - - private VersioningIterator(VersioningIterator other, IteratorEnvironment env) { - setSource(other.getSource().deepCopy(env)); - maxVersions = other.maxVersions; - } - - public VersioningIterator() {} - - public VersioningIterator(SortedKeyValueIterator iterator, int maxVersions) { - if (maxVersions < 1) - throw new IllegalArgumentException("maxVersions for versioning iterator must be >= 1"); - this.setSource(iterator); - this.maxVersions = maxVersions; + VersioningIterator copy = new VersioningIterator(); + copy.setSource(getSource().deepCopy(env)); + copy.maxVersions = maxVersions; + return copy; } @Override Modified: incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java Thu Jan 19 19:33:09 2012 @@ -279,6 +279,74 @@ public class CombinerTest { } @Test + public void testDeepCopy() throws IOException { + Encoder encoder = LongCombiner.FIXED_LEN_ENCODER; + + TreeMap tm1 = new TreeMap(); + + // keys that aggregate + nkv(tm1, 1, 1, 1, 1, false, 2l, encoder); + nkv(tm1, 1, 1, 1, 2, false, 3l, encoder); + nkv(tm1, 1, 1, 1, 3, false, 4l, encoder); + + // keys that do not aggregate + nkv(tm1, 2, 2, 1, 1, false, 2l, encoder); + nkv(tm1, 2, 2, 1, 2, false, 3l, encoder); + + Combiner ai = new SummingCombiner(); + + IteratorSetting is = new IteratorSetting(1, SummingCombiner.class); + LongCombiner.setEncodingType(is, FixedLenEncoder.class.getName()); + Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("cf001"))); + + ai.init(new SortedMapIterator(tm1), is.getProperties(), null); + + SortedKeyValueIterator ai2 = ai.deepCopy(null); + SortedKeyValueIterator ai3 = ai.deepCopy(null); + ai.seek(new Range(), EMPTY_COL_FAMS, false); + + assertTrue(ai.hasTop()); + assertEquals(nk(1, 1, 1, 3), ai.getTopKey()); + assertEquals("9", encoder.decode(ai.getTopValue().get()).toString()); + + ai.next(); + + assertTrue(ai.hasTop()); + assertEquals(nk(2, 2, 1, 2), ai.getTopKey()); + assertEquals("3", encoder.decode(ai.getTopValue().get()).toString()); + + ai.next(); + + assertTrue(ai.hasTop()); + assertEquals(nk(2, 2, 1, 1), ai.getTopKey()); + assertEquals("2", encoder.decode(ai.getTopValue().get()).toString()); + + ai.next(); + + assertFalse(ai.hasTop()); + + // seek after key that aggregates + ai2.seek(nr(1, 1, 1, 2), EMPTY_COL_FAMS, false); + + assertTrue(ai2.hasTop()); + assertEquals(nk(2, 2, 1, 2), ai2.getTopKey()); + assertEquals("3", encoder.decode(ai2.getTopValue().get()).toString()); + + // seek before key that aggregates + ai3.seek(nr(1, 1, 1, 4), EMPTY_COL_FAMS, false); + + assertTrue(ai3.hasTop()); + assertEquals(nk(1, 1, 1, 3), ai3.getTopKey()); + assertEquals("9", encoder.decode(ai3.getTopValue().get()).toString()); + + ai3.next(); + + assertTrue(ai3.hasTop()); + assertEquals(nk(2, 2, 1, 2), ai3.getTopKey()); + assertEquals("3", encoder.decode(ai3.getTopValue().get()).toString()); + } + + @Test public void test4() throws IOException { Encoder encoder = LongCombiner.STRING_ENCODER; Modified: incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/FilterTest.java Thu Jan 19 19:33:09 2012 @@ -16,6 +16,9 @@ */ package org.apache.accumulo.core.iterators.user; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -26,8 +29,6 @@ import java.util.HashSet; import java.util.Map; import java.util.TreeMap; -import junit.framework.TestCase; - import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.data.ByteSequence; import org.apache.accumulo.core.data.Column; @@ -43,13 +44,14 @@ import org.apache.accumulo.core.iterator import org.apache.accumulo.core.security.Authorizations; import org.apache.accumulo.core.security.ColumnVisibility; import org.apache.hadoop.io.Text; +import org.junit.Test; -public class FilterTest extends TestCase { +public class FilterTest { private static final Collection EMPTY_COL_FAMS = new ArrayList(); private static final Map EMPTY_OPTS = new HashMap(); - public class SimpleFilter extends Filter { + public static class SimpleFilter extends Filter { public boolean accept(Key k, Value v) { // System.out.println(k.getRow()); if (k.getRow().toString().endsWith("0")) @@ -58,7 +60,7 @@ public class FilterTest extends TestCase } } - public class SimpleFilter2 extends Filter { + public static class SimpleFilter2 extends Filter { public boolean accept(Key k, Value v) { if (k.getColumnFamily().toString().equals("a")) return false; @@ -76,6 +78,7 @@ public class FilterTest extends TestCase return size; } + @Test public void test1() throws IOException { Text colf = new Text("a"); Text colq = new Text("b"); @@ -110,6 +113,7 @@ public class FilterTest extends TestCase assertTrue("size = " + size, size == 0); } + @Test public void test1neg() throws IOException { Text colf = new Text("a"); Text colq = new Text("b"); @@ -122,32 +126,59 @@ public class FilterTest extends TestCase } assertTrue(tm.size() == 1000); - Filter filter1 = new SimpleFilter(); + Filter filter = new SimpleFilter(); IteratorSetting is = new IteratorSetting(1, SimpleFilter.class); Filter.setNegate(is, true); - filter1.init(new SortedMapIterator(tm), is.getProperties(), null); - filter1.seek(new Range(), EMPTY_COL_FAMS, false); - int size = size(filter1); + filter.init(new SortedMapIterator(tm), is.getProperties(), null); + filter.seek(new Range(), EMPTY_COL_FAMS, false); + int size = size(filter); assertTrue("size = " + size, size == 900); - Filter fi = new SimpleFilter(); - fi.init(new SortedMapIterator(tm), is.getProperties(), null); + filter.init(new SortedMapIterator(tm), is.getProperties(), null); Key k = new Key(new Text("500")); - fi.seek(new Range(k, null), EMPTY_COL_FAMS, false); - size = size(fi); + filter.seek(new Range(k, null), EMPTY_COL_FAMS, false); + size = size(filter); assertTrue("size = " + size, size == 450); - filter1 = new SimpleFilter(); - filter1.init(new SortedMapIterator(tm), EMPTY_OPTS, null); + filter.init(new SortedMapIterator(tm), EMPTY_OPTS, null); Filter filter2 = new SimpleFilter2(); - filter2.init(filter1, is.getProperties(), null); + filter2.init(filter, is.getProperties(), null); filter2.seek(new Range(), EMPTY_COL_FAMS, false); size = size(filter2); assertTrue("size = " + size, size == 100); } + @Test + public void testDeepCopy() throws IOException { + Text colf = new Text("a"); + Text colq = new Text("b"); + Value dv = new Value(); + TreeMap tm = new TreeMap(); + + for (int i = 0; i < 1000; i++) { + Key k = new Key(new Text(String.format("%03d", i)), colf, colq); + tm.put(k, dv); + } + assertTrue(tm.size() == 1000); + + SimpleFilter filter = new SimpleFilter(); + + IteratorSetting is = new IteratorSetting(1, SimpleFilter.class); + Filter.setNegate(is, true); + + filter.init(new SortedMapIterator(tm), is.getProperties(), null); + SortedKeyValueIterator copy = filter.deepCopy(null); + filter.seek(new Range(), EMPTY_COL_FAMS, false); + int size = size(filter); + assertTrue("size = " + size, size == 900); + copy.seek(new Range(), EMPTY_COL_FAMS, false); + size = size(copy); + assertTrue("size = " + size, size == 900); + } + + @Test public void test2() throws IOException { Text colf = new Text("a"); Text colq = new Text("b"); @@ -161,15 +192,21 @@ public class FilterTest extends TestCase } assertTrue(tm.size() == 1000); - AgeOffFilter a = new AgeOffFilter(); + SortedKeyValueIterator a = new AgeOffFilter(); IteratorSetting is = new IteratorSetting(1, AgeOffFilter.class); AgeOffFilter.setTTL(is, 101l); AgeOffFilter.setCurrentTime(is, 1001l); + AgeOffFilter.setNegate(is, true); a.init(new SortedMapIterator(tm), is.getProperties(), null); + a = a.deepCopy(null); + SortedKeyValueIterator copy = a.deepCopy(null); a.seek(new Range(), EMPTY_COL_FAMS, false); - assertEquals(size(a), 100); + assertEquals(size(a), 900); + copy.seek(new Range(), EMPTY_COL_FAMS, false); + assertEquals(size(copy), 900); } + @Test public void test2a() throws IOException { Text colf = new Text("a"); Text colq = new Text("b"); @@ -199,11 +236,13 @@ public class FilterTest extends TestCase ColumnAgeOffFilter.removeTTL(is, new IteratorSetting.Column("a", "b")); a.init(new SortedMapIterator(tm), is.getProperties(), new DefaultIteratorEnvironment()); + a = (ColumnAgeOffFilter) a.deepCopy(null); a.overrideCurrentTime(ts); a.seek(new Range(), EMPTY_COL_FAMS, false); assertEquals(size(a), 902); } + @Test public void test3() throws IOException { Value dv = new Value(); TreeMap tm = new TreeMap(); @@ -248,6 +287,7 @@ public class FilterTest extends TestCase assertTrue("size was " + size, size == 1000); } + @Test public void test4() throws IOException { Value dv = new Value(); TreeMap tm = new TreeMap(); @@ -283,6 +323,7 @@ public class FilterTest extends TestCase return a; } + @Test public void test5() throws IOException { Value dv = new Value(); TreeMap tm = new TreeMap(); @@ -314,6 +355,7 @@ public class FilterTest extends TestCase assertTrue(size == 3); } + @Test public void testNoVisFilter() throws IOException { TreeMap tm = new TreeMap(); Value v = new Value(); @@ -330,6 +372,7 @@ public class FilterTest extends TestCase assertTrue("size = " + size, size == 100); } + @Test public void testTimestampFilter() throws IOException, ParseException { Text colf = new Text("a"); Text colq = new Text("b"); @@ -356,6 +399,7 @@ public class FilterTest extends TestCase IteratorSetting is = new IteratorSetting(1, TimestampFilter.class); TimestampFilter.setRange(is, "19990101010011GMT+01:00", "19990101010031GMT+01:00"); a.init(new SortedMapIterator(tm), is.getProperties(), null); + a = (TimestampFilter) a.deepCopy(null); a.seek(new Range(), EMPTY_COL_FAMS, false); assertEquals(size(a), 21); TimestampFilter.setRange(is, baseTime + 11000, baseTime + 31000); Modified: incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/VersioningIteratorTest.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/VersioningIteratorTest.java?rev=1233547&r1=1233546&r2=1233547&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/VersioningIteratorTest.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/test/java/org/apache/accumulo/core/iterators/user/VersioningIteratorTest.java Thu Jan 19 19:33:09 2012 @@ -16,14 +16,15 @@ */ package org.apache.accumulo.core.iterators.user; +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.Entry; import java.util.TreeMap; -import junit.framework.TestCase; - import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.data.ByteSequence; import org.apache.accumulo.core.data.Key; @@ -33,8 +34,9 @@ import org.apache.accumulo.core.iterator import org.apache.accumulo.core.iterators.SortedMapIterator; import org.apache.accumulo.core.iterators.TypedValueCombiner.Encoder; import org.apache.hadoop.io.Text; +import org.junit.Test; -public class VersioningIteratorTest extends TestCase { +public class VersioningIteratorTest { // add test for seek function private static final Collection EMPTY_COL_FAMS = new ArrayList(); private static final Encoder encoder = LongCombiner.FIXED_LEN_ENCODER; @@ -60,6 +62,7 @@ public class VersioningIteratorTest exte return tmOut; } + @Test public void test1() { Text colf = new Text("a"); Text colq = new Text("b"); @@ -90,6 +93,7 @@ public class VersioningIteratorTest exte } } + @Test public void test2() { Text colf = new Text("a"); Text colq = new Text("b"); @@ -99,7 +103,10 @@ public class VersioningIteratorTest exte createTestData(tm, colf, colq); try { - VersioningIterator it = new VersioningIterator(new SortedMapIterator(tm), 3); + VersioningIterator it = new VersioningIterator(); + IteratorSetting is = new IteratorSetting(1, VersioningIterator.class); + VersioningIterator.setMaxVersions(is, 3); + it.init(new SortedMapIterator(tm), is.getProperties(), null); // after doing this seek, should only get two keys for row 1 // since we are seeking to the middle of the most recent @@ -122,6 +129,7 @@ public class VersioningIteratorTest exte } } + @Test public void test3() { Text colf = new Text("a"); Text colq = new Text("b"); @@ -170,6 +178,7 @@ public class VersioningIteratorTest exte } } + @Test public void test4() { Text colf = new Text("a"); Text colq = new Text("b"); @@ -198,6 +207,7 @@ public class VersioningIteratorTest exte } } + @Test public void test5() throws IOException { Text colf = new Text("a"); Text colq = new Text("b"); @@ -219,4 +229,29 @@ public class VersioningIteratorTest exte } + @Test + public void test6() throws IOException { + Text colf = new Text("a"); + Text colq = new Text("b"); + + TreeMap tm = new TreeMap(); + + createTestData(tm, colf, colq); + + VersioningIterator it = new VersioningIterator(); + IteratorSetting is = new IteratorSetting(1, VersioningIterator.class); + VersioningIterator.setMaxVersions(is, 3); + it.init(new SortedMapIterator(tm), is.getProperties(), null); + VersioningIterator it2 = it.deepCopy(null); + + Key seekKey = new Key(new Text(String.format("%03d", 1)), colf, colq, 19); + it.seek(new Range(seekKey, false, null, true), EMPTY_COL_FAMS, false); + it2.seek(new Range(seekKey, false, null, true), EMPTY_COL_FAMS, false); + + assertTrue(it.hasTop()); + assertTrue(it.getTopKey().getTimestamp() == 18); + + assertTrue(it2.hasTop()); + assertTrue(it2.getTopKey().getTimestamp() == 18); + } }