use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class DeletingIteratorTest method test2.
// seek test
@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");
SortedKeyValueIterator<Key, Value> it = DeletingIterator.wrap(new SortedMapIterator(tm), false, Behavior.PROCESS);
// 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.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class SourceSwitchingIteratorTest method test3.
@Test
public void test3() throws Exception {
// test switching after a row
TreeMap<Key, Value> tm1 = new TreeMap<>();
put(tm1, "r1", "cf1", "cq1", 5, "v1");
put(tm1, "r1", "cf1", "cq2", 5, "v2");
put(tm1, "r1", "cf1", "cq3", 5, "v3");
put(tm1, "r1", "cf1", "cq4", 5, "v4");
put(tm1, "r3", "cf1", "cq1", 5, "v5");
put(tm1, "r3", "cf1", "cq2", 5, "v6");
SortedMapIterator smi = new SortedMapIterator(tm1);
TestDataSource tds = new TestDataSource(smi);
SourceSwitchingIterator ssi = new SourceSwitchingIterator(tds, true);
ssi.seek(new Range(), new ArrayList<>(), false);
testAndCallNext(ssi, "r1", "cf1", "cq1", 5, "v1", true);
TreeMap<Key, Value> tm2 = new TreeMap<>(tm1);
// should not see this because it should not switch until
put(tm2, "r1", "cf1", "cq5", 5, "v7");
// the row is finished
// should see this new row after it switches
put(tm2, "r2", "cf1", "cq1", 5, "v8");
// setup a new data source, but it should not switch until the current row is finished
SortedMapIterator smi2 = new SortedMapIterator(tm2);
tds.next = new TestDataSource(smi2);
testAndCallNext(ssi, "r1", "cf1", "cq2", 5, "v2", true);
testAndCallNext(ssi, "r1", "cf1", "cq3", 5, "v3", true);
testAndCallNext(ssi, "r1", "cf1", "cq4", 5, "v4", true);
testAndCallNext(ssi, "r2", "cf1", "cq1", 5, "v8", true);
testAndCallNext(ssi, "r3", "cf1", "cq1", 5, "v5", true);
testAndCallNext(ssi, "r3", "cf1", "cq2", 5, "v6", true);
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class SourceSwitchingIteratorTest method test4.
@Test
public void test4() throws Exception {
// ensure switch is done on initial seek
TreeMap<Key, Value> tm1 = new TreeMap<>();
put(tm1, "r1", "cf1", "cq1", 5, "v1");
put(tm1, "r1", "cf1", "cq2", 5, "v2");
SortedMapIterator smi = new SortedMapIterator(tm1);
TestDataSource tds = new TestDataSource(smi);
SourceSwitchingIterator ssi = new SourceSwitchingIterator(tds, false);
TreeMap<Key, Value> tm2 = new TreeMap<>();
put(tm2, "r1", "cf1", "cq1", 6, "v3");
put(tm2, "r1", "cf1", "cq2", 6, "v4");
SortedMapIterator smi2 = new SortedMapIterator(tm2);
tds.next = new TestDataSource(smi2);
ssi.seek(new Range(), new ArrayList<>(), false);
testAndCallNext(ssi, "r1", "cf1", "cq1", 6, "v3", true);
testAndCallNext(ssi, "r1", "cf1", "cq2", 6, "v4", true);
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class SourceSwitchingIteratorTest method test5.
@Test
public void test5() throws Exception {
// ensure switchNow() works w/ deepCopy()
TreeMap<Key, Value> tm1 = new TreeMap<>();
put(tm1, "r1", "cf1", "cq1", 5, "v1");
put(tm1, "r1", "cf1", "cq2", 5, "v2");
SortedMapIterator smi = new SortedMapIterator(tm1);
TestDataSource tds = new TestDataSource(smi);
SourceSwitchingIterator ssi = new SourceSwitchingIterator(tds, false);
SortedKeyValueIterator<Key, Value> dc1 = ssi.deepCopy(null);
TreeMap<Key, Value> tm2 = new TreeMap<>();
put(tm2, "r1", "cf1", "cq1", 6, "v3");
put(tm2, "r2", "cf1", "cq2", 6, "v4");
SortedMapIterator smi2 = new SortedMapIterator(tm2);
TestDataSource tds2 = new TestDataSource(smi2);
tds.setNext(tds2);
ssi.switchNow();
ssi.seek(new Range("r1"), new ArrayList<>(), false);
dc1.seek(new Range("r2"), new ArrayList<>(), false);
testAndCallNext(ssi, "r1", "cf1", "cq1", 6, "v3", true);
assertFalse(ssi.hasTop());
testAndCallNext(dc1, "r2", "cf1", "cq2", 6, "v4", true);
assertFalse(dc1.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class WholeRowIteratorTest method testBug1.
@Test
public void testBug1() throws Exception {
SortedMap<Key, Value> map1 = new TreeMap<>();
pkv(map1, "row1", "cf1", "cq1", "cv1", 5, "foo");
pkv(map1, "row1", "cf1", "cq2", "cv1", 6, "bar");
SortedMap<Key, Value> map2 = new TreeMap<>();
pkv(map2, "row2", "cf1", "cq1", "cv1", 5, "foo");
SortedMap<Key, Value> map = new TreeMap<>();
map.putAll(map1);
map.putAll(map2);
MultiIterator source = new MultiIterator(Collections.singletonList(new SortedMapIterator(map)), new Range(null, true, new Text("row1"), true));
WholeRowIterator iter = new WholeRowIterator(source);
Range range = new Range(new Text("row1"), true, new Text("row2"), true);
iter.seek(range, new ArrayList<>(), false);
assertTrue(iter.hasTop());
assertEquals(map1, WholeRowIterator.decodeRow(iter.getTopKey(), iter.getTopValue()));
// simulate something continuing using the last key from the iterator
// this is what client and server code will do
range = new Range(iter.getTopKey(), false, range.getEndKey(), range.isEndKeyInclusive());
iter.seek(range, new ArrayList<>(), false);
assertFalse(iter.hasTop());
}
Aggregations