Search in sources :

Example 1 with IMap

use of com.hazelcast.core.IMap in project cas by apereo.

the class HazelcastMonitor method getStatistics.

@Override
protected CacheStatistics[] getStatistics() {
    final List<CacheStatistics> statsList = new ArrayList<>();
    final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
    LOGGER.debug("Locating hazelcast instance [{}]...", hz.getCluster().getInstanceName());
    final HazelcastInstance instance = Hazelcast.getHazelcastInstanceByName(hz.getCluster().getInstanceName());
    instance.getConfig().getMapConfigs().keySet().forEach(key -> {
        final IMap map = instance.getMap(key);
        LOGGER.debug("Starting to collect hazelcast statistics for map [{}] identified by key [{}]...", map, key);
        statsList.add(new HazelcastStatistics(map, hz.getCluster().getMembers().size()));
    });
    return statsList.toArray(new CacheStatistics[statsList.size()]);
}
Also used : HazelcastProperties(org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ArrayList(java.util.ArrayList)

Example 2 with IMap

use of com.hazelcast.core.IMap in project spring-boot by spring-projects.

the class HazelcastCacheStatisticsProvider method getCacheStatistics.

@Override
public CacheStatistics getCacheStatistics(CacheManager cacheManager, HazelcastCache cache) {
    DefaultCacheStatistics statistics = new DefaultCacheStatistics();
    LocalMapStats mapStatistics = ((IMap<?, ?>) cache.getNativeCache()).getLocalMapStats();
    statistics.setSize(mapStatistics.getOwnedEntryCount());
    statistics.setGetCacheCounts(mapStatistics.getHits(), mapStatistics.getGetOperationCount() - mapStatistics.getHits());
    return statistics;
}
Also used : LocalMapStats(com.hazelcast.monitor.LocalMapStats) IMap(com.hazelcast.core.IMap)

Example 3 with IMap

use of com.hazelcast.core.IMap in project hazelcast by hazelcast.

the class ClientRegressionWithMockNetworkTest method testOperationRedo.

@Test(timeout = 60000)
public void testOperationRedo() throws Exception {
    final HazelcastInstance hz1 = hazelcastFactory.newHazelcastInstance();
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setRedoOperation(true);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    final Thread thread = new Thread() {

        public void run() {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            hz1.getLifecycleService().shutdown();
        }
    };
    final IMap map = client.getMap("m");
    thread.start();
    int expected = 1000;
    for (int i = 0; i < expected; i++) {
        map.put(i, "item" + i);
    }
    thread.join();
    assertEquals(expected, map.size());
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with IMap

use of com.hazelcast.core.IMap in project hazelcast by hazelcast.

the class ClientRegressionWithMockNetworkTest method testMemberAddedWithListeners_thenCheckOperationsNotHanging.

@Test(timeout = 120000)
public void testMemberAddedWithListeners_thenCheckOperationsNotHanging() throws Exception {
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientExecutionServiceImpl.INTERNAL_EXECUTOR_POOL_SIZE.getName(), "1");
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    IMap map = client.getMap("map");
    map.addEntryListener(mock(MapListener.class), true);
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance();
    String key = generateKeyOwnedBy(h2);
    map.get(key);
}
Also used : IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapListener(com.hazelcast.map.listener.MapListener) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with IMap

use of com.hazelcast.core.IMap in project hazelcast by hazelcast.

the class ClientMaxAllowedInvocationTest method testMaxAllowed_withUnfinishedCallback.

@Test(expected = HazelcastOverloadException.class)
public void testMaxAllowed_withUnfinishedCallback() throws ExecutionException, InterruptedException {
    int MAX_ALLOWED = 10;
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), String.valueOf(MAX_ALLOWED));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    String name = randomString();
    IMap map = client.getMap(name);
    IExecutorService executorService = client.getExecutorService(randomString());
    for (int i = 0; i < MAX_ALLOWED - 1; i++) {
        executorService.submit(new SleepyProcessor(Integer.MAX_VALUE));
    }
    ClientDelegatingFuture future = (ClientDelegatingFuture) executorService.submit(new SleepyProcessor(2000));
    CountDownLatch countDownLatch = new CountDownLatch(1);
    future.andThenInternal(new SleepyCallback(countDownLatch), false);
    future.get();
    try {
        map.get(1);
    } catch (HazelcastOverloadException e) {
        throw e;
    } finally {
        countDownLatch.countDown();
    }
}
Also used : IMap(com.hazelcast.core.IMap) ClientDelegatingFuture(com.hazelcast.client.util.ClientDelegatingFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastOverloadException(com.hazelcast.core.HazelcastOverloadException) IExecutorService(com.hazelcast.core.IExecutorService) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

IMap (com.hazelcast.core.IMap)258 Test (org.junit.Test)241 QuickTest (com.hazelcast.test.annotation.QuickTest)218 ParallelTest (com.hazelcast.test.annotation.ParallelTest)211 HazelcastInstance (com.hazelcast.core.HazelcastInstance)140 Config (com.hazelcast.config.Config)80 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)80 Map (java.util.Map)65 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)62 HashMap (java.util.HashMap)53 CountDownLatch (java.util.concurrent.CountDownLatch)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)39 AssertTask (com.hazelcast.test.AssertTask)36 MapStoreConfig (com.hazelcast.config.MapStoreConfig)34 MapConfig (com.hazelcast.config.MapConfig)31 TransactionalMap (com.hazelcast.core.TransactionalMap)29 IExecutorService (com.hazelcast.core.IExecutorService)28 MapPutRunnable (com.hazelcast.client.executor.tasks.MapPutRunnable)27 TransactionContext (com.hazelcast.transaction.TransactionContext)21 TransactionException (com.hazelcast.transaction.TransactionException)21