Skip to content

Commit

Permalink
Addressed andrross's comment
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Alfonsi <[email protected]>
  • Loading branch information
Peter Alfonsi committed Jun 20, 2024
1 parent 406f8e2 commit 32e87e4
Showing 1 changed file with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Phaser;

public class DefaultCacheStatsHolderTests extends OpenSearchTestCase {
private final String storeName = "dummy_store";
Expand Down Expand Up @@ -150,27 +149,17 @@ public void testConcurrentRemoval() throws Exception {
// and reflect only the stats for their B1 child.

Thread[] threads = new Thread[numAValues + 1];
CountDownLatch countDownLatch = new CountDownLatch(numAValues + 1);
Phaser phaser = new Phaser(numAValues + 2);
for (int i = 0; i < numAValues; i++) {
int finalI = i;
threads[i] = new Thread(() -> {
phaser.arriveAndAwaitAdvance();
cacheStatsHolder.removeDimensions(List.of("A" + finalI, "B0"));
countDownLatch.countDown();
});
threads[i] = new Thread(() -> { cacheStatsHolder.removeDimensions(List.of("A" + finalI, "B0")); });
}
threads[numAValues] = new Thread(() -> {
phaser.arriveAndAwaitAdvance();
cacheStatsHolder.removeDimensions(List.of("A0", "B1"));
countDownLatch.countDown();
});
threads[numAValues] = new Thread(() -> { cacheStatsHolder.removeDimensions(List.of("A0", "B1")); });
for (Thread thread : threads) {
thread.start();
}

phaser.arriveAndAwaitAdvance();
countDownLatch.await();
for (Thread thread : threads) {
thread.join();
}

// intermediate node for A0 should be null
assertNull(getNode(List.of("A0"), cacheStatsHolder.getStatsRoot()));
Expand Down

0 comments on commit 32e87e4

Please sign in to comment.