Search in sources :

Example 66 with ClientConfig

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);
}
Also used : NearCacheManager(com.hazelcast.internal.nearcache.NearCacheManager) ClientConfig(com.hazelcast.client.config.ClientConfig) NearCacheTestUtils.createNearCacheConfig(com.hazelcast.internal.nearcache.NearCacheTestUtils.createNearCacheConfig) Config(com.hazelcast.config.Config) Data(com.hazelcast.nio.serialization.Data) NearCacheTestContext(com.hazelcast.internal.nearcache.NearCacheTestContext) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Example 67 with ClientConfig

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) ClientConfig(com.hazelcast.client.config.ClientConfig) Before(org.junit.Before)

Example 68 with ClientConfig

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;
}
Also used : NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig)

Example 69 with 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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Category(org.junit.experimental.categories.Category) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 70 with ClientConfig

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());
}
Also used : PagingPredicate(com.hazelcast.query.PagingPredicate) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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