Github user wy96f commented on the issue:
https://github.com/apache/activemq-artemis/pull/1851
Sorry for the late reply. Using lazySet to update capacity filed is a good
point. As for the test, I modified test as follows:
@Test
public void concurrentInsertionsAndReads() throws Throwable {
ExecutorService executor = Executors.newCachedThreadPool();
for (int x = 0; x < 1000; x++) {
ConcurrentLongHashMap<String> map = new ConcurrentLongHashMap<>(1,
1);
final int nThreads = 16;
final int N = 100_000;
String value = "v";
List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < nThreads; i++) {
futures.add(executor.submit(() -> {
Random random = new Random();
for (int j = 0; j < N; j++) {
long key = random.nextLong();
// Ensure keys are uniques
//key -= key % (threadIdx + 1);
map.get(key);
}
}));
final int threadIdx = i;
futures.add(executor.submit(() -> {
Random random = new Random();
for (int j = 0; j < N; j++) {
long key = random.nextLong();
// Ensure keys are uniques
key -= key % (threadIdx + 1);
map.put(key, value);
}
}));
}
for (Future<?> future : futures) {
future.get();
}
assertEquals(map.size(), N * nThreads);
}
executor.shutdown();
}
Most likely, npe would occur. The test may cost a long time to trigger the
bug. Is it ok to run the test for such a long time in the junit test?
---