use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientMapNearCacheSerializationCountTest method createContext.
@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
Config config = getConfig();
config.getMapConfig(DEFAULT_NEAR_CACHE_NAME).setInMemoryFormat(mapInMemoryFormat);
prepareSerializationConfig(config.getSerializationConfig());
ClientConfig clientConfig = getClientConfig();
if (nearCacheConfig != null) {
clientConfig.addNearCacheConfig(nearCacheConfig);
}
prepareSerializationConfig(clientConfig.getSerializationConfig());
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
IMap<K, V> memberMap = member.getMap(DEFAULT_NEAR_CACHE_NAME);
IMap<K, V> clientMap = client.getMap(DEFAULT_NEAR_CACHE_NAME);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new IMapDataStructureAdapter<K, V>(clientMap), new IMapDataStructureAdapter<K, V>(memberMap), false, nearCache, nearCacheManager);
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientMapNearCacheStaleReadTest method setUp.
@Before
public void setUp() throws Exception {
TestHazelcastFactory factory = new TestHazelcastFactory();
valuePut = new AtomicInteger(0);
stop = new AtomicBoolean(false);
failed = new AtomicBoolean(false);
assertionViolationCount = new AtomicInteger(0);
Config config = new Config();
config.setProperty(GroupProperty.MAP_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS.getName(), "2");
member = factory.newHazelcastInstance(config);
ClientConfig clientConfig = getClientConfig(MAP_NAME);
clientConfig.setProperty("hazelcast.invalidation.max.tolerated.miss.count", "0");
client = factory.newHazelcastClient(clientConfig);
map = client.getMap(MAP_NAME);
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientMapNearCacheStalenessTest method getClientConfig.
protected ClientConfig getClientConfig(String mapName) {
NearCacheConfig nearCacheConfig = getNearCacheConfig(mapName);
ClientConfig clientConfig = new ClientConfig();
clientConfig.addNearCacheConfig(nearCacheConfig);
return clientConfig;
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientMapIssueTest method testOperationNotBlockingAfterClusterShutdown.
@Test
@Category(NightlyTest.class)
public void testOperationNotBlockingAfterClusterShutdown() throws InterruptedException {
Config config = getConfig();
HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance(config);
HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(config);
ClientConfig clientConfig = new ClientConfig();
clientConfig.setExecutorPoolSize(1);
clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
clientConfig.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), "10");
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final IMap<String, String> map = client.getMap(randomMapName());
map.put(randomString(), randomString());
instance1.getLifecycleService().terminate();
instance2.getLifecycleService().terminate();
final CountDownLatch latch = new CountDownLatch(1);
new Thread() {
public void run() {
try {
map.get(randomString());
} catch (Exception ignored) {
} finally {
latch.countDown();
}
}
}.start();
assertOpenEventually(latch);
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientMapIssueTest method testMapPagingValues.
@Test
public void testMapPagingValues() {
Config config = getConfig();
hazelcastFactory.newHazelcastInstance(config);
hazelcastFactory.newHazelcastInstance(config);
final ClientConfig clientConfig = new ClientConfig();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final IMap<Integer, Integer> map = client.getMap("map");
final int size = 50;
final int pageSize = 5;
for (int i = 0; i < size; i++) {
map.put(i, i);
}
final PagingPredicate<Integer, Integer> predicate = new PagingPredicate<Integer, Integer>(pageSize);
predicate.nextPage();
Collection<Integer> values = map.values(predicate);
assertEquals(pageSize, values.size());
/**
* There may be cases when the server may return a list of entries larger than the requested page size , in this case
* the client should not put any anchor into the list that is on a page greater than the requested page. The case occurs
* when multiple members exist in the cluster. E.g.:
* pageSize:5
* page:2
* Map entries are: (0,0), (1, 1), ... (50, 50)
* server may return entries: 5, 6,7,8,9,10,13, 15, 16, 19 . We should not put (19, 19) as an anchor for page 2 but
* only (9, 9) for page 1. The below code tests this issue.
*/
// get the entries for page 0
predicate.setPage(0);
values = map.values(predicate);
assertEquals(pageSize, values.size());
int i = 0;
for (Integer value : values) {
assertEquals(i, value.intValue());
++i;
}
// get the entries for page 0, double check if calling second time works fine
values = map.values(predicate);
assertEquals(pageSize, values.size());
i = 0;
for (Integer value : values) {
assertEquals(i, value.intValue());
++i;
}
// get page 1, predicate anchors should be updated accordingly
predicate.nextPage();
values = map.values(predicate);
assertEquals(pageSize, values.size());
i = pageSize;
for (Integer value : values) {
assertEquals(i, value.intValue());
++i;
}
// Make sure that the anchor is the last entry of the first page. i.e. it is (9, 9)
Map.Entry anchor = predicate.getAnchor();
assertEquals((2 * pageSize) - 1, anchor.getKey());
assertEquals((2 * pageSize) - 1, anchor.getValue());
// jump to page 4
predicate.setPage(4);
values = map.values(predicate);
assertEquals(pageSize, values.size());
i = 4 * pageSize;
for (Integer value : values) {
assertEquals(i, value.intValue());
++i;
}
// Make sure that the new predicate is page 4 and last entry is: (24, 24)
anchor = predicate.getAnchor();
assertEquals((5 * pageSize) - 1, anchor.getKey());
assertEquals((5 * pageSize) - 1, anchor.getValue());
// jump to page 9
predicate.setPage(9);
values = map.values(predicate);
assertEquals(pageSize, values.size());
i = 9 * pageSize;
for (Integer value : values) {
assertEquals(i, value.intValue());
++i;
}
// make sure that the anchor is now (10 * 5) -1 = (49, 49)
anchor = predicate.getAnchor();
assertEquals((10 * pageSize) - 1, anchor.getKey());
assertEquals((10 * pageSize) - 1, anchor.getValue());
}
Aggregations