Search in sources :

Example 41 with EntryEvent

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

the class BasicMapTest method testMapQueryListener.

@Test
public void testMapQueryListener() {
    IMap<Object, Object> map = getInstance().getMap(randomMapName());
    final Object[] addedKey = new Object[1];
    final Object[] addedValue = new Object[1];
    final Object[] updatedKey = new Object[1];
    final Object[] oldValue = new Object[1];
    final Object[] newValue = new Object[1];
    final Object[] removedKey = new Object[1];
    final Object[] removedValue = new Object[1];
    EntryListener<Object, Object> listener = new EntryAdapter<Object, Object>() {

        @Override
        public void entryAdded(EntryEvent<Object, Object> event) {
            addedKey[0] = event.getKey();
            addedValue[0] = event.getValue();
        }

        @Override
        public void entryRemoved(EntryEvent<Object, Object> event) {
            removedKey[0] = event.getKey();
            removedValue[0] = event.getOldValue();
        }

        @Override
        public void entryUpdated(EntryEvent<Object, Object> event) {
            updatedKey[0] = event.getKey();
            oldValue[0] = event.getOldValue();
            newValue[0] = event.getValue();
        }

        @Override
        public void entryEvicted(EntryEvent<Object, Object> event) {
        }

        @Override
        public void mapEvicted(MapEvent event) {
        }

        @Override
        public void mapCleared(MapEvent event) {
        }
    };
    map.addEntryListener(listener, new StartsWithPredicate("a"), null, true);
    map.put("key1", "abc");
    map.put("key2", "bcd");
    map.put("key2", "axyz");
    map.remove("key1");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals("key1", addedKey[0]);
            assertEquals("abc", addedValue[0]);
            assertEquals("key2", updatedKey[0]);
            assertEquals("bcd", oldValue[0]);
            assertEquals("axyz", newValue[0]);
            assertEquals("key1", removedKey[0]);
            assertEquals("abc", removedValue[0]);
        }
    });
}
Also used : EntryAdapter(com.hazelcast.core.EntryAdapter) EntryEvent(com.hazelcast.core.EntryEvent) MapEvent(com.hazelcast.core.MapEvent) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 42 with EntryEvent

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

the class HazelcastReplicatedmapConsumerTest method testEvict.

/*
     * mail from talip (hazelcast) on 21.02.2011: MultiMap doesn't support eviction yet. We can and should add this feature.
     */
@Test
@SuppressWarnings("unchecked")
public void testEvict() throws InterruptedException {
    MockEndpoint out = getMockEndpoint("mock:evicted");
    out.expectedMessageCount(1);
    EntryEvent<Object, Object> event = new EntryEvent<Object, Object>("foo", null, EntryEventType.EVICTED.getType(), "4711", "my-foo");
    argument.getValue().entryEvicted(event);
    assertMockEndpointsSatisfied(30000, TimeUnit.MILLISECONDS);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) EntryEvent(com.hazelcast.core.EntryEvent) Test(org.junit.Test)

Example 43 with EntryEvent

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

the class HazelcastMapConsumerTest method testUpdate.

@Test
@SuppressWarnings("unchecked")
public void testUpdate() throws InterruptedException {
    MockEndpoint out = getMockEndpoint("mock:updated");
    out.expectedMessageCount(1);
    EntryEvent<Object, Object> event = new EntryEvent<Object, Object>("foo", null, EntryEventType.UPDATED.getType(), "4711", "my-foo");
    argument.getValue().entryUpdated(event);
    assertMockEndpointsSatisfied(5000, TimeUnit.MILLISECONDS);
    this.checkHeaders(out.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.UPDATED);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) EntryEvent(com.hazelcast.core.EntryEvent) Test(org.junit.Test)

Example 44 with EntryEvent

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

the class HazelcastMapConsumerTest method testEnict.

@Test
@SuppressWarnings("unchecked")
public void testEnict() throws InterruptedException {
    MockEndpoint out = super.getMockEndpoint("mock:evicted");
    out.expectedMessageCount(1);
    EntryEvent<Object, Object> event = new EntryEvent<Object, Object>("foo", null, EntryEventType.EVICTED.getType(), "4711", "my-foo");
    argument.getValue().entryEvicted(event);
    assertMockEndpointsSatisfied(30000, TimeUnit.MILLISECONDS);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) EntryEvent(com.hazelcast.core.EntryEvent) Test(org.junit.Test)

Example 45 with EntryEvent

use of com.hazelcast.core.EntryEvent in project wildfly-camel by wildfly-extras.

the class HazelcastMapConsumerIntegrationTest method testEvict.

@Test
@SuppressWarnings("unchecked")
public void testEvict() throws Exception {
    CamelContext camelctx = createCamelContext();
    camelctx.start();
    try {
        MockEndpoint mock = camelctx.getEndpoint("mock:evicted", MockEndpoint.class);
        mock.expectedMessageCount(1);
        EntryEvent<Object, Object> event = new EntryEvent<Object, Object>("foo", null, EntryEventType.EVICTED.getType(), "4711", "my-foo");
        argument.getValue().entryEvicted(event);
        mock.assertIsSatisfied(3000);
    } finally {
        camelctx.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) EntryEvent(com.hazelcast.core.EntryEvent) 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