use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class VersioningIteratorTest method test3.
@Test
public void test3() {
Text colf = new Text("a");
Text colq = new Text("b");
TreeMap<Key, Value> tm = new TreeMap<>();
createTestData(tm, colf, colq);
try {
VersioningIterator it = new VersioningIterator();
IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
VersioningIterator.setMaxVersions(is, 3);
it.init(new SortedMapIterator(tm), is.getOptions(), null);
// after doing this seek, should get zero keys for row 1
Key seekKey = new Key(new Text(String.format("%03d", 1)), colf, colq, 15);
it.seek(new Range(seekKey, null), EMPTY_COL_FAMS, false);
TreeMap<Key, Value> tmOut = iteratorOverTestData(it);
for (Entry<Key, Value> e : tmOut.entrySet()) {
assertEquals(8, e.getValue().get().length);
assertTrue(16 < encoder.decode(e.getValue().get()));
}
assertEquals(0, tmOut.size(), "size after seeking past versions was " + tmOut.size());
// after doing this seek, should get zero keys for row 0 and 3 keys for row 1
seekKey = new Key(new Text(String.format("%03d", 0)), colf, colq, 15);
it.seek(new Range(seekKey, null), EMPTY_COL_FAMS, false);
tmOut = iteratorOverTestData(it);
for (Entry<Key, Value> e : tmOut.entrySet()) {
assertEquals(8, e.getValue().get().length);
assertTrue(16 < encoder.decode(e.getValue().get()));
}
assertEquals(3, tmOut.size(), "size after seeking past versions was " + tmOut.size());
} catch (IOException e) {
fail();
} catch (Exception e) {
log.error("{}", e.getMessage(), e);
fail();
}
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class VersioningIteratorTest method test_maxLongInclusiveKey.
@Test
public void test_maxLongInclusiveKey() throws IOException {
Text row = new Text("a");
Text colf = new Text("b");
Text colq = new Text("c");
Text cv = new Text();
TreeMap<Key, Value> tm = new TreeMap<>();
tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE), new Value("00"));
tm.put(new Key(row, colf, colq, cv, Long.MAX_VALUE - 1), new Value("11"));
VersioningIterator it = new VersioningIterator();
IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
VersioningIterator.setMaxVersions(is, 1);
it.init(new SortedMapIterator(tm), is.getOptions(), null);
Key startKey = new Key(row, colf, colq, cv, Long.MAX_VALUE);
Range testRange = new Range(startKey, true, startKey.followingKey(PartialKey.ROW), true);
it.seek(testRange, EMPTY_COL_FAMS, false);
assertTrue(it.hasTop());
assertTrue(it.getTopValue().contentEquals("00".getBytes()));
it.next();
assertFalse(it.hasTop());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class VersioningIteratorTest method test2.
@Test
public void test2() {
Text colf = new Text("a");
Text colq = new Text("b");
TreeMap<Key, Value> tm = new TreeMap<>();
createTestData(tm, colf, colq);
try {
VersioningIterator it = new VersioningIterator();
IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
VersioningIterator.setMaxVersions(is, 3);
it.init(new SortedMapIterator(tm), is.getOptions(), null);
// after doing this seek, should only get two keys for row 1
// since we are seeking to the middle of the most recent
// three keys
Key seekKey = new Key(new Text(String.format("%03d", 1)), colf, colq, 18);
it.seek(new Range(seekKey, null), EMPTY_COL_FAMS, false);
TreeMap<Key, Value> tmOut = iteratorOverTestData(it);
for (Entry<Key, Value> e : tmOut.entrySet()) {
assertEquals(8, e.getValue().get().length);
assertTrue(16 < encoder.decode(e.getValue().get()));
}
assertEquals(2, tmOut.size(), "size after keeping 2 versions was " + tmOut.size());
} catch (IOException e) {
fail();
} catch (Exception e) {
log.error("{}", e.getMessage(), e);
fail();
}
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class VersioningIteratorTest method test6.
@Test
public void test6() throws IOException {
Text colf = new Text("a");
Text colq = new Text("b");
TreeMap<Key, Value> tm = new TreeMap<>();
createTestData(tm, colf, colq);
VersioningIterator it = new VersioningIterator();
IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
VersioningIterator.setMaxVersions(is, 3);
it.init(new SortedMapIterator(tm), is.getOptions(), null);
VersioningIterator it2 = it.deepCopy(null);
Key seekKey = new Key(new Text(String.format("%03d", 1)), colf, colq, 19);
it.seek(new Range(seekKey, false, null, true), EMPTY_COL_FAMS, false);
it2.seek(new Range(seekKey, false, null, true), EMPTY_COL_FAMS, false);
assertTrue(it.hasTop());
assertEquals(18, it.getTopKey().getTimestamp());
assertTrue(it2.hasTop());
assertEquals(18, it2.getTopKey().getTimestamp());
}
use of org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator in project accumulo by apache.
the class WholeColumnFamilyIteratorTest method testContinue.
@Test
public void testContinue() 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");
pkv(map2, "row2", "cf1", "cq2", "cv1", 6, "bar");
SortedMap<Key, Value> map3 = new TreeMap<>();
pkv(map3, "row3", "cf1", "cq1", "cv1", 5, "foo");
pkv(map3, "row3", "cf1", "cq2", "cv1", 6, "bar");
SortedMap<Key, Value> map = new TreeMap<>();
map.putAll(map1);
map.putAll(map2);
map.putAll(map3);
SortedMapIterator source = new SortedMapIterator(map);
WholeColumnFamilyIterator iter = new WholeColumnFamilyIterator(source);
Range range = new Range(new Text("row1"), true, new Text("row2"), true);
iter.seek(range, new ArrayList<>(), false);
assertTrue(iter.hasTop());
assertEquals(map1, WholeColumnFamilyIterator.decodeColumnFamily(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);
assertTrue(iter.hasTop());
assertEquals(map2, WholeColumnFamilyIterator.decodeColumnFamily(iter.getTopKey(), iter.getTopValue()));
iter.next();
assertFalse(iter.hasTop());
}
Aggregations