Search in sources :

Example 1 with IdGenerator

use of com.hazelcast.core.IdGenerator in project hazelcast by hazelcast.

the class IdGeneratorAbstractTest method testInit.

private void testInit(int initialValue, boolean expected, long expectedValue) {
    IdGenerator idGenerator = newInstance();
    boolean initialized = idGenerator.init(initialValue);
    assertEquals(expected, initialized);
    long newId = idGenerator.newId();
    assertEquals(expectedValue, newId);
}
Also used : IdGenerator(com.hazelcast.core.IdGenerator)

Example 2 with IdGenerator

use of com.hazelcast.core.IdGenerator in project hazelcast by hazelcast.

the class IdGeneratorProxyTest method assertNewIdAfterInit.

private static void assertNewIdAfterInit(int initialValue) {
    IdGenerator idGenerator = createIdGenerator();
    assertTrue(idGenerator.init(initialValue));
    assertEquals(initialValue + 1, idGenerator.newId());
}
Also used : IdGenerator(com.hazelcast.core.IdGenerator)

Example 3 with IdGenerator

use of com.hazelcast.core.IdGenerator 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)

Example 4 with IdGenerator

use of com.hazelcast.core.IdGenerator in project hazelcast by hazelcast.

the class PartitionControlledIdTest method testIdGenerator.

@Test
public void testIdGenerator() throws Exception {
    String partitionKey = "hazelcast";
    HazelcastInstance hz = getHazelcastInstance(partitionKey);
    IdGenerator idGenerator = hz.getIdGenerator("idgenerator@" + partitionKey);
    idGenerator.newId();
    assertEquals("idgenerator@" + partitionKey, idGenerator.getName());
    assertEquals(partitionKey, idGenerator.getPartitionKey());
    AtomicLongService service = getNodeEngine(hz).getService(AtomicLongService.SERVICE_NAME);
    assertTrue(service.containsAtomicLong("hz:atomic:idGenerator:" + idGenerator.getName()));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicLongService(com.hazelcast.concurrent.atomiclong.AtomicLongService) IdGenerator(com.hazelcast.core.IdGenerator) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with IdGenerator

use of com.hazelcast.core.IdGenerator in project hazelcast by hazelcast.

the class HazelcastOSGiInstanceTest method getIdGeneratorCalledSuccessfullyOverOSGiInstance.

@Test
public void getIdGeneratorCalledSuccessfullyOverOSGiInstance() {
    IdGenerator mockIdGenerator = mock(IdGenerator.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = HazelcastOSGiTestUtil.createHazelcastOSGiInstance(mockHazelcastInstance);
    when(mockHazelcastInstance.getIdGenerator("my-idgenerator")).thenReturn(mockIdGenerator);
    assertEquals(mockIdGenerator, hazelcastOSGiInstance.getIdGenerator("my-idgenerator"));
    verify(mockHazelcastInstance).getIdGenerator("my-idgenerator");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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)6 Test (org.junit.Test)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 AtomicLongService (com.hazelcast.concurrent.atomiclong.AtomicLongService)1 LongHashSet (com.hazelcast.util.collection.LongHashSet)1 ArrayList (java.util.ArrayList)1 Future (java.util.concurrent.Future)1