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