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);
}
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());
}
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());
}
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()));
}
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");
}
Aggregations