use of com.hazelcast.client.impl.proxy.ClientReliableTopicProxy in project hazelcast by hazelcast.
the class ClientReliableTopicOnClusterRestartTest method shouldContinue_OnClusterRestart_whenDataLoss_LossTolerant_afterInvocationTimeout.
@Test
public void shouldContinue_OnClusterRestart_whenDataLoss_LossTolerant_afterInvocationTimeout() throws InterruptedException {
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
int invocationTimeoutSeconds = 2;
clientConfig.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), String.valueOf(invocationTimeoutSeconds));
final HazelcastInstance member = hazelcastFactory.newHazelcastInstance(smallInstanceConfig());
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
AtomicLong messageCount = new AtomicLong();
CountDownLatch messageArrived = new CountDownLatch(1);
String topicName = "topic";
member.getReliableTopic(topicName).publish("message");
member.getReliableTopic(topicName).publish("message");
ClientReliableTopicProxy<?> topic = (ClientReliableTopicProxy<?>) client.getReliableTopic(topicName);
UUID registrationId = topic.addMessageListener(createListener(true, m -> {
messageCount.incrementAndGet();
messageArrived.countDown();
}));
member.shutdown();
final HazelcastInstance restartedMember = hazelcastFactory.newHazelcastInstance(smallInstanceConfig());
// wait some time for subscription
Thread.sleep(TimeUnit.SECONDS.toMillis(invocationTimeoutSeconds));
assertTrueEventually(() -> {
String item = "newItem " + UUID.randomUUID();
restartedMember.getReliableTopic(topicName).publish(item);
assertOpenEventually(messageArrived, 5);
});
assertFalse(topic.isListenerCancelled(registrationId));
assertTrue(messageCount.get() >= 1);
}
use of com.hazelcast.client.impl.proxy.ClientReliableTopicProxy in project hazelcast by hazelcast.
the class ProxyManager method init.
@SuppressWarnings("checkstyle:methodlength")
public void init(ClientConfig config, ClientContext clientContext) {
context = clientContext;
// register defaults
register(MapService.SERVICE_NAME, createServiceProxyFactory(MapService.class));
if (JCacheDetector.isJCacheAvailable(config.getClassLoader())) {
register(ICacheService.SERVICE_NAME, new ClientCacheProxyFactory(client));
}
register(QueueService.SERVICE_NAME, ClientQueueProxy.class);
register(MultiMapService.SERVICE_NAME, ClientMultiMapProxy.class);
register(ListService.SERVICE_NAME, ClientListProxy.class);
register(SetService.SERVICE_NAME, ClientSetProxy.class);
register(TopicService.SERVICE_NAME, ClientTopicProxy.class);
register(DistributedExecutorService.SERVICE_NAME, ClientExecutorServiceProxy.class);
register(DistributedDurableExecutorService.SERVICE_NAME, ClientDurableExecutorServiceProxy.class);
register(ReplicatedMapService.SERVICE_NAME, ClientReplicatedMapProxy.class);
register(XAService.SERVICE_NAME, XAResourceProxy.class);
register(RingbufferService.SERVICE_NAME, ClientRingbufferProxy.class);
register(ReliableTopicService.SERVICE_NAME, (id, context) -> new ClientReliableTopicProxy(id, context, client));
register(FlakeIdGeneratorService.SERVICE_NAME, ClientFlakeIdGeneratorProxy.class);
register(CardinalityEstimatorService.SERVICE_NAME, ClientCardinalityEstimatorProxy.class);
register(DistributedScheduledExecutorService.SERVICE_NAME, ClientScheduledExecutorProxy.class);
register(PNCounterService.SERVICE_NAME, ClientPNCounterProxy.class);
register(LongRegisterService.SERVICE_NAME, ClientLongRegisterProxy.class);
ClassLoader classLoader = config.getClassLoader();
for (ProxyFactoryConfig proxyFactoryConfig : config.getProxyFactoryConfigs()) {
try {
ClientProxyFactory clientProxyFactory = proxyFactoryConfig.getFactoryImpl();
if (clientProxyFactory == null) {
String className = proxyFactoryConfig.getClassName();
clientProxyFactory = ClassLoaderUtil.newInstance(classLoader, className);
}
register(proxyFactoryConfig.getService(), clientProxyFactory);
} catch (Exception e) {
throw rethrow(e);
}
}
readProxyDescriptors();
}
use of com.hazelcast.client.impl.proxy.ClientReliableTopicProxy in project hazelcast by hazelcast.
the class ClientReliableTopicOnClusterRestartTest method shouldContinue_OnClusterRestart_afterInvocationTimeout.
@Test
public void shouldContinue_OnClusterRestart_afterInvocationTimeout() throws InterruptedException {
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(smallInstanceConfig());
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
int invocationTimeoutSeconds = 2;
clientConfig.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), String.valueOf(invocationTimeoutSeconds));
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final CountDownLatch messageArrived = new CountDownLatch(1);
String topicName = "topic";
ITopic<String> topic = client.getReliableTopic(topicName);
UUID registrationId = topic.addMessageListener(createListener(true, m -> messageArrived.countDown()));
member.shutdown();
// wait for the topic operation to timeout
Thread.sleep(TimeUnit.SECONDS.toMillis(invocationTimeoutSeconds));
member = hazelcastFactory.newHazelcastInstance(smallInstanceConfig());
member.getReliableTopic(topicName).publish("message");
assertOpenEventually(messageArrived);
ClientReliableTopicProxy<?> proxy = (ClientReliableTopicProxy<?>) topic;
assertFalse(proxy.isListenerCancelled(registrationId));
}
use of com.hazelcast.client.impl.proxy.ClientReliableTopicProxy in project hazelcast by hazelcast.
the class ClientReliableTopicOnClusterRestartTest method shouldFail_OnClusterRestart_whenDataLoss_notLossTolerant.
@Test
public void shouldFail_OnClusterRestart_whenDataLoss_notLossTolerant() {
Config config = smallInstanceConfig();
String topicName = "topic";
config.getRingbufferConfig(topicName).setCapacity(10);
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
AtomicLong messageCount = new AtomicLong();
// initialises listener seq up to 10000
for (int i = 0; i < 10_000; i++) {
member.getReliableTopic(topicName).publish("message");
}
ITopic<String> topic = client.getReliableTopic(topicName);
UUID registrationId = topic.addMessageListener(createListener(false, m -> messageCount.incrementAndGet()));
member.shutdown();
member = hazelcastFactory.newHazelcastInstance(config);
HazelcastInstance finalMember = member;
assertTrueEventually(() -> {
// we require at least one new message to detect that the ringbuffer was recreated
finalMember.getReliableTopic(topicName).publish("message");
ClientReliableTopicProxy<?> proxy = (ClientReliableTopicProxy<?>) topic;
assertTrue(proxy.isListenerCancelled(registrationId));
});
assertEquals(0, messageCount.get());
}
Aggregations