keith-turner commented on code in PR #6075:
URL: https://github.com/apache/accumulo/pull/6075#discussion_r2722888007
##########
test/src/main/java/org/apache/accumulo/test/functional/ScanIteratorIT.java:
##########
@@ -250,4 +259,62 @@ private void writeTestMutation(AccumuloClient userC)
batchWriter.flush();
}
}
+
+ public static class AppendingIterator extends WrappingIterator {
+
+ private String append;
+
+ @Override
+ public void init(SortedKeyValueIterator<Key,Value> source,
Map<String,String> options,
+ IteratorEnvironment env) throws IOException {
+ super.init(source, options, env);
+ append = Objects.requireNonNull(options.get("append"));
+ }
+
+ @Override
+ public Value getTopValue() {
+ var val = super.getTopValue();
+ return new Value(val.toString() + append);
+ }
+
+ public static IteratorSetting configure(int prio, String append) {
+ IteratorSetting iter = new IteratorSetting(prio, "append_" + append,
AppendingIterator.class);
+ iter.addOption("append", append);
+ return iter;
+ }
+ }
+
+ // Ensures scan iterators run in the expected order
+ @Test
+ public void testIteratorOrder() throws Exception {
+
+ String tableName = getUniqueNames(2)[1];
+ try (AccumuloClient c =
Accumulo.newClient().from(getClientProps()).build()) {
+ var scopes = EnumSet.of(IteratorScope.scan);
+ NewTableConfiguration ntc =
+ new
NewTableConfiguration().attachIterator(AppendingIterator.configure(50, "x"),
scopes)
+ .attachIterator(AppendingIterator.configure(100, "a"), scopes);
+ c.tableOperations().create(tableName, ntc);
+
+ try (var writer = c.createBatchWriter(tableName)) {
+ Mutation m = new Mutation("r1");
+ m.put("", "", "base:");
+ writer.addMutation(m);
+ }
+
+ try (var scanner = c.createScanner(tableName)) {
+ assertEquals("base:xa",
scanner.iterator().next().getValue().toString());
+ scanner.addScanIterator(AppendingIterator.configure(70, "m"));
+ assertEquals("base:xma",
scanner.iterator().next().getValue().toString());
+ // These have the same priority as a table iterator so the iterators
should be ordered by
+ // their name in that case
+ scanner.addScanIterator(AppendingIterator.configure(50, "b"));
+ scanner.addScanIterator(AppendingIterator.configure(100, "c"));
+ assertEquals("base:bxmac",
scanner.iterator().next().getValue().toString());
+ // There are no compaction iterators, so this should not change value
+ c.tableOperations().compact(tableName, new
CompactionConfig().setWait(true));
+ assertEquals("base:bxmac",
scanner.iterator().next().getValue().toString());
+ }
Review Comment:
The merged iterators will have that. The table has iterators with name
`append_x`,50 and `append_a`,100. The scanner sets iterators with
`append_b`,50 and `append_c`,100.
Trying to make the scanner have that will throw an exception and that may be
covered by other test. For this test wanted to ensure the merged view had a
consistent order. Also I am not sure there is any test for the iterator order,
so this test also covers that basic case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]