http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/file/rfile/MultiLevelIndexTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/file/rfile/MultiLevelIndexTest.java b/core/src/test/java/org/apache/accumulo/core/file/rfile/MultiLevelIndexTest.java index 0487495..6f89454 100644 --- a/core/src/test/java/org/apache/accumulo/core/file/rfile/MultiLevelIndexTest.java +++ b/core/src/test/java/org/apache/accumulo/core/file/rfile/MultiLevelIndexTest.java @@ -39,44 +39,44 @@ import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; public class MultiLevelIndexTest extends TestCase { - + public void test1() throws Exception { - + runTest(500, 1); runTest(500, 10); runTest(500, 100); runTest(500, 1000); runTest(500, 10000); - + runTest(1, 100); } - + private void runTest(int maxBlockSize, int num) throws IOException { AccumuloConfiguration aconf = AccumuloConfiguration.getDefaultConfiguration(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); FSDataOutputStream dos = new FSDataOutputStream(baos, new FileSystem.Statistics("a")); CachableBlockFile.Writer _cbw = new CachableBlockFile.Writer(dos, "gz", CachedConfiguration.getInstance(), aconf); - + BufferedWriter mliw = new BufferedWriter(new Writer(_cbw, maxBlockSize)); - + for (int i = 0; i < num; i++) mliw.add(new Key(String.format("%05d000", i)), i, 0, 0, 0); - + mliw.addLast(new Key(String.format("%05d000", num)), num, 0, 0, 0); - + ABlockWriter root = _cbw.prepareMetaBlock("root"); mliw.close(root); root.close(); - + _cbw.close(); dos.close(); baos.close(); - + byte[] data = baos.toByteArray(); SeekableByteArrayInputStream bais = new SeekableByteArrayInputStream(data); FSDataInputStream in = new FSDataInputStream(bais); CachableBlockFile.Reader _cbr = new CachableBlockFile.Reader(in, data.length, CachedConfiguration.getInstance(), aconf); - + Reader reader = new Reader(_cbr, RFile.RINDEX_VER_7); BlockRead rootIn = _cbr.getMetaBlock("root"); reader.readFields(rootIn); @@ -89,22 +89,22 @@ public class MultiLevelIndexTest extends TestCase { assertEquals(count, liter.next().getNumEntries()); count++; } - + assertEquals(num + 1, count); - + while (liter.hasPrevious()) { count--; assertEquals(count, liter.previousIndex()); assertEquals(count, liter.peekPrevious().getNumEntries()); assertEquals(count, liter.previous().getNumEntries()); } - + assertEquals(0, count); - + // go past the end liter = reader.lookup(new Key(String.format("%05d000", num + 1))); assertFalse(liter.hasNext()); - + Random rand = new Random(); for (int i = 0; i < 100; i++) { int k = rand.nextInt(num * 1000); @@ -117,7 +117,7 @@ public class MultiLevelIndexTest extends TestCase { IndexEntry ie = liter.next(); assertEquals(expected, ie.getNumEntries()); } - + } - + }
http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java b/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java index 969b179..1a83f33 100644 --- a/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java +++ b/core/src/test/java/org/apache/accumulo/core/file/rfile/RFileTest.java @@ -178,7 +178,7 @@ public class RFileTest { private AccumuloConfiguration accumuloConfiguration; public Reader reader; public SortedKeyValueIterator<Key,Value> iter; - + public TestRFile(AccumuloConfiguration accumuloConfiguration) { this.accumuloConfiguration = accumuloConfiguration; if (this.accumuloConfiguration == null) @@ -250,7 +250,7 @@ public class RFileTest { static String nf(String prefix, int i) { return String.format(prefix + "%06d", i); } - + public AccumuloConfiguration conf = null; @Test @@ -1761,15 +1761,16 @@ public class RFileTest { trf.closeWriter(); byte[] rfBytes = trf.baos.toByteArray(); - + // If we get here, we have encrypted bytes for (Property prop : Property.values()) { if (prop.isSensitive()) { byte[] toCheck = prop.getKey().getBytes(); - assertEquals(-1, Bytes.indexOf(rfBytes, toCheck)); } - } + assertEquals(-1, Bytes.indexOf(rfBytes, toCheck)); + } + } } - + @Test public void testRootTabletEncryption() throws Exception { http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/file/rfile/RelativeKeyTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/file/rfile/RelativeKeyTest.java b/core/src/test/java/org/apache/accumulo/core/file/rfile/RelativeKeyTest.java index 8c0e691..e413448 100644 --- a/core/src/test/java/org/apache/accumulo/core/file/rfile/RelativeKeyTest.java +++ b/core/src/test/java/org/apache/accumulo/core/file/rfile/RelativeKeyTest.java @@ -37,7 +37,7 @@ import org.junit.BeforeClass; import org.junit.Test; public class RelativeKeyTest { - + @Test public void testBasicRelativeKey() { assertEquals(1, UnsynchronizedBuffer.nextArraySize(0)); @@ -48,11 +48,11 @@ public class RelativeKeyTest { assertEquals(8, UnsynchronizedBuffer.nextArraySize(5)); assertEquals(8, UnsynchronizedBuffer.nextArraySize(8)); assertEquals(16, UnsynchronizedBuffer.nextArraySize(9)); - + assertEquals(1 << 16, UnsynchronizedBuffer.nextArraySize((1 << 16) - 1)); assertEquals(1 << 16, UnsynchronizedBuffer.nextArraySize(1 << 16)); assertEquals(1 << 17, UnsynchronizedBuffer.nextArraySize((1 << 16) + 1)); - + assertEquals(1 << 30, UnsynchronizedBuffer.nextArraySize((1 << 30) - 1)); assertEquals(1 << 30, UnsynchronizedBuffer.nextArraySize(1 << 30)); @@ -60,7 +60,7 @@ public class RelativeKeyTest { assertEquals(Integer.MAX_VALUE, UnsynchronizedBuffer.nextArraySize(Integer.MAX_VALUE - 1)); assertEquals(Integer.MAX_VALUE, UnsynchronizedBuffer.nextArraySize(Integer.MAX_VALUE)); } - + @Test public void testCommonPrefix() { // exact matches @@ -73,13 +73,13 @@ public class RelativeKeyTest { assertEquals(-1, commonPrefixHelper("abab", "abab")); assertEquals(-1, commonPrefixHelper(new String("aaa"), new ArrayByteSequence("aaa").toString())); assertEquals(-1, commonPrefixHelper("abababababab".substring(3, 6), "ccababababcc".substring(3, 6))); - + // no common prefix assertEquals(0, commonPrefixHelper("", "a")); assertEquals(0, commonPrefixHelper("a", "")); assertEquals(0, commonPrefixHelper("a", "b")); assertEquals(0, commonPrefixHelper("aaaa", "bbbb")); - + // some common prefix assertEquals(1, commonPrefixHelper("a", "ab")); assertEquals(1, commonPrefixHelper("ab", "ac")); @@ -87,44 +87,44 @@ public class RelativeKeyTest { assertEquals(2, commonPrefixHelper("aa", "aaaa")); assertEquals(4, commonPrefixHelper("aaaaa", "aaaab")); } - + private int commonPrefixHelper(String a, String b) { return RelativeKey.getCommonPrefix(new ArrayByteSequence(a), new ArrayByteSequence(b)); } - + @Test public void testReadWritePrefix() throws IOException { Key prevKey = new Key("row1", "columnfamily1", "columnqualifier1", "columnvisibility1", 1000); Key newKey = new Key("row2", "columnfamily2", "columnqualifier2", "columnvisibility2", 3000); RelativeKey expected = new RelativeKey(prevKey, newKey); - + ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); expected.write(out); - + RelativeKey actual = new RelativeKey(); actual.setPrevKey(prevKey); actual.readFields(new DataInputStream(new ByteArrayInputStream(baos.toByteArray()))); - + assertEquals(expected.getKey(), actual.getKey()); } - + private static ArrayList<Key> expectedKeys; private static ArrayList<Value> expectedValues; private static ArrayList<Integer> expectedPositions; private static ByteArrayOutputStream baos; - + @BeforeClass public static void initSource() throws IOException { int initialListSize = 10000; - + baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); - + expectedKeys = new ArrayList<Key>(initialListSize); expectedValues = new ArrayList<Value>(initialListSize); expectedPositions = new ArrayList<Integer>(initialListSize); - + Key prev = null; int val = 0; for (int row = 0; row < 4; row++) { @@ -145,7 +145,7 @@ public class RelativeKeyTest { v.write(out); expectedKeys.add(k); expectedValues.add(v); - + k = RFileTest.nk(rowS, cfS, cqS, cvS, ts); v = RFileTest.nv("" + val); expectedPositions.add(out.size()); @@ -154,7 +154,7 @@ public class RelativeKeyTest { v.write(out); expectedKeys.add(k); expectedValues.add(v); - + val++; } } @@ -162,34 +162,34 @@ public class RelativeKeyTest { } } } - + private DataInputStream in; - + @Before public void setupDataInputStream() { in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray())); in.mark(0); } - + @Test public void testSeekBeforeEverything() throws IOException { Key seekKey = new Key(); Key prevKey = new Key(); Key currKey = null; MutableByteSequence value = new MutableByteSequence(new byte[64], 0, 0); - + RelativeKey.SkippR skippr = RelativeKey.fastSkip(in, seekKey, value, prevKey, currKey); assertEquals(1, skippr.skipped); assertEquals(new Key(), skippr.prevKey); assertEquals(expectedKeys.get(0), skippr.rk.getKey()); assertEquals(expectedValues.get(0).toString(), value.toString()); - + // ensure we can advance after fastskip skippr.rk.readFields(in); assertEquals(expectedKeys.get(1), skippr.rk.getKey()); - + in.reset(); - + seekKey = new Key("a", "b", "c", "d", 1); seekKey.setDeleted(true); skippr = RelativeKey.fastSkip(in, seekKey, value, prevKey, currKey); @@ -197,21 +197,21 @@ public class RelativeKeyTest { assertEquals(new Key(), skippr.prevKey); assertEquals(expectedKeys.get(0), skippr.rk.getKey()); assertEquals(expectedValues.get(0).toString(), value.toString()); - + skippr.rk.readFields(in); assertEquals(expectedKeys.get(1), skippr.rk.getKey()); } - + @Test(expected = EOFException.class) public void testSeekAfterEverything() throws IOException { Key seekKey = new Key("s", "t", "u", "v", 1); Key prevKey = new Key(); Key currKey = null; MutableByteSequence value = new MutableByteSequence(new byte[64], 0, 0); - + RelativeKey.fastSkip(in, seekKey, value, prevKey, currKey); } - + @Test public void testSeekMiddle() throws IOException { int seekIndex = expectedKeys.size() / 2; @@ -219,36 +219,36 @@ public class RelativeKeyTest { Key prevKey = new Key(); Key currKey = null; MutableByteSequence value = new MutableByteSequence(new byte[64], 0, 0); - + RelativeKey.SkippR skippr = RelativeKey.fastSkip(in, seekKey, value, prevKey, currKey); - + assertEquals(seekIndex + 1, skippr.skipped); assertEquals(expectedKeys.get(seekIndex - 1), skippr.prevKey); assertEquals(expectedKeys.get(seekIndex), skippr.rk.getKey()); assertEquals(expectedValues.get(seekIndex).toString(), value.toString()); - + skippr.rk.readFields(in); assertEquals(expectedValues.get(seekIndex + 1).toString(), value.toString()); - + // try fast skipping to a key that does not exist in.reset(); Key fKey = expectedKeys.get(seekIndex).followingKey(PartialKey.ROW_COLFAM_COLQUAL); int i; for (i = seekIndex; expectedKeys.get(i).compareTo(fKey) < 0; i++) {} - + skippr = RelativeKey.fastSkip(in, expectedKeys.get(i), value, prevKey, currKey); assertEquals(i + 1, skippr.skipped); assertEquals(expectedKeys.get(i - 1), skippr.prevKey); assertEquals(expectedKeys.get(i), skippr.rk.getKey()); assertEquals(expectedValues.get(i).toString(), value.toString()); - + // try fast skipping to our current location skippr = RelativeKey.fastSkip(in, expectedKeys.get(i), value, expectedKeys.get(i - 1), expectedKeys.get(i)); assertEquals(0, skippr.skipped); assertEquals(expectedKeys.get(i - 1), skippr.prevKey); assertEquals(expectedKeys.get(i), skippr.rk.getKey()); assertEquals(expectedValues.get(i).toString(), value.toString()); - + // try fast skipping 1 column family ahead from our current location, testing fastskip from middle of block as opposed to stating at beginning of block fKey = expectedKeys.get(i).followingKey(PartialKey.ROW_COLFAM); int j; @@ -258,6 +258,6 @@ public class RelativeKeyTest { assertEquals(expectedKeys.get(j - 1), skippr.prevKey); assertEquals(expectedKeys.get(j), skippr.rk.getKey()); assertEquals(expectedValues.get(j).toString(), value.toString()); - + } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/iterators/AggregatingIteratorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/AggregatingIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/AggregatingIteratorTest.java index 137a462..788366a 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/AggregatingIteratorTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/AggregatingIteratorTest.java @@ -40,413 +40,413 @@ import org.apache.hadoop.io.Text; */ @Deprecated public class AggregatingIteratorTest extends TestCase { - + private static final Collection<ByteSequence> EMPTY_COL_FAMS = new ArrayList<ByteSequence>(); - + public static class SummationAggregator implements Aggregator { - + int sum; - + public Value aggregate() { return new Value((sum + "").getBytes()); } - + public void collect(Value value) { int val = Integer.parseInt(value.toString()); - + sum += val; } - + public void reset() { sum = 0; - + } - + } - + static Key nk(int row, int colf, int colq, long ts, boolean deleted) { Key k = nk(row, colf, colq, ts); k.setDeleted(true); return k; } - + static Key nk(int row, int colf, int colq, long ts) { return new Key(nr(row), new Text(String.format("cf%03d", colf)), new Text(String.format("cq%03d", colq)), ts); } - + static Range nr(int row, int colf, int colq, long ts, boolean inclusive) { return new Range(nk(row, colf, colq, ts), inclusive, null, true); } - + static Range nr(int row, int colf, int colq, long ts) { return nr(row, colf, colq, ts, true); } - + static void nkv(TreeMap<Key,Value> tm, int row, int colf, int colq, long ts, boolean deleted, String val) { Key k = nk(row, colf, colq, ts); k.setDeleted(deleted); tm.put(k, new Value(val.getBytes())); } - + static Text nr(int row) { return new Text(String.format("r%03d", row)); } - + public void test1() throws IOException { - + TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); - + // keys that do not aggregate nkv(tm1, 1, 1, 1, 1, false, "2"); nkv(tm1, 1, 1, 1, 2, false, "3"); nkv(tm1, 1, 1, 1, 3, false, "4"); - + AggregatingIterator ai = new AggregatingIterator(); - + Map<String,String> emptyMap = Collections.emptyMap(); ai.init(new SortedMapIterator(tm1), emptyMap, null); ai.seek(new Range(), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 3), ai.getTopKey()); assertEquals("4", ai.getTopValue().toString()); - + ai.next(); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 2), ai.getTopKey()); assertEquals("3", ai.getTopValue().toString()); - + ai.next(); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 1), ai.getTopKey()); assertEquals("2", ai.getTopValue().toString()); - + ai.next(); - + assertFalse(ai.hasTop()); - + // try seeking - + ai.seek(nr(1, 1, 1, 2), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 2), ai.getTopKey()); assertEquals("3", ai.getTopValue().toString()); - + ai.next(); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 1), ai.getTopKey()); assertEquals("2", ai.getTopValue().toString()); - + ai.next(); - + assertFalse(ai.hasTop()); - + // seek after everything ai.seek(nr(1, 1, 1, 0), EMPTY_COL_FAMS, false); - + assertFalse(ai.hasTop()); - + } - + public void test2() throws IOException { TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); - + // keys that aggregate nkv(tm1, 1, 1, 1, 1, false, "2"); nkv(tm1, 1, 1, 1, 2, false, "3"); nkv(tm1, 1, 1, 1, 3, false, "4"); - + AggregatingIterator ai = new AggregatingIterator(); - + Map<String,String> opts = new HashMap<String,String>(); - + opts.put("cf001", SummationAggregator.class.getName()); - + ai.init(new SortedMapIterator(tm1), opts, null); ai.seek(new Range(), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 3), ai.getTopKey()); assertEquals("9", ai.getTopValue().toString()); - + ai.next(); - + assertFalse(ai.hasTop()); - + // try seeking to the beginning of a key that aggregates - + ai.seek(nr(1, 1, 1, 3), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 3), ai.getTopKey()); assertEquals("9", ai.getTopValue().toString()); - + ai.next(); - + assertFalse(ai.hasTop()); - + // try seeking the middle of a key the aggregates ai.seek(nr(1, 1, 1, 2), EMPTY_COL_FAMS, false); - + assertFalse(ai.hasTop()); - + // try seeking to the end of a key the aggregates ai.seek(nr(1, 1, 1, 1), EMPTY_COL_FAMS, false); - + assertFalse(ai.hasTop()); - + // try seeking before a key the aggregates ai.seek(nr(1, 1, 1, 4), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 3), ai.getTopKey()); assertEquals("9", ai.getTopValue().toString()); - + ai.next(); - + assertFalse(ai.hasTop()); } - + public void test3() throws IOException { - + TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); - + // keys that aggregate nkv(tm1, 1, 1, 1, 1, false, "2"); nkv(tm1, 1, 1, 1, 2, false, "3"); nkv(tm1, 1, 1, 1, 3, false, "4"); - + // keys that do not aggregate nkv(tm1, 2, 2, 1, 1, false, "2"); nkv(tm1, 2, 2, 1, 2, false, "3"); - + AggregatingIterator ai = new AggregatingIterator(); - + Map<String,String> opts = new HashMap<String,String>(); - + opts.put("cf001", SummationAggregator.class.getName()); - + ai.init(new SortedMapIterator(tm1), opts, null); ai.seek(new Range(), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 3), ai.getTopKey()); assertEquals("9", ai.getTopValue().toString()); - + ai.next(); - + assertTrue(ai.hasTop()); assertEquals(nk(2, 2, 1, 2), ai.getTopKey()); assertEquals("3", ai.getTopValue().toString()); - + ai.next(); - + assertTrue(ai.hasTop()); assertEquals(nk(2, 2, 1, 1), ai.getTopKey()); assertEquals("2", ai.getTopValue().toString()); - + ai.next(); - + assertFalse(ai.hasTop()); - + // seek after key that aggregates ai.seek(nr(1, 1, 1, 2), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(2, 2, 1, 2), ai.getTopKey()); assertEquals("3", ai.getTopValue().toString()); - + // seek before key that aggregates ai.seek(nr(1, 1, 1, 4), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 3), ai.getTopKey()); assertEquals("9", ai.getTopValue().toString()); - + ai.next(); - + assertTrue(ai.hasTop()); assertEquals(nk(2, 2, 1, 2), ai.getTopKey()); assertEquals("3", ai.getTopValue().toString()); - + } - + public void test4() throws IOException { - + TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); - + // keys that do not aggregate nkv(tm1, 0, 0, 1, 1, false, "7"); - + // keys that aggregate nkv(tm1, 1, 1, 1, 1, false, "2"); nkv(tm1, 1, 1, 1, 2, false, "3"); nkv(tm1, 1, 1, 1, 3, false, "4"); - + // keys that do not aggregate nkv(tm1, 2, 2, 1, 1, false, "2"); nkv(tm1, 2, 2, 1, 2, false, "3"); - + AggregatingIterator ai = new AggregatingIterator(); - + Map<String,String> opts = new HashMap<String,String>(); - + opts.put("cf001", SummationAggregator.class.getName()); - + ai.init(new SortedMapIterator(tm1), opts, null); ai.seek(new Range(), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(0, 0, 1, 1), ai.getTopKey()); assertEquals("7", ai.getTopValue().toString()); - + ai.next(); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 3), ai.getTopKey()); assertEquals("9", ai.getTopValue().toString()); - + ai.next(); - + assertTrue(ai.hasTop()); assertEquals(nk(2, 2, 1, 2), ai.getTopKey()); assertEquals("3", ai.getTopValue().toString()); - + ai.next(); - + assertTrue(ai.hasTop()); assertEquals(nk(2, 2, 1, 1), ai.getTopKey()); assertEquals("2", ai.getTopValue().toString()); - + ai.next(); - + assertFalse(ai.hasTop()); - + // seek test ai.seek(nr(0, 0, 1, 0), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 3), ai.getTopKey()); assertEquals("9", ai.getTopValue().toString()); - + ai.next(); - + assertTrue(ai.hasTop()); assertEquals(nk(2, 2, 1, 2), ai.getTopKey()); assertEquals("3", ai.getTopValue().toString()); - + // seek after key that aggregates ai.seek(nr(1, 1, 1, 2), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(2, 2, 1, 2), ai.getTopKey()); assertEquals("3", ai.getTopValue().toString()); - + } - + public void test5() throws IOException { // try aggregating across multiple data sets that contain // the exact same keys w/ different values - + TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); nkv(tm1, 1, 1, 1, 1, false, "2"); - + TreeMap<Key,Value> tm2 = new TreeMap<Key,Value>(); nkv(tm2, 1, 1, 1, 1, false, "3"); - + TreeMap<Key,Value> tm3 = new TreeMap<Key,Value>(); nkv(tm3, 1, 1, 1, 1, false, "4"); - + AggregatingIterator ai = new AggregatingIterator(); Map<String,String> opts = new HashMap<String,String>(); opts.put("cf001", SummationAggregator.class.getName()); - + List<SortedKeyValueIterator<Key,Value>> sources = new ArrayList<SortedKeyValueIterator<Key,Value>>(3); sources.add(new SortedMapIterator(tm1)); sources.add(new SortedMapIterator(tm2)); sources.add(new SortedMapIterator(tm3)); - + MultiIterator mi = new MultiIterator(sources, true); ai.init(mi, opts, null); ai.seek(new Range(), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 1), ai.getTopKey()); assertEquals("9", ai.getTopValue().toString()); } - + public void test6() throws IOException { TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); - + // keys that aggregate nkv(tm1, 1, 1, 1, 1, false, "2"); nkv(tm1, 1, 1, 1, 2, false, "3"); nkv(tm1, 1, 1, 1, 3, false, "4"); - + AggregatingIterator ai = new AggregatingIterator(); - + Map<String,String> opts = new HashMap<String,String>(); - + opts.put("cf001", SummationAggregator.class.getName()); - + ai.init(new SortedMapIterator(tm1), opts, new DefaultIteratorEnvironment()); - + // try seeking to the beginning of a key that aggregates - + ai.seek(nr(1, 1, 1, 3, false), EMPTY_COL_FAMS, false); - + assertFalse(ai.hasTop()); - + } - + public void test7() throws IOException { // test that delete is not aggregated - + TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); - + nkv(tm1, 1, 1, 1, 2, true, ""); nkv(tm1, 1, 1, 1, 3, false, "4"); nkv(tm1, 1, 1, 1, 4, false, "3"); - + AggregatingIterator ai = new AggregatingIterator(); - + Map<String,String> opts = new HashMap<String,String>(); - + opts.put("cf001", SummationAggregator.class.getName()); - + ai.init(new SortedMapIterator(tm1), opts, new DefaultIteratorEnvironment()); - + ai.seek(nr(1, 1, 1, 4, true), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 4), ai.getTopKey()); assertEquals("7", ai.getTopValue().toString()); - + ai.next(); assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 2, true), ai.getTopKey()); assertEquals("", ai.getTopValue().toString()); - + ai.next(); assertFalse(ai.hasTop()); - + tm1 = new TreeMap<Key,Value>(); nkv(tm1, 1, 1, 1, 2, true, ""); ai = new AggregatingIterator(); ai.init(new SortedMapIterator(tm1), opts, new DefaultIteratorEnvironment()); - + ai.seek(nr(1, 1, 1, 4, true), EMPTY_COL_FAMS, false); - + assertTrue(ai.hasTop()); assertEquals(nk(1, 1, 1, 2, true), ai.getTopKey()); assertEquals("", ai.getTopValue().toString()); - + ai.next(); assertFalse(ai.hasTop()); - + } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/iterators/DefaultIteratorEnvironment.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/DefaultIteratorEnvironment.java b/core/src/test/java/org/apache/accumulo/core/iterators/DefaultIteratorEnvironment.java index 94da7b5..c864fcc 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/DefaultIteratorEnvironment.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/DefaultIteratorEnvironment.java @@ -28,42 +28,42 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; public class DefaultIteratorEnvironment implements IteratorEnvironment { - + AccumuloConfiguration conf; - + public DefaultIteratorEnvironment(AccumuloConfiguration conf) { this.conf = conf; } - + public DefaultIteratorEnvironment() { this.conf = AccumuloConfiguration.getDefaultConfiguration(); } - + @Override public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String mapFileName) throws IOException { Configuration conf = CachedConfiguration.getInstance(); FileSystem fs = FileSystem.get(conf); return new MapFileIterator(this.conf, fs, mapFileName, conf); } - + @Override public AccumuloConfiguration getConfig() { return conf; } - + @Override public IteratorScope getIteratorScope() { throw new UnsupportedOperationException(); } - + @Override public boolean isFullMajorCompaction() { throw new UnsupportedOperationException(); } - + @Override public void registerSideChannel(SortedKeyValueIterator<Key,Value> iter) { throw new UnsupportedOperationException(); } - + } http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java index fa46360..21c31e2 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowIteratorTest.java @@ -16,6 +16,8 @@ */ package org.apache.accumulo.core.iterators; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.util.Collections; import java.util.TreeMap; @@ -29,82 +31,76 @@ import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope; import org.apache.accumulo.core.iterators.system.CountingIterator; import org.junit.Test; -import static org.junit.Assert.*; - public class FirstEntryInRowIteratorTest { @SuppressWarnings("unchecked") - private static long process(TreeMap<Key,Value> sourceMap, TreeMap<Key,Value> resultMap, Range range, int numScans) throws IOException - { - org.apache.accumulo.core.iterators.SortedMapIterator source = new SortedMapIterator(sourceMap); - CountingIterator counter = new CountingIterator(source); - FirstEntryInRowIterator feiri = new FirstEntryInRowIterator(); - IteratorEnvironment env = new IteratorEnvironment(){ - - public AccumuloConfiguration getConfig() { - return null; - } - - public IteratorScope getIteratorScope() { - return null; - } - - public boolean isFullMajorCompaction() { - return false; - } - - public void registerSideChannel(SortedKeyValueIterator<Key, Value> arg0) { - - } - - public SortedKeyValueIterator<Key, Value> reserveMapFileReader( - String arg0) throws IOException { - return null; - }}; - - feiri.init(counter, Collections.singletonMap(FirstEntryInRowIterator.NUM_SCANS_STRING_NAME, Integer.toString(numScans)), env); - - feiri.seek(range, Collections.EMPTY_SET, false); - while(feiri.hasTop()) - { - resultMap.put(feiri.getTopKey(), feiri.getTopValue()); - feiri.next(); - } - return counter.getCount(); + private static long process(TreeMap<Key,Value> sourceMap, TreeMap<Key,Value> resultMap, Range range, int numScans) throws IOException { + org.apache.accumulo.core.iterators.SortedMapIterator source = new SortedMapIterator(sourceMap); + CountingIterator counter = new CountingIterator(source); + FirstEntryInRowIterator feiri = new FirstEntryInRowIterator(); + IteratorEnvironment env = new IteratorEnvironment() { + + public AccumuloConfiguration getConfig() { + return null; + } + + public IteratorScope getIteratorScope() { + return null; + } + + public boolean isFullMajorCompaction() { + return false; + } + + public void registerSideChannel(SortedKeyValueIterator<Key,Value> arg0) { + + } + + public SortedKeyValueIterator<Key,Value> reserveMapFileReader(String arg0) throws IOException { + return null; + } + }; + + feiri.init(counter, Collections.singletonMap(FirstEntryInRowIterator.NUM_SCANS_STRING_NAME, Integer.toString(numScans)), env); + + feiri.seek(range, Collections.EMPTY_SET, false); + while (feiri.hasTop()) { + resultMap.put(feiri.getTopKey(), feiri.getTopValue()); + feiri.next(); } + return counter.getCount(); + } @Test - public void test() throws IOException { - TreeMap<Key,Value> sourceMap = new TreeMap<Key, Value>(); - Value emptyValue = new Value("".getBytes()); - sourceMap.put(new Key("r1","cf","cq"), emptyValue); - sourceMap.put(new Key("r2","cf","cq"), emptyValue); - sourceMap.put(new Key("r3","cf","cq"), emptyValue); - TreeMap<Key,Value> resultMap = new TreeMap<Key,Value>(); - long numSourceEntries = sourceMap.size(); - long numNexts = process(sourceMap,resultMap,new Range(),10); - assertEquals(numNexts, numSourceEntries); - assertEquals(sourceMap.size(),resultMap.size()); - - for(int i = 0; i < 20; i++) - { - sourceMap.put(new Key("r2","cf","cq"+i),emptyValue); - } - resultMap.clear(); - numNexts = process(sourceMap,resultMap,new Range(new Key("r1"), (new Key("r2")).followingKey(PartialKey.ROW)),10); - assertEquals(numNexts,resultMap.size()+10); - assertEquals(resultMap.size(),2); - - resultMap.clear(); - numNexts = process(sourceMap,resultMap,new Range(new Key("r1"), new Key("r2","cf2")),10); - assertEquals(numNexts,resultMap.size()+10); - assertEquals(resultMap.size(),2); - - resultMap.clear(); - numNexts = process(sourceMap,resultMap,new Range(new Key("r1"), new Key("r4")),10); - assertEquals(numNexts,resultMap.size()+10); - assertEquals(resultMap.size(),3); + public void test() throws IOException { + TreeMap<Key,Value> sourceMap = new TreeMap<Key,Value>(); + Value emptyValue = new Value("".getBytes()); + sourceMap.put(new Key("r1", "cf", "cq"), emptyValue); + sourceMap.put(new Key("r2", "cf", "cq"), emptyValue); + sourceMap.put(new Key("r3", "cf", "cq"), emptyValue); + TreeMap<Key,Value> resultMap = new TreeMap<Key,Value>(); + long numSourceEntries = sourceMap.size(); + long numNexts = process(sourceMap, resultMap, new Range(), 10); + assertEquals(numNexts, numSourceEntries); + assertEquals(sourceMap.size(), resultMap.size()); + + for (int i = 0; i < 20; i++) { + sourceMap.put(new Key("r2", "cf", "cq" + i), emptyValue); } + resultMap.clear(); + numNexts = process(sourceMap, resultMap, new Range(new Key("r1"), (new Key("r2")).followingKey(PartialKey.ROW)), 10); + assertEquals(numNexts, resultMap.size() + 10); + assertEquals(resultMap.size(), 2); + + resultMap.clear(); + numNexts = process(sourceMap, resultMap, new Range(new Key("r1"), new Key("r2", "cf2")), 10); + assertEquals(numNexts, resultMap.size() + 10); + assertEquals(resultMap.size(), 2); + + resultMap.clear(); + numNexts = process(sourceMap, resultMap, new Range(new Key("r1"), new Key("r4")), 10); + assertEquals(numNexts, resultMap.size() + 10); + assertEquals(resultMap.size(), 3); + } } - http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowTest.java index 3afd629..8214c2c 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/FirstEntryInRowTest.java @@ -36,41 +36,41 @@ import org.junit.Test; public class FirstEntryInRowTest { private static final Map<String,String> EMPTY_MAP = new HashMap<String,String>(); private static final Collection<ByteSequence> EMPTY_SET = new HashSet<ByteSequence>(); - + private Key nk(String row, String cf, String cq, long time) { return new Key(new Text(row), new Text(cf), new Text(cq), time); } - + private Key nk(int row, int cf, int cq, long time) { return nk(String.format("%06d", row), String.format("%06d", cf), String.format("%06d", cq), time); } - + private void put(TreeMap<Key,Value> tm, String row, String cf, String cq, long time, Value val) { tm.put(nk(row, cf, cq, time), val); } - + private void put(TreeMap<Key,Value> tm, String row, String cf, String cq, long time, String val) { put(tm, row, cf, cq, time, new Value(val.getBytes())); } - + private void put(TreeMap<Key,Value> tm, int row, int cf, int cq, long time, int val) { tm.put(nk(row, cf, cq, time), new Value((val + "").getBytes())); } - + private void aten(FirstEntryInRowIterator rdi, String row, String cf, String cq, long time, String val) throws Exception { assertTrue(rdi.hasTop()); assertEquals(nk(row, cf, cq, time), rdi.getTopKey()); assertEquals(val, rdi.getTopValue().toString()); rdi.next(); } - + private void aten(FirstEntryInRowIterator rdi, int row, int cf, int cq, long time, int val) throws Exception { assertTrue(rdi.hasTop()); assertEquals(nk(row, cf, cq, time), rdi.getTopKey()); assertEquals(val, Integer.parseInt(rdi.getTopValue().toString())); rdi.next(); } - + @Test public void test1() throws Exception { TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); @@ -80,22 +80,22 @@ public class FirstEntryInRowTest { put(tm1, "r2", "cf2", "cq4", 5, "v4"); put(tm1, "r2", "cf2", "cq5", 5, "v5"); put(tm1, "r3", "cf3", "cq6", 5, "v6"); - + FirstEntryInRowIterator fei = new FirstEntryInRowIterator(); fei.init(new SortedMapIterator(tm1), EMPTY_MAP, null); - + fei.seek(new Range(), EMPTY_SET, false); aten(fei, "r1", "cf1", "cq1", 5, "v1"); aten(fei, "r2", "cf1", "cq1", 5, "v3"); aten(fei, "r3", "cf3", "cq6", 5, "v6"); assertFalse(fei.hasTop()); - + } - + @Test public void test2() throws Exception { TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); - + for (int r = 0; r < 5; r++) { for (int cf = r; cf < 100; cf++) { for (int cq = 3; cq < 6; cq++) { @@ -103,7 +103,7 @@ public class FirstEntryInRowTest { } } } - + FirstEntryInRowIterator fei = new FirstEntryInRowIterator(); fei.init(new SortedMapIterator(tm1), EMPTY_MAP, null); fei.seek(new Range(nk(0, 10, 0, 0), null), EMPTY_SET, false); @@ -112,16 +112,15 @@ public class FirstEntryInRowTest { aten(fei, 3, 3, 3, 6, 3 * 3 * 3); aten(fei, 4, 4, 3, 6, 4 * 4 * 3); assertFalse(fei.hasTop()); - + fei.seek(new Range(nk(1, 1, 3, 6), nk(3, 3, 3, 6)), EMPTY_SET, false); aten(fei, 1, 1, 3, 6, 1 * 1 * 3); aten(fei, 2, 2, 3, 6, 2 * 2 * 3); aten(fei, 3, 3, 3, 6, 3 * 3 * 3); assertFalse(fei.hasTop()); - + fei.seek(new Range(nk(1, 1, 3, 6), false, nk(3, 3, 3, 6), false), EMPTY_SET, false); aten(fei, 2, 2, 3, 6, 2 * 2 * 3); assertFalse(fei.hasTop()); } } - http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/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 index 4d843d3..125268a 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/IteratorUtilTest.java @@ -45,248 +45,248 @@ 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 + // 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()); http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/NumSummationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/NumSummationTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/NumSummationTest.java index d08c31b..d8d3b47 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/NumSummationTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/NumSummationTest.java @@ -26,22 +26,22 @@ import org.apache.log4j.Logger; */ @Deprecated public class NumSummationTest extends TestCase { - + private static final Logger log = Logger.getLogger(NumSummationTest.class); - + public byte[] init(int n) { byte[] b = new byte[n]; for (int i = 0; i < b.length; i++) b[i] = 0; return b; } - + public void test1() { try { long[] la = {1l, 2l, 3l}; byte[] b = NumArraySummation.longArrayToBytes(la); long[] la2 = NumArraySummation.bytesToLongArray(b); - + assertTrue(la.length == la2.length); for (int i = 0; i < la.length; i++) { assertTrue(i + ": " + la[i] + " does not equal " + la2[i], la[i] == la2[i]); @@ -50,7 +50,7 @@ public class NumSummationTest extends TestCase { assertTrue(false); } } - + public void test2() { try { NumArraySummation nas = new NumArraySummation(); @@ -72,7 +72,7 @@ public class NumSummationTest extends TestCase { assertTrue(false); } } - + public void test3() { try { NumArraySummation nas = new NumArraySummation(); @@ -91,19 +91,19 @@ public class NumSummationTest extends TestCase { assertTrue(false); } } - + public void test4() { try { long l = 5l; byte[] b = NumSummation.longToBytes(l); long l2 = NumSummation.bytesToLong(b); - + assertTrue(l == l2); } catch (Exception e) { assertTrue(false); } } - + public void test5() { try { NumSummation ns = new NumSummation(); @@ -112,23 +112,23 @@ public class NumSummationTest extends TestCase { } long l = NumSummation.bytesToLong(ns.aggregate().get()); assertTrue("l was " + l, l == 13); - + ns.collect(new Value(NumSummation.longToBytes(Long.MAX_VALUE))); l = NumSummation.bytesToLong(ns.aggregate().get()); assertTrue("l was " + l, l == Long.MAX_VALUE); - + ns.collect(new Value(NumSummation.longToBytes(Long.MIN_VALUE))); l = NumSummation.bytesToLong(ns.aggregate().get()); assertTrue("l was " + l, l == -1); - + ns.collect(new Value(NumSummation.longToBytes(Long.MIN_VALUE))); l = NumSummation.bytesToLong(ns.aggregate().get()); assertTrue("l was " + l, l == Long.MIN_VALUE); - + ns.collect(new Value(NumSummation.longToBytes(Long.MIN_VALUE))); l = NumSummation.bytesToLong(ns.aggregate().get()); assertTrue("l was " + l, l == Long.MIN_VALUE); - + ns.reset(); l = NumSummation.bytesToLong(ns.aggregate().get()); assertTrue("l was " + l, l == 0); http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfigurationTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfigurationTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfigurationTest.java index b17ff28..1a285bc 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfigurationTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/aggregation/conf/AggregatorConfigurationTest.java @@ -29,38 +29,38 @@ public class AggregatorConfigurationTest extends TestCase { public void testBinary() { Text colf = new Text(); Text colq = new Text(); - + for (int i = 0; i < 256; i++) { colf.append(new byte[] {(byte) i}, 0, 1); colq.append(new byte[] {(byte) (255 - i)}, 0, 1); } - + runTest(colf, colq); runTest(colf); } - + public void testBasic() { runTest(new Text("colf1"), new Text("cq2")); runTest(new Text("colf1")); } - + private void runTest(Text colf) { String encodedCols; PerColumnIteratorConfig ac3 = new PerColumnIteratorConfig(colf, "com.foo.SuperAgg"); encodedCols = ac3.encodeColumns(); PerColumnIteratorConfig ac4 = PerColumnIteratorConfig.decodeColumns(encodedCols, "com.foo.SuperAgg"); - + assertEquals(colf, ac4.getColumnFamily()); assertNull(ac4.getColumnQualifier()); } - + private void runTest(Text colf, Text colq) { PerColumnIteratorConfig ac = new PerColumnIteratorConfig(colf, colq, "com.foo.SuperAgg"); String encodedCols = ac.encodeColumns(); PerColumnIteratorConfig ac2 = PerColumnIteratorConfig.decodeColumns(encodedCols, "com.foo.SuperAgg"); - + assertEquals(colf, ac2.getColumnFamily()); assertEquals(colq, ac2.getColumnQualifier()); } - + } http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/iterators/system/ColumnFamilySkippingIteratorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/system/ColumnFamilySkippingIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/system/ColumnFamilySkippingIteratorTest.java index aae5e8a..fbe7fd5 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/system/ColumnFamilySkippingIteratorTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/system/ColumnFamilySkippingIteratorTest.java @@ -31,36 +31,36 @@ import org.apache.accumulo.core.iterators.SortedMapIterator; import org.apache.hadoop.io.Text; public class ColumnFamilySkippingIteratorTest extends TestCase { - + private static final Collection<ByteSequence> EMPTY_SET = new HashSet<ByteSequence>(); - + Key nk(String row, String cf, String cq, long time) { return new Key(new Text(row), new Text(cf), new Text(cq), time); } - + Key nk(int row, int cf, int cq, long time) { return nk(String.format("%06d", row), String.format("%06d", cf), String.format("%06d", cq), time); } - + void put(TreeMap<Key,Value> tm, String row, String cf, String cq, long time, Value val) { tm.put(nk(row, cf, cq, time), val); } - + void put(TreeMap<Key,Value> tm, String row, String cf, String cq, long time, String val) { put(tm, row, cf, cq, time, new Value(val.getBytes())); } - + void put(TreeMap<Key,Value> tm, int row, int cf, int cq, long time, int val) { tm.put(nk(row, cf, cq, time), new Value((val + "").getBytes())); } - + private void aten(ColumnFamilySkippingIterator rdi, String row, String cf, String cq, long time, String val) throws Exception { assertTrue(rdi.hasTop()); assertEquals(nk(row, cf, cq, time), rdi.getTopKey()); assertEquals(val, rdi.getTopValue().toString()); rdi.next(); } - + public void test1() throws Exception { TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); put(tm1, "r1", "cf1", "cq1", 5, "v1"); @@ -69,12 +69,12 @@ public class ColumnFamilySkippingIteratorTest extends TestCase { put(tm1, "r2", "cf2", "cq4", 5, "v4"); put(tm1, "r2", "cf2", "cq5", 5, "v5"); put(tm1, "r3", "cf3", "cq6", 5, "v6"); - + ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(new SortedMapIterator(tm1)); - + cfi.seek(new Range(), EMPTY_SET, true); assertFalse(cfi.hasTop()); - + cfi.seek(new Range(), EMPTY_SET, false); assertTrue(cfi.hasTop()); TreeMap<Key,Value> tm2 = new TreeMap<Key,Value>(); @@ -83,14 +83,14 @@ public class ColumnFamilySkippingIteratorTest extends TestCase { cfi.next(); } assertEquals(tm1, tm2); - + HashSet<ByteSequence> colfams = new HashSet<ByteSequence>(); colfams.add(new ArrayByteSequence("cf2")); cfi.seek(new Range(), colfams, true); aten(cfi, "r2", "cf2", "cq4", 5, "v4"); aten(cfi, "r2", "cf2", "cq5", 5, "v5"); assertFalse(cfi.hasTop()); - + colfams.add(new ArrayByteSequence("cf3")); colfams.add(new ArrayByteSequence("cf4")); cfi.seek(new Range(), colfams, true); @@ -98,18 +98,18 @@ public class ColumnFamilySkippingIteratorTest extends TestCase { aten(cfi, "r2", "cf2", "cq5", 5, "v5"); aten(cfi, "r3", "cf3", "cq6", 5, "v6"); assertFalse(cfi.hasTop()); - + cfi.seek(new Range(), colfams, false); aten(cfi, "r1", "cf1", "cq1", 5, "v1"); aten(cfi, "r1", "cf1", "cq3", 5, "v2"); aten(cfi, "r2", "cf1", "cq1", 5, "v3"); assertFalse(cfi.hasTop()); - + } - + public void test2() throws Exception { TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); - + for (int r = 0; r < 10; r++) { for (int cf = 0; cf < 1000; cf++) { for (int cq = 0; cq < 3; cq++) { @@ -117,80 +117,80 @@ public class ColumnFamilySkippingIteratorTest extends TestCase { } } } - + HashSet<ByteSequence> allColfams = new HashSet<ByteSequence>(); for (int cf = 0; cf < 1000; cf++) { allColfams.add(new ArrayByteSequence(String.format("%06d", cf))); } - + ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(new SortedMapIterator(tm1)); HashSet<ByteSequence> colfams = new HashSet<ByteSequence>(); - + runTest(cfi, 30000, 0, allColfams, colfams); - + colfams.add(new ArrayByteSequence(String.format("%06d", 60))); runTest(cfi, 30000, 30, allColfams, colfams); - + colfams.add(new ArrayByteSequence(String.format("%06d", 602))); runTest(cfi, 30000, 60, allColfams, colfams); - + colfams.add(new ArrayByteSequence(String.format("%06d", 0))); runTest(cfi, 30000, 90, allColfams, colfams); - + colfams.add(new ArrayByteSequence(String.format("%06d", 999))); runTest(cfi, 30000, 120, allColfams, colfams); - + colfams.remove(new ArrayByteSequence(String.format("%06d", 0))); runTest(cfi, 30000, 90, allColfams, colfams); - + colfams.add(new ArrayByteSequence(String.format("%06d", 1000))); runTest(cfi, 30000, 90, allColfams, colfams); - + colfams.remove(new ArrayByteSequence(String.format("%06d", 999))); runTest(cfi, 30000, 60, allColfams, colfams); - + colfams.add(new ArrayByteSequence(String.format("%06d", 61))); runTest(cfi, 30000, 90, allColfams, colfams); - + for (int i = 62; i < 100; i++) colfams.add(new ArrayByteSequence(String.format("%06d", i))); - + runTest(cfi, 30000, 1230, allColfams, colfams); - + } - + private void runTest(ColumnFamilySkippingIterator cfi, int total, int expected, HashSet<ByteSequence> allColfams, HashSet<ByteSequence> colfams) throws Exception { cfi.seek(new Range(), colfams, true); HashSet<ByteSequence> excpected1 = new HashSet<ByteSequence>(colfams); excpected1.retainAll(allColfams); runTest(cfi, expected, excpected1); - + HashSet<ByteSequence> excpected2 = new HashSet<ByteSequence>(allColfams); excpected2.removeAll(colfams); cfi.seek(new Range(), colfams, false); runTest(cfi, total - expected, excpected2); } - + private void runTest(ColumnFamilySkippingIterator cfi, int expected, HashSet<ByteSequence> colfams) throws Exception { int count = 0; - + HashSet<ByteSequence> ocf = new HashSet<ByteSequence>(); - + while (cfi.hasTop()) { count++; ocf.add(cfi.getTopKey().getColumnFamilyData()); cfi.next(); } - + assertEquals(expected, count); assertEquals(colfams, ocf); } - + public void test3() throws Exception { // construct test where ColumnFamilySkippingIterator might try to seek past the end of the user supplied range TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); - + for (int r = 0; r < 3; r++) { for (int cf = 4; cf < 1000; cf++) { for (int cq = 0; cq < 1; cq++) { @@ -198,31 +198,31 @@ public class ColumnFamilySkippingIteratorTest extends TestCase { } } } - + CountingIterator ci = new CountingIterator(new SortedMapIterator(tm1)); ColumnFamilySkippingIterator cfi = new ColumnFamilySkippingIterator(ci); HashSet<ByteSequence> colfams = new HashSet<ByteSequence>(); colfams.add(new ArrayByteSequence(String.format("%06d", 4))); - + Range range = new Range(nk(0, 4, 0, 6), true, nk(0, 400, 0, 6), true); cfi.seek(range, colfams, true); - + assertTrue(cfi.hasTop()); assertEquals(nk(0, 4, 0, 6), cfi.getTopKey()); cfi.next(); assertFalse(cfi.hasTop()); - + colfams.add(new ArrayByteSequence(String.format("%06d", 500))); cfi.seek(range, colfams, true); - + assertTrue(cfi.hasTop()); assertEquals(nk(0, 4, 0, 6), cfi.getTopKey()); cfi.next(); assertFalse(cfi.hasTop()); - + range = new Range(nk(0, 4, 0, 6), true, nk(1, 400, 0, 6), true); cfi.seek(range, colfams, true); - + assertTrue(cfi.hasTop()); assertEquals(nk(0, 4, 0, 6), cfi.getTopKey()); cfi.next(); @@ -233,7 +233,7 @@ public class ColumnFamilySkippingIteratorTest extends TestCase { assertEquals(nk(1, 4, 0, 6), cfi.getTopKey()); cfi.next(); assertFalse(cfi.hasTop()); - + // System.out.println(ci.getCount()); } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/iterators/system/ColumnFilterTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/system/ColumnFilterTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/system/ColumnFilterTest.java index 58b3295..3fd66b4 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/system/ColumnFilterTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/system/ColumnFilterTest.java @@ -26,51 +26,51 @@ import org.apache.accumulo.core.data.Value; import org.apache.hadoop.io.Text; public class ColumnFilterTest extends TestCase { - + Key nk(String row, String cf, String cq) { return new Key(new Text(row), new Text(cf), new Text(cq)); } - + Column nc(String cf) { return new Column(cf.getBytes(), null, null); } - + Column nc(String cf, String cq) { return new Column(cf.getBytes(), cq.getBytes(), null); } - + public void test1() { HashSet<Column> columns = new HashSet<Column>(); - + columns.add(nc("cf1")); - + ColumnQualifierFilter cf = new ColumnQualifierFilter(null, columns); - + assertTrue(cf.accept(nk("r1", "cf1", "cq1"), new Value(new byte[0]))); assertTrue(cf.accept(nk("r1", "cf2", "cq1"), new Value(new byte[0]))); - + } - + public void test2() { HashSet<Column> columns = new HashSet<Column>(); - + columns.add(nc("cf1")); columns.add(nc("cf2", "cq1")); - + ColumnQualifierFilter cf = new ColumnQualifierFilter(null, columns); - + assertTrue(cf.accept(nk("r1", "cf1", "cq1"), new Value(new byte[0]))); assertTrue(cf.accept(nk("r1", "cf2", "cq1"), new Value(new byte[0]))); assertFalse(cf.accept(nk("r1", "cf2", "cq2"), new Value(new byte[0]))); } - + public void test3() { HashSet<Column> columns = new HashSet<Column>(); - + columns.add(nc("cf2", "cq1")); - + ColumnQualifierFilter cf = new ColumnQualifierFilter(null, columns); - + assertFalse(cf.accept(nk("r1", "cf1", "cq1"), new Value(new byte[0]))); assertTrue(cf.accept(nk("r1", "cf2", "cq1"), new Value(new byte[0]))); assertFalse(cf.accept(nk("r1", "cf2", "cq2"), new Value(new byte[0]))); http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/iterators/system/DeletingIteratorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/system/DeletingIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/system/DeletingIteratorTest.java index f499680..4fd48d5 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/system/DeletingIteratorTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/system/DeletingIteratorTest.java @@ -32,19 +32,19 @@ import org.apache.accumulo.core.iterators.SortedMapIterator; import org.apache.hadoop.io.Text; public class DeletingIteratorTest extends TestCase { - + private static final Collection<ByteSequence> EMPTY_COL_FAMS = new ArrayList<ByteSequence>(); - + public void test1() { Text colf = new Text("a"); Text colq = new Text("b"); Value dvOld = new Value("old".getBytes()); Value dvDel = new Value("old".getBytes()); Value dvNew = new Value("new".getBytes()); - + TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); Key k; - + for (int i = 0; i < 2; i++) { for (long j = 0; j < 5; j++) { k = new Key(new Text(String.format("%03d", i)), colf, colq, j); @@ -61,12 +61,12 @@ public class DeletingIteratorTest extends TestCase { } } assertTrue("Initial size was " + tm.size(), tm.size() == 21); - + Text checkRow = new Text("000"); try { DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), false); it.seek(new Range(), EMPTY_COL_FAMS, false); - + TreeMap<Key,Value> tmOut = new TreeMap<Key,Value>(); while (it.hasTop()) { tmOut.put(it.getTopKey(), it.getTopValue()); @@ -84,7 +84,7 @@ public class DeletingIteratorTest extends TestCase { } catch (IOException e) { assertFalse(true); } - + try { DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), true); it.seek(new Range(), EMPTY_COL_FAMS, false); @@ -112,120 +112,120 @@ public class DeletingIteratorTest extends TestCase { assertFalse(true); } } - + // seek test public void test2() throws IOException { TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); - + nkv(tm, "r000", 4, false, "v4"); nkv(tm, "r000", 3, false, "v3"); nkv(tm, "r000", 2, true, "v2"); nkv(tm, "r000", 1, false, "v1"); - + DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), false); - + // SEEK two keys before delete it.seek(nr("r000", 4), EMPTY_COL_FAMS, false); - + assertTrue(it.hasTop()); assertEquals(nk("r000", 4), it.getTopKey()); assertEquals("v4", it.getTopValue().toString()); - + it.next(); - + assertTrue(it.hasTop()); assertEquals(nk("r000", 3), it.getTopKey()); assertEquals("v3", it.getTopValue().toString()); - + it.next(); - + assertFalse(it.hasTop()); - + // SEEK passed delete it.seek(nr("r000", 1), EMPTY_COL_FAMS, false); - + assertFalse(it.hasTop()); - + // SEEK to delete it.seek(nr("r000", 2), EMPTY_COL_FAMS, false); - + assertFalse(it.hasTop()); - + // SEEK right before delete it.seek(nr("r000", 3), EMPTY_COL_FAMS, false); - + assertTrue(it.hasTop()); assertEquals(nk("r000", 3), it.getTopKey()); assertEquals("v3", it.getTopValue().toString()); - + it.next(); - + assertFalse(it.hasTop()); } - + // test delete with same timestamp as existing key public void test3() throws IOException { TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); - + nkv(tm, "r000", 3, false, "v3"); nkv(tm, "r000", 2, false, "v2"); nkv(tm, "r000", 2, true, ""); nkv(tm, "r000", 1, false, "v1"); - + DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), false); it.seek(new Range(), EMPTY_COL_FAMS, false); - + assertTrue(it.hasTop()); assertEquals(nk("r000", 3), it.getTopKey()); assertEquals("v3", it.getTopValue().toString()); - + it.next(); - + assertFalse(it.hasTop()); - + it.seek(nr("r000", 2), EMPTY_COL_FAMS, false); - + assertFalse(it.hasTop()); } - + // test range inclusiveness public void test4() throws IOException { TreeMap<Key,Value> tm = new TreeMap<Key,Value>(); - + nkv(tm, "r000", 3, false, "v3"); nkv(tm, "r000", 2, false, "v2"); nkv(tm, "r000", 2, true, ""); nkv(tm, "r000", 1, false, "v1"); - + DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), false); - + it.seek(nr("r000", 3), EMPTY_COL_FAMS, false); - + assertTrue(it.hasTop()); assertEquals(nk("r000", 3), it.getTopKey()); assertEquals("v3", it.getTopValue().toString()); - + it.next(); - + assertFalse(it.hasTop()); - + it.seek(nr("r000", 3, false), EMPTY_COL_FAMS, false); - + assertFalse(it.hasTop()); } - + private Range nr(String row, long ts, boolean inclusive) { return new Range(nk(row, ts), inclusive, null, true); } - + private Range nr(String row, long ts) { return nr(row, ts, true); } - + private Key nk(String row, long ts) { return new Key(new Text(row), ts); } - + private void nkv(TreeMap<Key,Value> tm, String row, long ts, boolean deleted, String val) { Key k = nk(row, ts); k.setDeleted(deleted); http://git-wip-us.apache.org/repos/asf/accumulo/blob/6bc67602/core/src/test/java/org/apache/accumulo/core/iterators/system/MultiIteratorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/accumulo/core/iterators/system/MultiIteratorTest.java b/core/src/test/java/org/apache/accumulo/core/iterators/system/MultiIteratorTest.java index 5fcef31..c8ef180 100644 --- a/core/src/test/java/org/apache/accumulo/core/iterators/system/MultiIteratorTest.java +++ b/core/src/test/java/org/apache/accumulo/core/iterators/system/MultiIteratorTest.java @@ -35,34 +35,34 @@ import org.apache.accumulo.core.util.LocalityGroupUtil; import org.apache.hadoop.io.Text; public class MultiIteratorTest extends TestCase { - + private static final Collection<ByteSequence> EMPTY_COL_FAMS = new ArrayList<ByteSequence>(); - + public static Key nk(int row, long ts) { return new Key(nr(row), ts); } - + public static Range nrng(int row, long ts) { return new Range(nk(row, ts), null); } - + public static void nkv(TreeMap<Key,Value> tm, int row, long ts, boolean deleted, String val) { Key k = nk(row, ts); k.setDeleted(deleted); tm.put(k, new Value(val.getBytes())); } - + public static Text nr(int row) { return new Text(String.format("r%03d", row)); } - + void verify(int start, int end, Key seekKey, Text endRow, Text prevEndRow, boolean init, boolean incrRow, List<TreeMap<Key,Value>> maps) throws IOException { List<SortedKeyValueIterator<Key,Value>> iters = new ArrayList<SortedKeyValueIterator<Key,Value>>(maps.size()); - + for (TreeMap<Key,Value> map : maps) { iters.add(new SortedMapIterator(map)); } - + MultiIterator mi; if (endRow == null && prevEndRow == null) mi = new MultiIterator(iters, init); @@ -72,58 +72,58 @@ public class MultiIteratorTest extends TestCase { for (SortedKeyValueIterator<Key,Value> iter : iters) iter.seek(range, LocalityGroupUtil.EMPTY_CF_SET, false); mi = new MultiIterator(iters, range); - + if (init) mi.seek(range, LocalityGroupUtil.EMPTY_CF_SET, false); } - + if (seekKey != null) mi.seek(new Range(seekKey, null), EMPTY_COL_FAMS, false); else mi.seek(new Range(), EMPTY_COL_FAMS, false); - + int i = start; while (mi.hasTop()) { if (incrRow) assertEquals(nk(i, 0), mi.getTopKey()); else assertEquals(nk(0, i), mi.getTopKey()); - + assertEquals("v" + i, mi.getTopValue().toString()); - + mi.next(); if (incrRow) i++; else i--; } - + assertEquals("start=" + start + " end=" + end + " seekKey=" + seekKey + " endRow=" + endRow + " prevEndRow=" + prevEndRow + " init=" + init + " incrRow=" + incrRow + " maps=" + maps, end, i); } - + void verify(int start, Key seekKey, List<TreeMap<Key,Value>> maps) throws IOException { if (seekKey != null) { verify(start, -1, seekKey, null, null, false, false, maps); } - + verify(start, -1, seekKey, null, null, true, false, maps); } - + void verify(int start, int end, Key seekKey, Text endRow, Text prevEndRow, List<TreeMap<Key,Value>> maps) throws IOException { if (seekKey != null) { verify(start, end, seekKey, endRow, prevEndRow, false, false, maps); } - + verify(start, end, seekKey, endRow, prevEndRow, true, false, maps); } - + public void test1() throws IOException { // TEST non overlapping inputs - + TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); List<TreeMap<Key,Value>> tmpList = new ArrayList<TreeMap<Key,Value>>(2); - + for (int i = 0; i < 4; i++) { nkv(tm1, 0, i, false, "v" + i); } @@ -140,14 +140,14 @@ public class MultiIteratorTest extends TestCase { verify(seek, nk(0, seek), tmpList); } } - + public void test2() throws IOException { // TEST overlapping inputs - + TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); TreeMap<Key,Value> tm2 = new TreeMap<Key,Value>(); List<TreeMap<Key,Value>> tmpList = new ArrayList<TreeMap<Key,Value>>(2); - + for (int i = 0; i < 8; i++) { if (i % 2 == 0) nkv(tm1, 0, i, false, "v" + i); @@ -163,18 +163,18 @@ public class MultiIteratorTest extends TestCase { verify(seek, nk(0, seek), tmpList); } } - + public void test3() throws IOException { // TEST single input - + TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); List<TreeMap<Key,Value>> tmpList = new ArrayList<TreeMap<Key,Value>>(2); - + for (int i = 0; i < 8; i++) { nkv(tm1, 0, i, false, "v" + i); } tmpList.add(tm1); - + for (int seek = -1; seek < 8; seek++) { if (seek == 7) { verify(seek, null, tmpList); @@ -182,71 +182,71 @@ public class MultiIteratorTest extends TestCase { verify(seek, nk(0, seek), tmpList); } } - + public void test4() throws IOException { // TEST empty input - + TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); - + List<SortedKeyValueIterator<Key,Value>> skvil = new ArrayList<SortedKeyValueIterator<Key,Value>>(1); skvil.add(new SortedMapIterator(tm1)); MultiIterator mi = new MultiIterator(skvil, true); - + assertFalse(mi.hasTop()); - + mi.seek(nrng(0, 6), EMPTY_COL_FAMS, false); assertFalse(mi.hasTop()); } - + public void test5() throws IOException { // TEST overlapping inputs AND prevRow AND endRow AND seek - + TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); TreeMap<Key,Value> tm2 = new TreeMap<Key,Value>(); List<TreeMap<Key,Value>> tmpList = new ArrayList<TreeMap<Key,Value>>(2); - + for (int i = 0; i < 8; i++) { if (i % 2 == 0) nkv(tm1, i, 0, false, "v" + i); else nkv(tm2, i, 0, false, "v" + i); } - + tmpList.add(tm1); tmpList.add(tm2); for (int seek = -1; seek < 9; seek++) { verify(Math.max(0, seek), 8, nk(seek, 0), null, null, true, true, tmpList); verify(Math.max(0, seek), 8, nk(seek, 0), null, null, false, true, tmpList); - + for (int er = seek; er < 10; er++) { - + int end = seek > er ? seek : Math.min(er + 1, 8); - + int noSeekEnd = Math.min(er + 1, 8); if (er < 0) { noSeekEnd = 0; } - + verify(0, noSeekEnd, null, nr(er), null, true, true, tmpList); verify(Math.max(0, seek), end, nk(seek, 0), nr(er), null, true, true, tmpList); verify(Math.max(0, seek), end, nk(seek, 0), nr(er), null, false, true, tmpList); - + for (int per = -1; per < er; per++) { - + int start = Math.max(per + 1, seek); - + if (start > er) end = start; - + if (per >= 8) end = start; - + int noSeekStart = Math.max(0, per + 1); - + if (er < 0 || per >= 7) { noSeekEnd = noSeekStart; } - + verify(noSeekStart, noSeekEnd, null, nr(er), nr(per), true, true, tmpList); verify(Math.max(0, start), end, nk(seek, 0), nr(er), nr(per), true, true, tmpList); verify(Math.max(0, start), end, nk(seek, 0), nr(er), nr(per), false, true, tmpList); @@ -254,80 +254,80 @@ public class MultiIteratorTest extends TestCase { } } } - + public void test6() throws IOException { // TEst setting an endKey TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); nkv(tm1, 3, 0, false, "1"); nkv(tm1, 4, 0, false, "2"); nkv(tm1, 6, 0, false, "3"); - + List<SortedKeyValueIterator<Key,Value>> skvil = new ArrayList<SortedKeyValueIterator<Key,Value>>(1); skvil.add(new SortedMapIterator(tm1)); MultiIterator mi = new MultiIterator(skvil, true); mi.seek(new Range(null, true, nk(5, 9), false), EMPTY_COL_FAMS, false); - + assertTrue(mi.hasTop()); assertTrue(mi.getTopKey().equals(nk(3, 0))); assertTrue(mi.getTopValue().toString().equals("1")); mi.next(); - + assertTrue(mi.hasTop()); assertTrue(mi.getTopKey().equals(nk(4, 0))); assertTrue(mi.getTopValue().toString().equals("2")); mi.next(); - + assertFalse(mi.hasTop()); - + mi.seek(new Range(nk(4, 10), true, nk(5, 9), false), EMPTY_COL_FAMS, false); assertTrue(mi.hasTop()); assertTrue(mi.getTopKey().equals(nk(4, 0))); assertTrue(mi.getTopValue().toString().equals("2")); mi.next(); - + assertFalse(mi.hasTop()); - + mi.seek(new Range(nk(4, 10), true, nk(6, 0), false), EMPTY_COL_FAMS, false); assertTrue(mi.hasTop()); assertTrue(mi.getTopKey().equals(nk(4, 0))); assertTrue(mi.getTopValue().toString().equals("2")); mi.next(); - + assertFalse(mi.hasTop()); - + mi.seek(new Range(nk(4, 10), true, nk(6, 0), true), EMPTY_COL_FAMS, false); assertTrue(mi.hasTop()); assertTrue(mi.getTopKey().equals(nk(4, 0))); assertTrue(mi.getTopValue().toString().equals("2")); mi.next(); - + assertTrue(mi.hasTop()); assertTrue(mi.getTopKey().equals(nk(6, 0))); assertTrue(mi.getTopValue().toString().equals("3")); mi.next(); - + assertFalse(mi.hasTop()); - + mi.seek(new Range(nk(4, 0), true, nk(6, 0), false), EMPTY_COL_FAMS, false); assertTrue(mi.hasTop()); assertTrue(mi.getTopKey().equals(nk(4, 0))); assertTrue(mi.getTopValue().toString().equals("2")); mi.next(); - + assertFalse(mi.hasTop()); - + mi.seek(new Range(nk(4, 0), false, nk(6, 0), false), EMPTY_COL_FAMS, false); assertFalse(mi.hasTop()); - + mi.seek(new Range(nk(4, 0), false, nk(6, 0), true), EMPTY_COL_FAMS, false); assertTrue(mi.hasTop()); assertTrue(mi.getTopKey().equals(nk(6, 0))); assertTrue(mi.getTopValue().toString().equals("3")); mi.next(); assertFalse(mi.hasTop()); - + } - + public void test7() throws IOException { // TEst setting an endKey TreeMap<Key,Value> tm1 = new TreeMap<Key,Value>(); @@ -340,13 +340,13 @@ public class MultiIteratorTest extends TestCase { nkv(tm1, 1, 0, false, "7"); nkv(tm1, 2, 1, false, "8"); nkv(tm1, 2, 0, false, "9"); - + List<SortedKeyValueIterator<Key,Value>> skvil = new ArrayList<SortedKeyValueIterator<Key,Value>>(1); skvil.add(new SortedMapIterator(tm1)); - + KeyExtent extent = new KeyExtent(new Text("tablename"), nr(1), nr(0)); MultiIterator mi = new MultiIterator(skvil, extent); - + Range r1 = new Range((Text) null, (Text) null); mi.seek(r1, EMPTY_COL_FAMS, false); assertTrue(mi.hasTop()); @@ -359,7 +359,7 @@ public class MultiIteratorTest extends TestCase { assertTrue(mi.getTopValue().toString().equals("7")); mi.next(); assertFalse(mi.hasTop()); - + Range r2 = new Range(nk(0, 0), true, nk(1, 1), true); mi.seek(r2, EMPTY_COL_FAMS, false); assertTrue(mi.hasTop()); @@ -369,32 +369,32 @@ public class MultiIteratorTest extends TestCase { assertTrue(mi.getTopValue().toString().equals("6")); mi.next(); assertFalse(mi.hasTop()); - + Range r3 = new Range(nk(0, 0), false, nk(1, 1), false); mi.seek(r3, EMPTY_COL_FAMS, false); assertTrue(mi.hasTop()); assertTrue(mi.getTopValue().toString().equals("5")); mi.next(); assertFalse(mi.hasTop()); - + Range r4 = new Range(nk(1, 2), true, nk(1, 1), false); mi.seek(r4, EMPTY_COL_FAMS, false); assertTrue(mi.hasTop()); assertTrue(mi.getTopValue().toString().equals("5")); mi.next(); assertFalse(mi.hasTop()); - + Range r5 = new Range(nk(1, 2), false, nk(1, 1), true); mi.seek(r5, EMPTY_COL_FAMS, false); assertTrue(mi.hasTop()); assertTrue(mi.getTopValue().toString().equals("6")); mi.next(); assertFalse(mi.hasTop()); - + Range r6 = new Range(nk(2, 1), true, nk(2, 0), true); mi.seek(r6, EMPTY_COL_FAMS, false); assertFalse(mi.hasTop()); - + Range r7 = new Range(nk(0, 3), true, nk(0, 1), true); mi.seek(r7, EMPTY_COL_FAMS, false); assertFalse(mi.hasTop());