use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class RowFilterTest method testFilterConjunction.
@Test
public void testFilterConjunction() throws Exception {
SortedMapIterator source = new SortedMapIterator(createKeyValues());
RowFilter filter0 = new RowZeroOrOneFilter();
filter0.init(source, Collections.emptyMap(), new DefaultIteratorEnvironment());
RowFilter filter = new RowOneOrTwoFilter();
filter.init(filter0, Collections.emptyMap(), new DefaultIteratorEnvironment());
filter.seek(new Range(), Collections.emptySet(), false);
assertEquals(new HashSet<>(Arrays.asList("1")), getRows(filter));
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class TransformingIteratorTest method setUpTransformIterator.
private void setUpTransformIterator(Class<? extends TransformingIterator> clazz, boolean setupAuths) throws IOException {
SortedMapIterator source = new SortedMapIterator(data);
ColumnFamilySkippingIterator cfsi = new ColumnFamilySkippingIterator(source);
SortedKeyValueIterator<Key, Value> visFilter = VisibilityFilter.wrap(cfsi, authorizations, new byte[0]);
ReuseIterator reuserIter = new ReuseIterator();
reuserIter.init(visFilter, EMPTY_OPTS, null);
try {
titer = clazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
IteratorEnvironment iterEnv = EasyMock.createMock(IteratorEnvironment.class);
EasyMock.expect(iterEnv.getIteratorScope()).andReturn(IteratorScope.scan).anyTimes();
EasyMock.replay(iterEnv);
Map<String, String> opts;
if (setupAuths) {
IteratorSetting cfg = new IteratorSetting(21, clazz);
TransformingIterator.setAuthorizations(cfg, new Authorizations("vis0", "vis1", "vis2", "vis3"));
opts = cfg.getOptions();
} else {
opts = ImmutableMap.of();
}
titer.init(reuserIter, opts, iterEnv);
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class VersioningIteratorTest method test5.
@Test
public void test5() 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);
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);
assertTrue(it.hasTop());
assertTrue(it.getTopKey().getTimestamp() == 18);
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class VersioningIteratorTest method test4.
@Test
public void test4() {
Text colf = new Text("a");
Text colq = new Text("b");
TreeMap<Key, Value> tm = new TreeMap<>();
createTestData(tm, colf, colq);
for (int i = 1; i <= 30; i++) {
try {
VersioningIterator it = new VersioningIterator();
IteratorSetting is = new IteratorSetting(1, VersioningIterator.class);
VersioningIterator.setMaxVersions(is, i);
it.init(new SortedMapIterator(tm), is.getOptions(), null);
it.seek(new Range(), EMPTY_COL_FAMS, false);
TreeMap<Key, Value> tmOut = iteratorOverTestData(it);
assertTrue("size after keeping " + i + " versions was " + tmOut.size(), tmOut.size() == Math.min(40, 2 * i));
} catch (IOException e) {
assertFalse(true);
} catch (Exception e) {
log.error("{}", e.getMessage(), e);
assertFalse(true);
}
}
}
use of org.apache.accumulo.core.iterators.SortedMapIterator in project accumulo by apache.
the class VisibilityFilterTest method verify.
private void verify(TreeMap<Key, Value> source, int expectedSourceSize, Map<String, String> options, Text expectedCF, Text expectedCQ, Text expectedCV, int expectedFinalCount) throws IOException {
assertEquals(expectedSourceSize, source.size());
Filter filter = new VisibilityFilter();
filter.init(new SortedMapIterator(source), options, null);
filter.seek(new Range(), EMPTY_COL_FAMS, false);
int count = 0;
while (filter.hasTop()) {
count++;
// System.out.println(DefaultFormatter.formatEntry(Collections.singletonMap(filter.getTopKey(), filter.getTopValue()).entrySet().iterator().next(),
// false));
assertEquals(expectedCF, filter.getTopKey().getColumnFamily());
assertEquals(expectedCQ, filter.getTopKey().getColumnQualifier());
assertEquals(expectedCV, filter.getTopKey().getColumnVisibility());
filter.next();
}
assertEquals(expectedFinalCount, count);
}
Aggregations