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


##########
test/src/main/java/org/apache/accumulo/test/TableOperationsIT.java:
##########
@@ -202,6 +205,64 @@ public void createTable() throws TableExistsException, 
AccumuloException,
     accumuloClient.tableOperations().delete(tableName);
   }
 
+  @Test
+  public void testDefendAgainstThreadsCreateSameTableNameConcurrently()
+      throws ExecutionException, InterruptedException {
+
+    final int numTasks = 10;
+    ExecutorService pool = Executors.newFixedThreadPool(numTasks);
+
+    for (String tablename : getUniqueNames(30)) {
+      CountDownLatch startSignal = new CountDownLatch(1);
+      CountDownLatch doneSignal = new CountDownLatch(numTasks);
+      AtomicInteger numTasksRunning = new AtomicInteger(0);
+
+      List<Future<Boolean>> futureList = new ArrayList<>();
+
+      for (int j = 0; j < numTasks; j++) {
+        Future<Boolean> future = pool.submit(() -> {
+          boolean result;
+          try {
+            numTasksRunning.incrementAndGet();
+            startSignal.await();
+            accumuloClient.tableOperations().create(tablename);
+            result = true;
+          } catch (TableExistsException e) {
+            result = false;
+          } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            result = false;
+          } finally {
+            doneSignal.countDown();
+          }
+          return result;
+        });
+        futureList.add(future);
+      }
+
+      Wait.waitFor(() -> numTasksRunning.get() == numTasks);
+
+      startSignal.countDown();
+
+      doneSignal.await();

Review Comment:
   doneSignal seems redundant w/ calling future.get() which will block until 
the future is done, so could probably remove this variable.  Calling 
future.get() on all futures will wait till all of them are done.  



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