public void testCompaction() throws Exception {
TreeMap<Key,Value> testData = new TreeMap<Key,Value>();
genTestData(testData, 20);
LargeRowFilter lrfi = setupIterator(testData, 13, IteratorScope.majc);
lrfi.seek(new Range(), LocalityGroupUtil.EMPTY_CF_SET, false);
TreeMap<Key,Value> compactedData = new TreeMap<Key,Value>();
while (lrfi.hasTop()) {
compactedData.put(lrfi.getTopKey(), lrfi.getTopValue());
lrfi.next();
}
// compacted data should now contain suppression markers
// add column to row that should be suppressed\
genRow(compactedData, 15, 15, 16);
// scanning over data w/ higher max columns should not change behavior
// because there are suppression markers.. if there was a bug and data
// was not suppressed, increasing the threshold would expose the bug
lrfi = setupIterator(compactedData, 20, IteratorScope.scan);
lrfi.seek(new Range(), LocalityGroupUtil.EMPTY_CF_SET, false);
// only expect to see 13 rows
TreeMap<Key,Value> expectedData = new TreeMap<Key,Value>();
genTestData(expectedData, 13);
TreeMap<Key,Value> filteredData = new TreeMap<Key,Value>();
while (lrfi.hasTop()) {
filteredData.put(lrfi.getTopKey(), lrfi.getTopValue());
lrfi.next();
}
assertEquals(expectedData.size() + 8, compactedData.size());
assertEquals(expectedData, filteredData);
// try seeking to the middle of row 15... row has data and suppression marker... this seeks past the marker but before the column
lrfi.seek(new Range(new Key(genRow(15), "cf001", genCQ(4), 5), true, new Key(genRow(15)).followingKey(PartialKey.ROW), false),
LocalityGroupUtil.EMPTY_CF_SET, false);
assertFalse(lrfi.hasTop());
// test seeking w/ column families
HashSet<ByteSequence> colfams = new HashSet<ByteSequence>();
colfams.add(new ArrayByteSequence("cf001"));
lrfi.seek(new Range(new Key(genRow(15), "cf001", genCQ(4), 5), true, new Key(genRow(15)).followingKey(PartialKey.ROW), false), colfams, true);
assertFalse(lrfi.hasTop());
}