@Test
public void testEmptyStuff() throws IOException {
SortedMap<Key,Value> map = new TreeMap<Key,Value>();
SortedMap<Key,Value> map2 = new TreeMap<Key,Value>();
final Map<Text,Boolean> toInclude = new HashMap<Text,Boolean>();
map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 1l), new Value("val1".getBytes()));
map.put(new Key(new Text("r1"), new Text("cf1"), new Text("cq2"), new Text("cv1"), 2l), new Value("val2".getBytes()));
map.put(new Key(new Text("r2"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 3l), new Value("val3".getBytes()));
map.put(new Key(new Text("r2"), new Text("cf2"), new Text("cq1"), new Text("cv1"), 4l), new Value("val4".getBytes()));
map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 5l), new Value("val4".getBytes()));
map.put(new Key(new Text("r3"), new Text("cf1"), new Text("cq1"), new Text("cv2"), 6l), new Value("val4".getBytes()));
map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text("cv1"), 7l), new Value("".getBytes()));
map.put(new Key(new Text("r4"), new Text("cf1"), new Text("cq1"), new Text(""), 8l), new Value("val1".getBytes()));
map.put(new Key(new Text("r4"), new Text("cf1"), new Text(""), new Text("cv1"), 9l), new Value("val1".getBytes()));
map.put(new Key(new Text("r4"), new Text(""), new Text("cq1"), new Text("cv1"), 10l), new Value("val1".getBytes()));
map.put(new Key(new Text(""), new Text("cf1"), new Text("cq1"), new Text("cv1"), 11l), new Value("val1".getBytes()));
boolean b = true;
int trueCount = 0;
for (Key k : map.keySet()) {
if (toInclude.containsKey(k.getRow())) {
if (toInclude.get(k.getRow())) {
map2.put(k, map.get(k));
}
continue;
}
b = !b;
toInclude.put(k.getRow(), b);
if (b) {
trueCount++;
map2.put(k, map.get(k));
}
}
SortedMapIterator source = new SortedMapIterator(map);
WholeRowIterator iter = new WholeRowIterator(source);
SortedMap<Key,Value> resultMap = new TreeMap<Key,Value>();
iter.seek(new Range(), new ArrayList<ByteSequence>(), false);
int numRows = 0;
while (iter.hasTop()) {
numRows++;
Key rowKey = iter.getTopKey();
Value rowValue = iter.getTopValue();
resultMap.putAll(WholeRowIterator.decodeRow(rowKey, rowValue));
iter.next();
}
assertTrue(numRows == 5);
assertEquals(resultMap, map);
WholeRowIterator iter2 = new WholeRowIterator(source) {
@Override
public boolean filter(Text row, List<Key> keys, List<Value> values) {
return toInclude.get(row);
}
};
resultMap.clear();
iter2.seek(new Range(), new ArrayList<ByteSequence>(), false);
numRows = 0;
while (iter2.hasTop()) {
numRows++;
Key rowKey = iter2.getTopKey();
Value rowValue = iter2.getTopValue();
resultMap.putAll(WholeRowIterator.decodeRow(rowKey, rowValue));
iter2.next();
}
assertTrue(numRows == trueCount);
assertEquals(resultMap, map2);