ctubbsii commented on a change in pull request #341: ACCUMULO-3902 Ensure 
[Batch]Scanners are closed in ITs
URL: https://github.com/apache/accumulo/pull/341#discussion_r158128286
 
 

 ##########
 File path: 
test/src/main/java/org/apache/accumulo/test/BatchWriterInTabletServerIT.java
 ##########
 @@ -104,24 +104,34 @@ private void test(String t1, String t2, Connector c, 
IteratorSetting itset, int
     c.tableOperations().attachIterator(t2, summer);
 
     Map.Entry<Key,Value> actual;
-    // Scan t1 with an iterator that writes to table t2
-    Scanner scanner = c.createScanner(t1, Authorizations.EMPTY);
-    scanner.addScanIterator(itset);
-    actual = Iterators.getOnlyElement(scanner.iterator());
-    Assert.assertTrue(actual.getKey().equals(k, 
PartialKey.ROW_COLFAM_COLQUAL));
-    Assert.assertEquals(BatchWriterIterator.SUCCESS_VALUE, actual.getValue());
-    scanner.close();
+    Scanner scanner = null;
+    try {
+      // Scan t1 with an iterator that writes to table t2
+      scanner = c.createScanner(t1, Authorizations.EMPTY);
+      scanner.addScanIterator(itset);
+      actual = Iterators.getOnlyElement(scanner.iterator());
+      Assert.assertTrue(actual.getKey().equals(k, 
PartialKey.ROW_COLFAM_COLQUAL));
+      Assert.assertEquals(BatchWriterIterator.SUCCESS_VALUE, 
actual.getValue());
+    } finally {
+      if (scanner != null) {
+        scanner.close();
+      }
+    }
 
-    // ensure entries correctly wrote to table t2
-    scanner = c.createScanner(t2, Authorizations.EMPTY);
-    actual = Iterators.getOnlyElement(scanner.iterator());
-    log.debug("t2 entry is " + actual.getKey().toStringNoTime() + " -> " + 
actual.getValue());
-    Assert.assertTrue(actual.getKey().equals(k, 
PartialKey.ROW_COLFAM_COLQUAL));
-    Assert.assertEquals(numEntriesToWritePerEntry, 
Integer.parseInt(actual.getValue().toString()));
-    scanner.close();
+    try {
+      // ensure entries correctly wrote to table t2
+      scanner = c.createScanner(t2, Authorizations.EMPTY);
+      actual = Iterators.getOnlyElement(scanner.iterator());
+      log.debug("t2 entry is " + actual.getKey().toStringNoTime() + " -> " + 
actual.getValue());
+      Assert.assertTrue(actual.getKey().equals(k, 
PartialKey.ROW_COLFAM_COLQUAL));
+      Assert.assertEquals(numEntriesToWritePerEntry, 
Integer.parseInt(actual.getValue().toString()));
+    } finally {
+      if (scanner != null) {
+        scanner.close();
+      }
+    }
 
 Review comment:
   The two in this class can use try-with-resources also. It's okay that the 
variable will have to be declared twice instead of reused.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to