use of com.hazelcast.flakeidgen.FlakeIdGenerator in project hazelcast by hazelcast.
the class FlakeIdGenerator_ClientIntegrationTest method configTest.
@Test
public void configTest() throws Exception {
int myBatchSize = 3;
ClientFlakeIdGeneratorConfig clientFlakeIdGeneratorConfig = new ClientFlakeIdGeneratorConfig("gen").setPrefetchCount(myBatchSize).setPrefetchValidityMillis(3000);
before(new ClientConfig().addFlakeIdGeneratorConfig(clientFlakeIdGeneratorConfig));
final FlakeIdGenerator generator = instance.getFlakeIdGenerator("gen");
assertTrue("This test assumes default validity be larger than 3000 by a good margin", FlakeIdGeneratorConfig.DEFAULT_PREFETCH_VALIDITY_MILLIS >= 5000);
// this should take a batch of 3 IDs from the member and store it in the auto-batcher
long id1 = generator.newId();
// this should take second ID from auto-created batch. It should be exactly next to id1
long id2 = generator.newId();
long increment = 1 << DEFAULT_BITS_NODE_ID;
assertEquals(id1 + increment, id2);
Thread.sleep(3000);
// this ID should be from a new batch, because the validity elapsed
long id3 = generator.newId();
assertTrue(id1 + increment * myBatchSize < id3);
}
use of com.hazelcast.flakeidgen.FlakeIdGenerator in project hazelcast by hazelcast.
the class FlakeIdGenerator_ClientIntegrationTest method smokeTest.
@Test
public void smokeTest() throws Exception {
before(null);
final FlakeIdGenerator generator = instance.getFlakeIdGenerator("gen");
FlakeIdConcurrencyTestUtil.concurrentlyGenerateIds(generator::newId);
}
use of com.hazelcast.flakeidgen.FlakeIdGenerator in project hazelcast by hazelcast.
the class DistributedDatastructuresMetricsTest method testFlakeIdGenerator.
@Test
public void testFlakeIdGenerator() {
final FlakeIdGenerator idGenerator = hz.getFlakeIdGenerator(FLAKE_ID_GENERATOR_NAME);
final FlakeIdGenerator idGeneratorNoStat = hz.getFlakeIdGenerator(FLAKE_ID_GENERATOR_NAME_NO_STAT);
for (int i = 0; i < EVENT_COUNTER; i++) {
idGenerator.newId();
idGeneratorNoStat.newId();
}
assertHasStatsEventually(FLAKE_ID_GENERATOR_NAME, "flakeIdGenerator.");
assertHasNoStats(FLAKE_ID_GENERATOR_NAME_NO_STAT, "flakeIdGenerator.");
}
use of com.hazelcast.flakeidgen.FlakeIdGenerator in project hazelcast by hazelcast.
the class FlakeIdGenerator_MemberIntegrationTest method smokeTest.
@Test
public void smokeTest() throws Exception {
HazelcastInstance instance = factory.newHazelcastInstance();
final FlakeIdGenerator generator = instance.getFlakeIdGenerator("gen");
FlakeIdConcurrencyTestUtil.concurrentlyGenerateIds(generator::newId);
}
use of com.hazelcast.flakeidgen.FlakeIdGenerator in project hazelcast by hazelcast.
the class FlakeIdGenerator_NodeIdOverflowIntegrationTest method when_allMembersOutOfRangeNodeId_then_error.
@Test
public void when_allMembersOutOfRangeNodeId_then_error() {
assignOutOfRangeNodeId(instance1);
assignOutOfRangeNodeId(instance2);
FlakeIdGenerator gen = instance1.getFlakeIdGenerator("gen");
exception.expect(HazelcastException.class);
exception.expectMessage("All members have node ID out of range");
gen.newId();
}
Aggregations