Search in sources :

Example 41 with ClientConfig

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

the class ClientCacheNearCachePreloaderTest method createClientContext.

private <K, V> NearCacheTestContext<K, V, Data, String> createClientContext(CacheConfig<K, V> cacheConfig) {
    ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
    HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
    NearCacheManager nearCacheManager = client.client.getNearCacheManager();
    CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
    HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
    String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(nearCacheConfig.getName());
    ICache<K, V> clientCache = cacheManager.createCache(nearCacheConfig.getName(), cacheConfig);
    NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
    return new com.hazelcast.internal.nearcache.NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, null, new ICacheDataStructureAdapter<K, V>(clientCache), null, false, nearCache, nearCacheManager, cacheManager, null);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) Data(com.hazelcast.nio.serialization.Data) NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) HazelcastClientCacheManager(com.hazelcast.client.cache.impl.HazelcastClientCacheManager)

Example 42 with ClientConfig

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

the class ClientClusterStateTest method testClient_canNotExecuteWriteOperations_whenClusterState_passive.

@Test(expected = IllegalStateException.class)
public void testClient_canNotExecuteWriteOperations_whenClusterState_passive() {
    warmUpPartitions(instances);
    ClientConfig clientConfig = new ClientConfig().setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), "3");
    HazelcastInstance client = factory.newHazelcastClient(clientConfig);
    IMap<Object, Object> map = client.getMap(randomMapName());
    changeClusterStateEventually(instance, ClusterState.PASSIVE);
    map.put(1, 1);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 43 with ClientConfig

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

the class ClientNodeExtensionTest method test_canGetFromMap_whenNodeExtensionIsNotComplete.

@Test(expected = IllegalStateException.class)
public void test_canGetFromMap_whenNodeExtensionIsNotComplete() {
    IMap<Object, Object> map = null;
    ManagedExtensionNodeContext nodeContext = null;
    try {
        nodeContext = new ManagedExtensionNodeContext(factory.getRegistry(), new Address("127.0.0.1", 5555), true);
        HazelcastInstanceFactory.newHazelcastInstance(new Config(), randomName(), nodeContext);
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), "3");
        clientConfig.getNetworkConfig().addAddress("127.0.0.1:5555");
        HazelcastInstance hazelcastClient = factory.newHazelcastClient(clientConfig);
        map = hazelcastClient.getMap(randomMapName());
        assertNull(map.get("dummy"));
    } catch (Throwable t) {
        fail("Should not throw exception! Error:" + t);
    }
    nodeContext.setStartupDone(false);
    map.get("dummy");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 44 with ClientConfig

use of com.hazelcast.client.config.ClientConfig 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 = HazelcastClientCachingProvider.createCachingProvider(client);
    CacheManager cacheManager = cachingProvider.getCacheManager();
    Cache<String, String> cache = cacheManager.getCache("entrylistenertestcache");
    cache.put("foo", "bar");
    HazelcastInstance client2 = HazelcastClient.newHazelcastClient(clientConfig);
    HazelcastClientCachingProvider cachingProvider2 = HazelcastClientCachingProvider.createCachingProvider(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 45 with ClientConfig

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

the class ClientCacheConfigTest method testGetPreConfiguredCache.

@Test
public void testGetPreConfiguredCache() {
    ClientConfig config = new ClientConfig();
    config.getGroupConfig().setName("cluster1");
    config.getGroupConfig().setPassword("cluster1pass");
    for (int i = 0; i < 4; i++) {
        HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
        CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
        CacheManager cacheManager = provider.getCacheManager();
        Cache<Object, Object> cache = cacheManager.getCache(simpleConfig.getName());
        Assert.assertNotNull("Cache cannot be retrieved on client: " + i, cache);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastCachingProvider(com.hazelcast.cache.HazelcastCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) HazelcastClientCachingProvider(com.hazelcast.client.cache.impl.HazelcastClientCachingProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientConfig (com.hazelcast.client.config.ClientConfig)214 Test (org.junit.Test)129 HazelcastInstance (com.hazelcast.core.HazelcastInstance)110 QuickTest (com.hazelcast.test.annotation.QuickTest)107 ParallelTest (com.hazelcast.test.annotation.ParallelTest)81 Config (com.hazelcast.config.Config)45 NearCacheConfig (com.hazelcast.config.NearCacheConfig)32 NightlyTest (com.hazelcast.test.annotation.NightlyTest)32 CountDownLatch (java.util.concurrent.CountDownLatch)25 AssertTask (com.hazelcast.test.AssertTask)20 Before (org.junit.Before)20 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)16 ClientNetworkConfig (com.hazelcast.client.config.ClientNetworkConfig)15 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)13 CachingProvider (javax.cache.spi.CachingProvider)13 IMap (com.hazelcast.core.IMap)12 LifecycleListener (com.hazelcast.core.LifecycleListener)12 LifecycleEvent (com.hazelcast.core.LifecycleEvent)11 Data (com.hazelcast.nio.serialization.Data)11 NearCacheManager (com.hazelcast.internal.nearcache.NearCacheManager)10