keith-turner commented on code in PR #5801: URL: https://github.com/apache/accumulo/pull/5801#discussion_r2285434295
########## 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; Review Comment: Seeing an interrupted exception is not an expected outcome when calling `create()` in this scenario, so should not let it pass. Should only see the table be created successfully or a TableExistsException being thrown. Any other exception should be allowed to propogate and cause `future.get()` to fail which should fail the test. ```suggestion ``` ########## 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(); + + int taskSucceeded = 0; + int taskFailed = 0; + for (Future<Boolean> result : futureList) { + if (result.get() == true) { + taskSucceeded++; + } else { + taskFailed++; + } + } + + assertEquals(1, taskSucceeded); + assertEquals(9, taskFailed); + } + Review Comment: Would be good to call `accumuloClient.tableOperations().list()` and ensure the returned set contains all of the tables created. -- 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-unsubscr...@accumulo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org