kevinrr888 commented on code in PR #5801:
URL: https://github.com/apache/accumulo/pull/5801#discussion_r2279401133


##########
test/src/main/java/org/apache/accumulo/test/TableOperationsIT.java:
##########
@@ -202,6 +204,60 @@ public void createTable() throws TableExistsException, 
AccumuloException,
     accumuloClient.tableOperations().delete(tableName);
   }
 
+  @Test
+  public void testDefendAgainstThreadsCreateSameTableNameConcurrently()
+      throws ExecutionException, InterruptedException {
+
+    ExecutorService pool = Executors.newFixedThreadPool(64);
+
+    for (int i = 0; i < 30; i++) {
+      String tablename = "t" + i;
+      List<Future<String>> futureList = new ArrayList<>();
+
+      CountDownLatch startSignal = new CountDownLatch(1);
+      CountDownLatch doneSignal = new CountDownLatch(10);
+
+      for (int j = 0; j < 10; j++) {
+        Future<String> future = pool.submit(() -> {
+          String result;
+          try {
+            startSignal.await();
+            accumuloClient.tableOperations().create(tablename);
+            result = "success";
+          } catch (TableExistsException e) {
+            result = "fail";
+          } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+            result = "fail";
+          } finally {
+            doneSignal.countDown();
+          }
+          return result;
+        });
+        futureList.add(future);
+      }
+
+      startSignal.countDown();

Review Comment:
   We still don't know for sure that all threads have started work and are at 
the await() at this point of calling countDown(). I thought ExecutorService had 
a method to get the number of executing threads, but it doesn't seem that is 
correct, must be some specific impl of ExecutorService that I'm thinking of. 
So, instead could have an `AtomicInteger numTasksRunning` and increment it 
before the `await()` then after the loop, `Wait.waitFor(() -> 
numTasksRunning.get() == 10)`. Then can call `countDown()`
   
   Also would be good to put 10 in a var numTasks or similar since it is used 
throughout the test.



##########
test/src/main/java/org/apache/accumulo/test/TableOperationsIT.java:
##########
@@ -202,6 +204,60 @@ public void createTable() throws TableExistsException, 
AccumuloException,
     accumuloClient.tableOperations().delete(tableName);
   }
 
+  @Test
+  public void testDefendAgainstThreadsCreateSameTableNameConcurrently()
+      throws ExecutionException, InterruptedException {
+
+    ExecutorService pool = Executors.newFixedThreadPool(64);

Review Comment:
   No need for 64 threads since only executing 10 tasks, and those tasks are 
waited on before the next `i` iteration
   ```suggestion
       final int numTasks = 10;
       ExecutorService pool = Executors.newFixedThreadPool(numTasks);
   ```



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