keith-turner commented on code in PR #4051:
URL: https://github.com/apache/accumulo/pull/4051#discussion_r1422937213


##########
test/src/main/java/org/apache/accumulo/test/ScanConsistencyIT.java:
##########
@@ -150,75 +147,77 @@ private static void runTest(AccumuloClient client, 
FileSystem fileSystem, String
     // getClusterControl().stopAllServers(ServerType.GARBAGE_COLLECTOR);
 
     var executor = Executors.newCachedThreadPool();
-    client.tableOperations().create(table);
+    try {
+      client.tableOperations().create(table);
 
-    TestContext testContext = new TestContext(client, table, fileSystem, 
tmpDir);
+      TestContext testContext = new TestContext(client, table, fileSystem, 
tmpDir);
 
-    List<Future<WriteStats>> writeTasks = new ArrayList<>();
-    List<Future<ScanStats>> scanTasks = new ArrayList<>();
+      List<Future<WriteStats>> writeTasks = new ArrayList<>();
+      List<Future<ScanStats>> scanTasks = new ArrayList<>();
 
-    Random random = new Random();
-
-    int numWriteTask = random.nextInt(10) + 1;
-    int numsScanTask = random.nextInt(10) + 1;
-
-    for (int i = 0; i < numWriteTask; i++) {
-      writeTasks.add(executor.submit(new WriteTask(testContext)));
-    }
+      Random random = new Random();
 
-    for (int i = 0; i < numsScanTask; i++) {
-      scanTasks.add(executor.submit(new ScanTask(testContext)));
-    }
+      int numWriteTask = random.nextInt(10) + 1;
+      int numsScanTask = random.nextInt(10) + 1;
 
-    var tableOpsTask = executor.submit(new TableOpsTask(testContext));
+      for (int i = 0; i < numWriteTask; i++) {
+        writeTasks.add(executor.submit(new WriteTask(testContext)));
+      }
 
-    // let the concurrent mayhem run for a bit
-    Thread.sleep(60000);
+      for (int i = 0; i < numsScanTask; i++) {
+        scanTasks.add(executor.submit(new ScanTask(testContext)));
+      }
 
-    // let the threads know to exit
-    testContext.keepRunning.set(false);
+      var tableOpsTask = executor.submit(new TableOpsTask(testContext));
 
-    for (Future<WriteStats> writeTask : writeTasks) {
-      var stats = writeTask.get();
-      log.debug(String.format("Wrote:%,d Bulk imported:%,d Deleted:%,d Bulk 
deleted:%,d",
-          stats.written, stats.bulkImported, stats.deleted, 
stats.bulkDeleted));
-      checkTrue(stats.written + stats.bulkImported > 0);
-      checkTrue(stats.deleted + stats.bulkDeleted > 0);
-    }
+      // let the concurrent mayhem run for a bit
+      Thread.sleep(60000);
 
-    for (Future<ScanStats> scanTask : scanTasks) {
-      var stats = scanTask.get();
-      log.debug(String.format("Scanned:%,d verified:%,d", stats.scanned, 
stats.verified));
-      checkTrue(stats.verified > 0);
-      // These scans were running concurrently with writes, so a scan will see 
more data than what
-      // was written before the scan started.
-      checkTrue(stats.scanned > stats.verified);
-    }
+      // let the threads know to exit
+      testContext.keepRunning.set(false);
 
-    log.debug(tableOpsTask.get());
+      for (Future<WriteStats> writeTask : writeTasks) {
+        var stats = writeTask.get();
+        log.debug(String.format("Wrote:%,d Bulk imported:%,d Deleted:%,d Bulk 
deleted:%,d",
+            stats.written, stats.bulkImported, stats.deleted, 
stats.bulkDeleted));
+        checkTrue(stats.written + stats.bulkImported > 0);
+        checkTrue(stats.deleted + stats.bulkDeleted > 0);
+      }
 
-    var stats1 = scanData(testContext, random, new Range(), false);
-    var stats2 = scanData(testContext, random, new Range(), true);
-    var stats3 = batchScanData(testContext, new Range());
-    log.debug(
-        String.format("Final scan, scanned:%,d verified:%,d", stats1.scanned, 
stats1.verified));
-    checkTrue(stats1.verified > 0);
-    // Should see all expected data now that there are no concurrent writes 
happening
-    checkEquals(stats1.scanned, stats1.verified);
-    checkEquals(stats2.scanned, stats1.scanned);
-    checkEquals(stats2.verified, stats1.verified);
-    checkEquals(stats3.scanned, stats1.scanned);
-    checkEquals(stats3.verified, stats1.verified);
+      for (Future<ScanStats> scanTask : scanTasks) {
+        var stats = scanTask.get();
+        log.debug(String.format("Scanned:%,d verified:%,d", stats.scanned, 
stats.verified));
+        checkTrue(stats.verified > 0);
+        // These scans were running concurrently with writes, so a scan will 
see more data than what
+        // was written before the scan started.
+        checkTrue(stats.scanned > stats.verified);
+      }
 
-    executor.shutdownNow();
+      log.debug(tableOpsTask.get());
+
+      var stats1 = scanData(testContext, random, new Range(), false);
+      var stats2 = scanData(testContext, random, new Range(), true);
+      var stats3 = batchScanData(testContext, new Range());
+      log.debug(
+          String.format("Final scan, scanned:%,d verified:%,d", 
stats1.scanned, stats1.verified));
+      checkTrue(stats1.verified > 0);
+      // Should see all expected data now that there are no concurrent writes 
happening
+      checkEquals(stats1.scanned, stats1.verified);
+      checkEquals(stats2.scanned, stats1.scanned);
+      checkEquals(stats2.verified, stats1.verified);
+      checkEquals(stats3.scanned, stats1.scanned);
+      checkEquals(stats3.verified, stats1.verified);
+    } finally {
+      executor.shutdownNow();
+      client.tableOperations().delete(table);

Review Comment:
   Placing code in a finally block that may throw an exception is tricky.  I 
would not expected shutting down the executor throw an exception, but deleting 
the table might.  If code in the try block throws an exception and code in the 
finally block throws an exception, then the exception from the try block is 
lost.  Not sure of a good way to improve this though other than something like 
the following.
   
   ```
   try{
   
   } catch(Exception e) {
      // log here in case the finally block also throws an exception
       log.error(e.getMessage(),e);
       throw e;
   } finally {
      executor.shutdownNow();
      client.tableOperations().delete(table);
   }



-- 
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]

Reply via email to