Search in sources :

Example 81 with IMap

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

the class OverloadedConnectionsPluginTest method test.

@Test
public void test() {
    spawn(new Runnable() {

        @Override
        public void run() {
            IMap<String, String> map = local.getMap("foo");
            while (!stop) {
                map.getAsync(remoteKey);
            }
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            plugin.run(logWriter);
            assertContains(GetOperation.class.getSimpleName() + " sampleCount=");
        }
    });
}
Also used : IMap(com.hazelcast.map.IMap) GetOperation(com.hazelcast.map.impl.operation.GetOperation) AssertTask(com.hazelcast.test.AssertTask) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 82 with IMap

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

the class MapExpirationManagerTest method restarts_running_backgroundClearTask_when_lifecycleState_turns_to_MERGED.

@Test
public void restarts_running_backgroundClearTask_when_lifecycleState_turns_to_MERGED() {
    Config config = getConfig();
    config.setProperty(taskPeriodSecondsPropName(), "1");
    HazelcastInstance node = createHazelcastInstance(config);
    final AtomicInteger expirationCounter = new AtomicInteger();
    IMap<Integer, Integer> map = node.getMap("test");
    map.addEntryListener((EntryExpiredListener) event -> expirationCounter.incrementAndGet(), true);
    map.put(1, 1, 3, TimeUnit.SECONDS);
    ((LifecycleServiceImpl) node.getLifecycleService()).fireLifecycleEvent(MERGING);
    ((LifecycleServiceImpl) node.getLifecycleService()).fireLifecycleEvent(MERGED);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            int expirationCount = expirationCounter.get();
            assertEquals(format("Expecting 1 expiration but found:%d", expirationCount), 1, expirationCount);
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) MERGING(com.hazelcast.core.LifecycleEvent.LifecycleState.MERGING) MERGED(com.hazelcast.core.LifecycleEvent.LifecycleState.MERGED) LifecycleServiceImpl(com.hazelcast.instance.impl.LifecycleServiceImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PROP_PRIMARY_DRIVES_BACKUP(com.hazelcast.map.impl.eviction.MapClearExpiredRecordsTask.PROP_PRIMARY_DRIVES_BACKUP) PartitionContainer(com.hazelcast.map.impl.PartitionContainer) System.getProperty(java.lang.System.getProperty) SHUTTING_DOWN(com.hazelcast.core.LifecycleEvent.LifecycleState.SHUTTING_DOWN) System.setProperty(java.lang.System.setProperty) EntryEvent(com.hazelcast.core.EntryEvent) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) LifecycleEvent(com.hazelcast.core.LifecycleEvent) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MapService(com.hazelcast.map.impl.MapService) Category(org.junit.experimental.categories.Category) EntryExpiredListener(com.hazelcast.map.listener.EntryExpiredListener) String.format(java.lang.String.format) TimeUnit(java.util.concurrent.TimeUnit) SERVICE_NAME(com.hazelcast.map.impl.MapService.SERVICE_NAME) MapClearExpiredRecordsTask(com.hazelcast.map.impl.eviction.MapClearExpiredRecordsTask) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) AssertTask(com.hazelcast.test.AssertTask) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) LifecycleServiceImpl(com.hazelcast.instance.impl.LifecycleServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 83 with IMap

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

the class MBeanDestroyTest method testMap.

@Test
public void testMap() throws Exception {
    IMap map = holder.getHz().getMap("map");
    map.size();
    holder.assertMBeanExistEventually("IMap", map.getName());
    destroyObjectAndAssert(map, "IMap");
}
Also used : IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 84 with IMap

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

the class MBeanTest method testMap.

@Test
public void testMap() throws Exception {
    IMap map = holder.getHz().getMap("map");
    map.size();
    holder.assertMBeanExistEventually("IMap", map.getName());
}
Also used : IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 85 with IMap

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

the class ReadMetricsOperationTest method testMetricsPresent_map.

@Test
public void testMetricsPresent_map() {
    Config config = new Config();
    HazelcastInstance hzInstance = createHazelcastInstance(config);
    IMap<Object, Object> map = hzInstance.getMap("map");
    map.put("key", "value");
    NodeEngineImpl nodeEngine = getNode(hzInstance).getNodeEngine();
    OperationServiceImpl operationService = nodeEngine.getOperationService();
    AtomicLong nextSequence = new AtomicLong();
    assertTrueEventually(() -> {
        long sequence = nextSequence.get();
        ReadMetricsOperation readMetricsOperation = new ReadMetricsOperation(sequence);
        InternalCompletableFuture<RingbufferSlice<Map.Entry<Long, byte[]>>> future = operationService.invokeOnTarget(MetricsService.SERVICE_NAME, readMetricsOperation, nodeEngine.getThisAddress());
        RingbufferSlice<Map.Entry<Long, byte[]>> ringbufferSlice = future.get();
        MetricsResultSet metricsResultSet = new MetricsResultSet(ringbufferSlice.nextSequence(), ringbufferSlice.elements());
        nextSequence.set(metricsResultSet.nextSequence());
        boolean mapMetric = false;
        List<Map.Entry<Long, byte[]>> collections = metricsResultSet.collections();
        MetricKeyConsumer metricConsumer = new MetricKeyConsumer();
        for (Map.Entry<Long, byte[]> entry : collections) {
            MetricsCompressor.extractMetrics(entry.getValue(), metricConsumer);
        }
        assertTrue(metricConsumer.mapMetric);
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) RingbufferSlice(com.hazelcast.internal.metrics.managementcenter.ConcurrentArrayRingbuffer.RingbufferSlice) Config(com.hazelcast.config.Config) ReadMetricsOperation(com.hazelcast.internal.metrics.managementcenter.ReadMetricsOperation) MetricsResultSet(com.hazelcast.internal.metrics.managementcenter.MetricsResultSet) AtomicLong(java.util.concurrent.atomic.AtomicLong) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) IMap(com.hazelcast.map.IMap) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IMap (com.hazelcast.map.IMap)292 Test (org.junit.Test)259 QuickTest (com.hazelcast.test.annotation.QuickTest)237 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)228 HazelcastInstance (com.hazelcast.core.HazelcastInstance)139 Config (com.hazelcast.config.Config)103 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)82 Map (java.util.Map)73 CountDownLatch (java.util.concurrent.CountDownLatch)65 MapStoreConfig (com.hazelcast.config.MapStoreConfig)54 Category (org.junit.experimental.categories.Category)51 Assert.assertEquals (org.junit.Assert.assertEquals)50 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)48 HashMap (java.util.HashMap)48 Collection (java.util.Collection)41 RunWith (org.junit.runner.RunWith)41 MapConfig (com.hazelcast.config.MapConfig)36 Set (java.util.Set)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 AssertTask (com.hazelcast.test.AssertTask)32