ibilley7 commented on code in PR #5801:
URL: https://github.com/apache/accumulo/pull/5801#discussion_r2285790277
##########
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:
To do this I just tested that 30 tables were added to
`accumuloClient.tableOperations.list()`
##########
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:
To do this I just tested that 30 tables were added to
`accumuloClient.tableOperations().list()`
--
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]