Search in sources :

Example 1 with ClientReliableTopicProxy

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);
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Message(com.hazelcast.topic.Message) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) ClientProperty(com.hazelcast.client.properties.ClientProperty) HazelcastTestSupport.smallInstanceConfig(com.hazelcast.test.HazelcastTestSupport.smallInstanceConfig) ClientReliableTopicProxy(com.hazelcast.client.impl.proxy.ClientReliableTopicProxy) DurableMessageListener(com.hazelcast.topic.impl.reliable.DurableSubscriptionTest.DurableMessageListener) After(org.junit.After) HazelcastTestSupport.assertOpenEventually(com.hazelcast.test.HazelcastTestSupport.assertOpenEventually) ClientConfig(com.hazelcast.client.config.ClientConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ITopic(com.hazelcast.topic.ITopic) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastTestSupport.assertTrueEventually(com.hazelcast.test.HazelcastTestSupport.assertTrueEventually) Test(org.junit.Test) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) TestCase.assertEquals(junit.framework.TestCase.assertEquals) AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientReliableTopicProxy(com.hazelcast.client.impl.proxy.ClientReliableTopicProxy) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with ClientReliableTopicProxy

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();
}
Also used : ProxyFactoryConfig(com.hazelcast.client.config.ProxyFactoryConfig) ClientCacheProxyFactory(com.hazelcast.client.cache.impl.ClientCacheProxyFactory) ClientReliableTopicProxy(com.hazelcast.client.impl.proxy.ClientReliableTopicProxy) MultiMapService(com.hazelcast.multimap.impl.MultiMapService) ReplicatedMapService(com.hazelcast.replicatedmap.impl.ReplicatedMapService) MapService(com.hazelcast.map.impl.MapService) HazelcastException(com.hazelcast.core.HazelcastException) ClientServiceNotFoundException(com.hazelcast.client.impl.spi.impl.ClientServiceNotFoundException)

Example 3 with ClientReliableTopicProxy

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));
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Message(com.hazelcast.topic.Message) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) ClientProperty(com.hazelcast.client.properties.ClientProperty) HazelcastTestSupport.smallInstanceConfig(com.hazelcast.test.HazelcastTestSupport.smallInstanceConfig) ClientReliableTopicProxy(com.hazelcast.client.impl.proxy.ClientReliableTopicProxy) DurableMessageListener(com.hazelcast.topic.impl.reliable.DurableSubscriptionTest.DurableMessageListener) After(org.junit.After) HazelcastTestSupport.assertOpenEventually(com.hazelcast.test.HazelcastTestSupport.assertOpenEventually) ClientConfig(com.hazelcast.client.config.ClientConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ITopic(com.hazelcast.topic.ITopic) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastTestSupport.assertTrueEventually(com.hazelcast.test.HazelcastTestSupport.assertTrueEventually) Test(org.junit.Test) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) TestCase.assertEquals(junit.framework.TestCase.assertEquals) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientReliableTopicProxy(com.hazelcast.client.impl.proxy.ClientReliableTopicProxy) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with ClientReliableTopicProxy

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());
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) Message(com.hazelcast.topic.Message) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) ClientProperty(com.hazelcast.client.properties.ClientProperty) HazelcastTestSupport.smallInstanceConfig(com.hazelcast.test.HazelcastTestSupport.smallInstanceConfig) ClientReliableTopicProxy(com.hazelcast.client.impl.proxy.ClientReliableTopicProxy) DurableMessageListener(com.hazelcast.topic.impl.reliable.DurableSubscriptionTest.DurableMessageListener) After(org.junit.After) HazelcastTestSupport.assertOpenEventually(com.hazelcast.test.HazelcastTestSupport.assertOpenEventually) ClientConfig(com.hazelcast.client.config.ClientConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ITopic(com.hazelcast.topic.ITopic) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastTestSupport.assertTrueEventually(com.hazelcast.test.HazelcastTestSupport.assertTrueEventually) Test(org.junit.Test) UUID(java.util.UUID) Category(org.junit.experimental.categories.Category) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) TestCase.assertEquals(junit.framework.TestCase.assertEquals) AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastTestSupport.smallInstanceConfig(com.hazelcast.test.HazelcastTestSupport.smallInstanceConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) ClientReliableTopicProxy(com.hazelcast.client.impl.proxy.ClientReliableTopicProxy) ClientConfig(com.hazelcast.client.config.ClientConfig) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientReliableTopicProxy (com.hazelcast.client.impl.proxy.ClientReliableTopicProxy)4 ClientConfig (com.hazelcast.client.config.ClientConfig)3 ClientProperty (com.hazelcast.client.properties.ClientProperty)3 TestHazelcastFactory (com.hazelcast.client.test.TestHazelcastFactory)3 Config (com.hazelcast.config.Config)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)3 HazelcastTestSupport.assertOpenEventually (com.hazelcast.test.HazelcastTestSupport.assertOpenEventually)3 HazelcastTestSupport.assertTrueEventually (com.hazelcast.test.HazelcastTestSupport.assertTrueEventually)3 HazelcastTestSupport.smallInstanceConfig (com.hazelcast.test.HazelcastTestSupport.smallInstanceConfig)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 ITopic (com.hazelcast.topic.ITopic)3 Message (com.hazelcast.topic.Message)3 DurableMessageListener (com.hazelcast.topic.impl.reliable.DurableSubscriptionTest.DurableMessageListener)3 UUID (java.util.UUID)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 TimeUnit (java.util.concurrent.TimeUnit)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Consumer (java.util.function.Consumer)3