use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class DeletingIteratorTest method test1.
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 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);
tm.put(k, dvOld);
}
}
k = new Key(new Text(String.format("%03d", 0)), colf, colq, 5);
k.setDeleted(true);
tm.put(k, dvDel);
for (int i = 0; i < 2; i++) {
for (long j = 6; j < 11; j++) {
k = new Key(new Text(String.format("%03d", i)), colf, colq, j);
tm.put(k, dvNew);
}
}
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<>();
while (it.hasTop()) {
tmOut.put(it.getTopKey(), it.getTopValue());
it.next();
}
assertTrue("size after no propagation was " + tmOut.size(), tmOut.size() == 15);
for (Entry<Key, Value> e : tmOut.entrySet()) {
if (e.getKey().getRow().equals(checkRow)) {
byte[] b = e.getValue().get();
assertTrue(b[0] == 'n');
assertTrue(b[1] == 'e');
assertTrue(b[2] == 'w');
}
}
} catch (IOException e) {
assertFalse(true);
}
try {
DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), true);
it.seek(new Range(), EMPTY_COL_FAMS, false);
TreeMap<Key, Value> tmOut = new TreeMap<>();
while (it.hasTop()) {
tmOut.put(it.getTopKey(), it.getTopValue());
it.next();
}
assertTrue("size after propagation was " + tmOut.size(), tmOut.size() == 16);
for (Entry<Key, Value> e : tmOut.entrySet()) {
if (e.getKey().getRow().equals(checkRow)) {
byte[] b = e.getValue().get();
if (e.getKey().isDeleted()) {
assertTrue(b[0] == 'o');
assertTrue(b[1] == 'l');
assertTrue(b[2] == 'd');
} else {
assertTrue(b[0] == 'n');
assertTrue(b[1] == 'e');
assertTrue(b[2] == 'w');
}
}
}
} catch (IOException e) {
assertFalse(true);
}
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class DeletingIteratorTest method test2.
// seek test
public void test2() throws IOException {
TreeMap<Key, Value> tm = new TreeMap<>();
newKeyValue(tm, "r000", 4, false, "v4");
newKeyValue(tm, "r000", 3, false, "v3");
newKeyValue(tm, "r000", 2, true, "v2");
newKeyValue(tm, "r000", 1, false, "v1");
DeletingIterator it = new DeletingIterator(new SortedMapIterator(tm), false);
// SEEK two keys before delete
it.seek(newRange("r000", 4), EMPTY_COL_FAMS, false);
assertTrue(it.hasTop());
assertEquals(newKey("r000", 4), it.getTopKey());
assertEquals("v4", it.getTopValue().toString());
it.next();
assertTrue(it.hasTop());
assertEquals(newKey("r000", 3), it.getTopKey());
assertEquals("v3", it.getTopValue().toString());
it.next();
assertFalse(it.hasTop());
// SEEK passed delete
it.seek(newRange("r000", 1), EMPTY_COL_FAMS, false);
assertFalse(it.hasTop());
// SEEK to delete
it.seek(newRange("r000", 2), EMPTY_COL_FAMS, false);
assertFalse(it.hasTop());
// SEEK right before delete
it.seek(newRange("r000", 3), EMPTY_COL_FAMS, false);
assertTrue(it.hasTop());
assertEquals(newKey("r000", 3), it.getTopKey());
assertEquals("v3", it.getTopValue().toString());
it.next();
assertFalse(it.hasTop());
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class MultiIteratorTest method test4.
public void test4() throws IOException {
// TEST empty input
TreeMap<Key, Value> tm1 = new TreeMap<>();
List<SortedKeyValueIterator<Key, Value>> skvil = new ArrayList<>(1);
skvil.add(new SortedMapIterator(tm1));
MultiIterator mi = new MultiIterator(skvil, true);
assertFalse(mi.hasTop());
mi.seek(newRange(0, 6), EMPTY_COL_FAMS, false);
assertFalse(mi.hasTop());
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class MultiIteratorTest method verify.
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<>(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);
else {
Range range = new Range(prevEndRow, false, endRow, true);
if (init)
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(newKey(i, 0), mi.getTopKey());
else
assertEquals(newKey(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);
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class MultiIteratorTest method test6.
public void test6() throws IOException {
// TEst setting an endKey
TreeMap<Key, Value> tm1 = new TreeMap<>();
newKeyValue(tm1, 3, 0, false, "1");
newKeyValue(tm1, 4, 0, false, "2");
newKeyValue(tm1, 6, 0, false, "3");
List<SortedKeyValueIterator<Key, Value>> skvil = new ArrayList<>(1);
skvil.add(new SortedMapIterator(tm1));
MultiIterator mi = new MultiIterator(skvil, true);
mi.seek(new Range(null, true, newKey(5, 9), false), EMPTY_COL_FAMS, false);
assertTrue(mi.hasTop());
assertTrue(mi.getTopKey().equals(newKey(3, 0)));
assertTrue(mi.getTopValue().toString().equals("1"));
mi.next();
assertTrue(mi.hasTop());
assertTrue(mi.getTopKey().equals(newKey(4, 0)));
assertTrue(mi.getTopValue().toString().equals("2"));
mi.next();
assertFalse(mi.hasTop());
mi.seek(new Range(newKey(4, 10), true, newKey(5, 9), false), EMPTY_COL_FAMS, false);
assertTrue(mi.hasTop());
assertTrue(mi.getTopKey().equals(newKey(4, 0)));
assertTrue(mi.getTopValue().toString().equals("2"));
mi.next();
assertFalse(mi.hasTop());
mi.seek(new Range(newKey(4, 10), true, newKey(6, 0), false), EMPTY_COL_FAMS, false);
assertTrue(mi.hasTop());
assertTrue(mi.getTopKey().equals(newKey(4, 0)));
assertTrue(mi.getTopValue().toString().equals("2"));
mi.next();
assertFalse(mi.hasTop());
mi.seek(new Range(newKey(4, 10), true, newKey(6, 0), true), EMPTY_COL_FAMS, false);
assertTrue(mi.hasTop());
assertTrue(mi.getTopKey().equals(newKey(4, 0)));
assertTrue(mi.getTopValue().toString().equals("2"));
mi.next();
assertTrue(mi.hasTop());
assertTrue(mi.getTopKey().equals(newKey(6, 0)));
assertTrue(mi.getTopValue().toString().equals("3"));
mi.next();
assertFalse(mi.hasTop());
mi.seek(new Range(newKey(4, 0), true, newKey(6, 0), false), EMPTY_COL_FAMS, false);
assertTrue(mi.hasTop());
assertTrue(mi.getTopKey().equals(newKey(4, 0)));
assertTrue(mi.getTopValue().toString().equals("2"));
mi.next();
assertFalse(mi.hasTop());
mi.seek(new Range(newKey(4, 0), false, newKey(6, 0), false), EMPTY_COL_FAMS, false);
assertFalse(mi.hasTop());
mi.seek(new Range(newKey(4, 0), false, newKey(6, 0), true), EMPTY_COL_FAMS, false);
assertTrue(mi.hasTop());
assertTrue(mi.getTopKey().equals(newKey(6, 0)));
assertTrue(mi.getTopValue().toString().equals("3"));
mi.next();
assertFalse(mi.hasTop());
}
Aggregations