Search in sources :

Example 6 with FlakeIdGenerator

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);
}
Also used : ClientFlakeIdGeneratorConfig(com.hazelcast.client.config.ClientFlakeIdGeneratorConfig) FlakeIdGenerator(com.hazelcast.flakeidgen.FlakeIdGenerator) ClientConfig(com.hazelcast.client.config.ClientConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with FlakeIdGenerator

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);
}
Also used : FlakeIdGenerator(com.hazelcast.flakeidgen.FlakeIdGenerator) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with FlakeIdGenerator

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.");
}
Also used : FlakeIdGenerator(com.hazelcast.flakeidgen.FlakeIdGenerator) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with 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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) FlakeIdGenerator(com.hazelcast.flakeidgen.FlakeIdGenerator) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with FlakeIdGenerator

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();
}
Also used : FlakeIdGenerator(com.hazelcast.flakeidgen.FlakeIdGenerator) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

FlakeIdGenerator (com.hazelcast.flakeidgen.FlakeIdGenerator)10 Test (org.junit.Test)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ClientConfig (com.hazelcast.client.config.ClientConfig)2 ClientFlakeIdGeneratorConfig (com.hazelcast.client.config.ClientFlakeIdGeneratorConfig)1 LocalFlakeIdGeneratorStats (com.hazelcast.internal.monitor.LocalFlakeIdGeneratorStats)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1