Search in sources :

Example 1 with LongHashSet

use of com.hazelcast.util.collection.LongHashSet in project hazelcast by hazelcast.

the class IdGeneratorStressTest method testMultipleThreads.

@Test
public void testMultipleThreads() throws ExecutionException, InterruptedException {
    pickIdGenerator().init(13013);
    List<Future> futureList = new ArrayList<Future>(THREAD_COUNT);
    for (int i = 0; i < THREAD_COUNT; i++) {
        IdGenerator idGenerator = pickIdGenerator();
        IdGeneratorCallable callable = new IdGeneratorCallable(idGenerator);
        Future<long[]> future = spawn(callable);
        futureList.add(future);
    }
    LongHashSet totalGeneratedIds = new LongHashSet(TOTAL_ID_GENERATED, -1);
    for (Future<long[]> future : futureList) {
        long[] generatedIds = future.get();
        for (long generatedId : generatedIds) {
            assertTrue("ID: " + generatedId, totalGeneratedIds.add(generatedId));
        }
    }
    assertEquals(TOTAL_ID_GENERATED, totalGeneratedIds.size());
}
Also used : LongHashSet(com.hazelcast.util.collection.LongHashSet) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IdGenerator(com.hazelcast.core.IdGenerator) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

IdGenerator (com.hazelcast.core.IdGenerator)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 LongHashSet (com.hazelcast.util.collection.LongHashSet)1 ArrayList (java.util.ArrayList)1 Future (java.util.concurrent.Future)1 Test (org.junit.Test)1