Search in sources :

Example 1 with ClientFlakeIdGeneratorConfig

use of com.hazelcast.client.config.ClientFlakeIdGeneratorConfig in project hazelcast by hazelcast.

the class ClientDomConfigProcessor method handleFlakeIdGeneratorNode.

protected void handleFlakeIdGeneratorNode(Node node) {
    String name = getName(node);
    ClientFlakeIdGeneratorConfig config = new ClientFlakeIdGeneratorConfig(name);
    for (Node child : childElements(node)) {
        String nodeName = cleanNodeName(child);
        if (matches("prefetch-count", nodeName)) {
            config.setPrefetchCount(Integer.parseInt(getTextContent(child)));
        } else if (matches("prefetch-validity-millis", lowerCaseInternal(nodeName))) {
            config.setPrefetchValidityMillis(Long.parseLong(getTextContent(child)));
        }
    }
    clientConfig.addFlakeIdGeneratorConfig(config);
}
Also used : ClientFlakeIdGeneratorConfig(com.hazelcast.client.config.ClientFlakeIdGeneratorConfig) Node(org.w3c.dom.Node)

Example 2 with ClientFlakeIdGeneratorConfig

use of com.hazelcast.client.config.ClientFlakeIdGeneratorConfig in project hazelcast by hazelcast.

the class FlakeIdGenerator_ClientBackpressureTest method before.

@Before
public void before() {
    factory = new TestHazelcastFactory(1);
    factory.newHazelcastInstance();
    instance = factory.newHazelcastClient(new ClientConfig().addFlakeIdGeneratorConfig(new ClientFlakeIdGeneratorConfig("gen").setPrefetchCount(BATCH_SIZE)));
}
Also used : ClientFlakeIdGeneratorConfig(com.hazelcast.client.config.ClientFlakeIdGeneratorConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ClientConfig(com.hazelcast.client.config.ClientConfig) Before(org.junit.Before)

Example 3 with ClientFlakeIdGeneratorConfig

use of com.hazelcast.client.config.ClientFlakeIdGeneratorConfig 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 4 with ClientFlakeIdGeneratorConfig

use of com.hazelcast.client.config.ClientFlakeIdGeneratorConfig in project hazelcast by hazelcast.

the class TestClientApplicationContext method testFlakeIdGeneratorConfig.

@Test
public void testFlakeIdGeneratorConfig() {
    Map<String, ClientFlakeIdGeneratorConfig> configMap = client10.getClientConfig().getFlakeIdGeneratorConfigMap();
    assertEquals(1, configMap.size());
    ClientFlakeIdGeneratorConfig config = configMap.values().iterator().next();
    assertEquals("gen1", config.getName());
    assertEquals(3, config.getPrefetchCount());
    assertEquals(3000L, config.getPrefetchValidityMillis());
}
Also used : ClientFlakeIdGeneratorConfig(com.hazelcast.client.config.ClientFlakeIdGeneratorConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientFlakeIdGeneratorConfig (com.hazelcast.client.config.ClientFlakeIdGeneratorConfig)4 ClientConfig (com.hazelcast.client.config.ClientConfig)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)1 FlakeIdGenerator (com.hazelcast.flakeidgen.FlakeIdGenerator)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 Before (org.junit.Before)1 Node (org.w3c.dom.Node)1