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