use of com.yahoo.pulsar.common.util.collections.ConcurrentOpenHashSet in project pulsar by yahoo.
the class ConcurrentOpenHashSetTest method concurrentInsertionsAndReads.
@Test
public void concurrentInsertionsAndReads() throws Throwable {
ConcurrentOpenHashSet<Long> map = new ConcurrentOpenHashSet<>();
ExecutorService executor = Executors.newCachedThreadPool();
final int nThreads = 16;
final int N = 100_000;
List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < nThreads; i++) {
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 unique
key -= key % (threadIdx + 1);
map.add(key);
}
}));
}
for (Future<?> future : futures) {
future.get();
}
assertEquals(map.size(), N * nThreads);
executor.shutdown();
}
use of com.yahoo.pulsar.common.util.collections.ConcurrentOpenHashSet in project pulsar by yahoo.
the class ConcurrentOpenHashSetTest method concurrentInsertions.
@Test
public void concurrentInsertions() throws Throwable {
ConcurrentOpenHashSet<Long> set = new ConcurrentOpenHashSet<>();
ExecutorService executor = Executors.newCachedThreadPool();
final int nThreads = 16;
final int N = 100_000;
List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < nThreads; i++) {
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 unique
key -= key % (threadIdx + 1);
set.add(key);
}
}));
}
for (Future<?> future : futures) {
future.get();
}
assertEquals(set.size(), N * nThreads);
executor.shutdown();
}
Aggregations