Search in sources :

Example 1 with HazelcastClientCachingProvider

use of com.hazelcast.client.cache.impl.HazelcastClientCachingProvider in project hazelcast by hazelcast.

the class CacheClientListenerTest method testEntryListenerUsingMemberConfig.

@Test
public void testEntryListenerUsingMemberConfig() {
    System.setProperty("hazelcast.config", "classpath:hazelcast-cache-entrylistener-test.xml");
    Hazelcast.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().addAddress("127.0.0.1");
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    Cache<String, String> cache = cacheManager.getCache("entrylistenertestcache");
    cache.put("foo", "bar");
    HazelcastInstance client2 = HazelcastClient.newHazelcastClient(clientConfig);
    HazelcastClientCachingProvider cachingProvider2 = createClientCachingProvider(client2);
    CacheManager cacheManager2 = cachingProvider2.getCacheManager();
    Cache<String, String> cache2 = cacheManager2.getCache("entrylistenertestcache");
    client.shutdown();
    // sleep enough so that the put entry is expired
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // Trigger expiry event
    cache2.get("foo");
    final CountDownLatch expiredLatch = ClientCacheEntryExpiredLatchCountdownListener.getExpiredLatch();
    assertCountEventually("The expired event should only be received one time", 1, expiredLatch, 3);
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals("Expired event is received more than once", 1, expiredLatch.getCount());
        }
    }, 3);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) CacheListenerTest(com.hazelcast.cache.CacheListenerTest)

Example 2 with HazelcastClientCachingProvider

use of com.hazelcast.client.cache.impl.HazelcastClientCachingProvider in project hazelcast by hazelcast.

the class ClientCacheCreationTest method createSingleCache_whenMemberDown_throwsOperationTimeoutException.

@Test(expected = OperationTimeoutException.class)
public void createSingleCache_whenMemberDown_throwsOperationTimeoutException() {
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    clientConfig.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), "2");
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    hazelcastInstance.shutdown();
    MutableConfiguration configuration = new MutableConfiguration();
    cacheManager.createCache("xmlCache", configuration);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) CacheManager(javax.cache.CacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheCreationTest(com.hazelcast.cache.CacheCreationTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 3 with HazelcastClientCachingProvider

use of com.hazelcast.client.cache.impl.HazelcastClientCachingProvider in project hazelcast by hazelcast.

the class ClientCacheCreationTest method createSingleCache_whenMemberBounce.

@Test
public void createSingleCache_whenMemberBounce() throws InterruptedException {
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    hazelcastInstance.shutdown();
    final CountDownLatch cacheCreated = new CountDownLatch(1);
    new Thread(new Runnable() {

        @Override
        public void run() {
            MutableConfiguration configuration = new MutableConfiguration();
            cacheManager.createCache("xmlCache", configuration);
            cacheCreated.countDown();
        }
    }).start();
    // leave some gap to let create cache to start and retry
    Thread.sleep(2000);
    Hazelcast.newHazelcastInstance();
    assertOpenEventually(cacheCreated);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) CacheManager(javax.cache.CacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) MutableConfiguration(javax.cache.configuration.MutableConfiguration) CacheCreationTest(com.hazelcast.cache.CacheCreationTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 4 with HazelcastClientCachingProvider

use of com.hazelcast.client.cache.impl.HazelcastClientCachingProvider in project hazelcast by hazelcast.

the class ClientCacheNearCacheCacheOnUpdateTest method newNearCachedCache.

private ICache<Integer, Integer> newNearCachedCache(NearCacheConfig.LocalUpdatePolicy localUpdatePolicy) {
    NearCacheConfig nearCacheConfig = getNearCacheConfig(localUpdatePolicy);
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    CachingProvider provider = new HazelcastClientCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    return cacheManager.createCache(DEFAULT_CACHE_NAME, newCacheConfig(InMemoryFormat.BINARY));
}
Also used : HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 5 with HazelcastClientCachingProvider

use of com.hazelcast.client.cache.impl.HazelcastClientCachingProvider in project hazelcast by hazelcast.

the class ClientCacheCreationTest method recreateCacheOnRestartedCluster_whenMaxConcurrentInvocationLow.

@Test
public void recreateCacheOnRestartedCluster_whenMaxConcurrentInvocationLow() {
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), "1");
    // disable metrics collection (the periodic send statistics task may interfere with the test)
    clientConfig.getMetricsConfig().setEnabled(false);
    // disable backup acknowledgements (the backup listener registration may interfere with the test)
    clientConfig.setBackupAckToClientEnabled(false);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    MutableConfiguration configuration = new MutableConfiguration();
    // ensure cache is created despite the low concurrent invocation limit
    assertTrueEventually(() -> {
        try {
            cacheManager.createCache("xmlCache", configuration);
        } catch (HazelcastOverloadException e) {
            throw new AssertionError("Could not create cache due to " + "low concurrent invocation count.");
        }
    });
    IExecutorService executorService = client.getExecutorService("exec");
    // keep the slot for one invocation to test if client can reconnect even if all slots are kept
    CountDownLatch testFinished = new CountDownLatch(1);
    executorService.submit(new ExecutorServiceTestSupport.SleepingTask(0), new ExecutionCallback<Boolean>() {

        @Override
        public void onResponse(Boolean response) {
            try {
                testFinished.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(Throwable t) {
            try {
                testFinished.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    hazelcastInstance.shutdown();
    HazelcastInstance instance = Hazelcast.newHazelcastInstance();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            try {
                instance.getCacheManager().getCache("xmlCache");
            } catch (Exception e) {
                fail();
            }
        }
    });
    testFinished.countDown();
}
Also used : HazelcastOverloadException(com.hazelcast.core.HazelcastOverloadException) ExecutorServiceTestSupport(com.hazelcast.executor.ExecutorServiceTestSupport) IExecutorService(com.hazelcast.core.IExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) MutableConfiguration(javax.cache.configuration.MutableConfiguration) HazelcastOverloadException(com.hazelcast.core.HazelcastOverloadException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) CacheCreationTest(com.hazelcast.cache.CacheCreationTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)6 ClientConfig (com.hazelcast.client.config.ClientConfig)5 CacheManager (javax.cache.CacheManager)5 Test (org.junit.Test)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 CacheCreationTest (com.hazelcast.cache.CacheCreationTest)3 SlowTest (com.hazelcast.test.annotation.SlowTest)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 MutableConfiguration (javax.cache.configuration.MutableConfiguration)3 AssertTask (com.hazelcast.test.AssertTask)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 CacheListenerTest (com.hazelcast.cache.CacheListenerTest)1 HazelcastClientCacheManager (com.hazelcast.client.cache.impl.HazelcastClientCacheManager)1 HazelcastClientProxy (com.hazelcast.client.impl.clientside.HazelcastClientProxy)1 CacheConfig (com.hazelcast.config.CacheConfig)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 HazelcastOverloadException (com.hazelcast.core.HazelcastOverloadException)1 IExecutorService (com.hazelcast.core.IExecutorService)1 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)1 ExecutorServiceTestSupport (com.hazelcast.executor.ExecutorServiceTestSupport)1