Search in sources :

Example 66 with EntryEvent

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

the class EvictionTest method testZeroResetsTTL.

@Test
public void testZeroResetsTTL() throws Exception {
    MapConfig mapConfig = newMapConfig("testZeroResetsTTL").setTimeToLiveSeconds(5);
    Config config = getConfig().addMapConfig(mapConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    final IMap<Object, Object> map = instance.getMap("testZeroResetsTTL");
    final CountDownLatch latch = new CountDownLatch(1);
    map.addEntryListener(new EntryAdapter<Object, Object>() {

        public void entryEvicted(EntryEvent event) {
            latch.countDown();
        }
    }, false);
    map.put(1, 1);
    map.put(2, 2);
    map.put(1, 2, 0, SECONDS);
    latch.await(10, SECONDS);
    assertTrueEventually(() -> {
        assertNull(map.get(2));
        assertEquals(2, map.get(1));
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) EntryEvent(com.hazelcast.core.EntryEvent) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) MapConfig(com.hazelcast.config.MapConfig) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 67 with EntryEvent

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

the class EvictionTest method testMapRecordEviction.

@Test(timeout = 5 * 60 * 1000)
public void testMapRecordEviction() {
    String mapName = randomMapName();
    final int size = 100;
    final AtomicInteger entryEvictedEventCount = new AtomicInteger(0);
    EntryListenerConfig entryListenerConfig = new EntryListenerConfig().setLocal(true).setImplementation(new EntryAdapter() {

        public void entryExpired(EntryEvent event) {
            entryEvictedEventCount.incrementAndGet();
        }
    });
    MapConfig mapConfig = newMapConfig(mapName).setTimeToLiveSeconds(1).addEntryListenerConfig(entryListenerConfig);
    Config config = getConfig().addMapConfig(mapConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Integer> map = instance.getMap(mapName);
    for (int i = 0; i < size; i++) {
        map.put(i, i);
    }
    // wait until eviction is complete
    assertSizeEventually(0, map);
    assertTrueEventually(() -> assertEquals(size, entryEvictedEventCount.get()));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapConfig(com.hazelcast.config.MapConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 68 with EntryEvent

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

the class EvictionTest method testMapPutTTLWithListener.

/**
 * Background task {@link com.hazelcast.map.impl.eviction.MapClearExpiredRecordsTask}
 * should sweep expired records eventually.
 */
@Test
@Category(NightlyTest.class)
public void testMapPutTTLWithListener() {
    int putCount = 100;
    IMap<Integer, Integer> map = createSimpleMap();
    final CountDownLatch latch = new CountDownLatch(putCount);
    map.addEntryListener(new EntryAdapter() {

        @Override
        public void entryExpired(final EntryEvent event) {
            latch.countDown();
        }
    }, true);
    int ttl = (int) (Math.random() * 5000);
    for (int j = 0; j < putCount; j++) {
        map.put(j, j, ttl, TimeUnit.MILLISECONDS);
    }
    // wait until eviction is complete
    assertOpenEventually(latch, 100);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Category(org.junit.experimental.categories.Category) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 69 with EntryEvent

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

the class ListenerTest method testConfigListenerRegistration.

@Test
public void testConfigListenerRegistration() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    String name = randomString();
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(name);
    EntryListenerConfig entryListenerConfig = new EntryListenerConfig();
    entryListenerConfig.setImplementation(new EntryAdapter() {

        public void entryAdded(EntryEvent event) {
            latch.countDown();
        }
    });
    mapConfig.addEntryListenerConfig(entryListenerConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Object, Object> map = instance.getMap(name);
    map.put(1, 1);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) MapConfig(com.hazelcast.config.MapConfig) CountDownLatch(java.util.concurrent.CountDownLatch) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 70 with EntryEvent

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

the class MapStoreWriteThroughTest method testOneMemberWriteThroughWithLRU.

@Test(timeout = 120000)
public void testOneMemberWriteThroughWithLRU() {
    final int size = 10000;
    TestMapStore testMapStore = new TestMapStore(size * 2, 1, 1);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 0);
    config.setProperty(ClusterProperty.PARTITION_COUNT.getName(), "1");
    MapConfig mapConfig = config.getMapConfig("default");
    EvictionConfig evictionConfig = mapConfig.getEvictionConfig();
    evictionConfig.setEvictionPolicy(EvictionPolicy.LRU);
    evictionConfig.setSize(size);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap("default");
    final CountDownLatch countDownLatch = new CountDownLatch(size);
    map.addEntryListener(new EntryAdapter() {

        @Override
        public void entryEvicted(EntryEvent event) {
            countDownLatch.countDown();
        }
    }, false);
    for (int i = 0; i < size * 2; i++) {
        // trigger eviction
        if (i == (size * 2) - 1 || i == size) {
            sleepMillis(1001);
        }
        map.put(i, new Employee("joe", i, true, 100.00));
    }
    assertEquals(testMapStore.getStore().size(), size * 2);
    assertOpenEventually(countDownLatch);
    final String msgFailure = String.format("map size: %d put count: %d", map.size(), size);
    assertTrue(msgFailure, map.size() > size / 2);
    assertTrue(msgFailure, map.size() <= size);
    assertEquals(testMapStore.getStore().size(), size * 2);
}
Also used : MapConfig(com.hazelcast.config.MapConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) EvictionConfig(com.hazelcast.config.EvictionConfig) EntryAdapter(com.hazelcast.core.EntryAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) EntryEvent(com.hazelcast.core.EntryEvent) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

EntryEvent (com.hazelcast.core.EntryEvent)71 Test (org.junit.Test)62 QuickTest (com.hazelcast.test.annotation.QuickTest)47 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)39 EntryAdapter (com.hazelcast.core.EntryAdapter)22 HazelcastInstance (com.hazelcast.core.HazelcastInstance)22 Config (com.hazelcast.config.Config)19 CountDownLatch (java.util.concurrent.CountDownLatch)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 AssertTask (com.hazelcast.test.AssertTask)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)15 MapListener (com.hazelcast.map.listener.MapListener)11 MapListenerAdapter (com.hazelcast.map.impl.MapListenerAdapter)10 MapConfig (com.hazelcast.config.MapConfig)9 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)8 Predicate (com.hazelcast.query.Predicate)8 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)8 EntryAddedListener (com.hazelcast.map.listener.EntryAddedListener)7 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)6