You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/04/25 05:31:59 UTC
[GitHub] [accumulo] ctubbsii commented on a diff in pull request #2646: Replace iterator usage
ctubbsii commented on code in PR #2646:
URL: https://github.com/apache/accumulo/pull/2646#discussion_r857265707
##########
test/src/main/java/org/apache/accumulo/test/functional/RowDeleteIT.java:
##########
@@ -105,8 +106,7 @@ public void run() throws Exception {
}
try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY)) {
- count = Iterators.size(scanner.iterator());
- assertEquals(0, count, "count == " + count);
+ assertTrue(scanner.stream().findAny().isEmpty());
bw.close();
Review Comment:
Your change looks fine, but it looks like there's something weird with the existing `bw.close()`. It won't be closed if the assertion fails. The BatchWriter should be in a try-with-resources block of its own, wrapping this scanner block and other stuff above here. That way, it's always closed.
##########
test/src/main/java/org/apache/accumulo/test/mapreduce/AccumuloOutputFormatIT.java:
##########
@@ -164,11 +162,9 @@ public void testMR() throws Exception {
assertNull(e1);
try (Scanner scanner = c.createScanner(table2, new Authorizations())) {
- Iterator<Entry<Key,Value>> iter = scanner.iterator();
- assertTrue(iter.hasNext());
- Entry<Key,Value> entry = iter.next();
- assertEquals(Integer.parseInt(new String(entry.getValue().get())), 100);
- assertFalse(iter.hasNext());
+ int actual = scanner.stream().map(Entry::getValue).map(Value::get).map(String::new)
+ .map(Integer::parseInt).collect(onlyElement());
Review Comment:
It's slightly shorter if you just call parseInt on the only element (some suggestion applies elsewhere in this PR):
```suggestion
int actual = Integer.parseInt(scanner.stream().map(Entry::getValue).map(Value::get).map(String::new).collect(onlyElement()));
```
##########
test/src/main/java/org/apache/accumulo/test/mapred/AccumuloOutputFormatIT.java:
##########
@@ -233,11 +232,9 @@ public void testMR() throws Exception {
assertNull(e1);
try (Scanner scanner = c.createScanner(table2, new Authorizations())) {
- Iterator<Entry<Key,Value>> iter = scanner.iterator();
- assertTrue(iter.hasNext());
- Entry<Key,Value> entry = iter.next();
- assertEquals(Integer.parseInt(new String(entry.getValue().get())), 100);
- assertFalse(iter.hasNext());
+ int actual = scanner.stream().map(Entry::getValue).map(Value::get).map(String::new)
+ .map(Integer::parseInt).collect(onlyElement());
+ assertEquals(actual, 100);
Review Comment:
Expected should come first for the failure messages to be correct (saw this in several places throughout this PR).
```suggestion
assertEquals(100, actual);
```
--
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: notifications-unsubscribe@accumulo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org