Search in sources :

Example 1 with MyGatewaySenderEventListener

use of org.apache.geode.internal.cache.wan.MyGatewaySenderEventListener in project geode by apache.

the class WANConfigurationJUnitTest method test_GatewaySenderWithGatewaySenderEventListener2.

@Test
public void test_GatewaySenderWithGatewaySenderEventListener2() {
    cache = new CacheFactory().set(MCAST_PORT, "0").create();
    GatewaySenderFactory fact = cache.createGatewaySenderFactory();
    AsyncEventListener listener = new MyGatewaySenderEventListener();
    ((InternalGatewaySenderFactory) fact).addAsyncEventListener(listener);
    try {
        ((InternalGatewaySenderFactory) fact).create("ln");
    } catch (Exception e) {
        fail("Received Exception :" + e);
    }
}
Also used : MyGatewaySenderEventListener(org.apache.geode.internal.cache.wan.MyGatewaySenderEventListener) InternalGatewaySenderFactory(org.apache.geode.internal.cache.wan.InternalGatewaySenderFactory) InternalGatewaySenderFactory(org.apache.geode.internal.cache.wan.InternalGatewaySenderFactory) IOException(java.io.IOException) GatewayReceiverException(org.apache.geode.internal.cache.wan.GatewayReceiverException) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with MyGatewaySenderEventListener

use of org.apache.geode.internal.cache.wan.MyGatewaySenderEventListener in project geode by apache.

the class SerialGatewaySenderEventListenerDUnitTest method validateReceivedEventsMapSizeListener2.

public static void validateReceivedEventsMapSizeListener2(final String senderId, final Map map) {
    Set<GatewaySender> senders = cache.getGatewaySenders();
    GatewaySender sender = null;
    for (GatewaySender s : senders) {
        if (s.getId().equals(senderId)) {
            sender = s;
            break;
        }
    }
    final List<AsyncEventListener> listeners = ((AbstractGatewaySender) sender).getAsyncEventListeners();
    if (listeners.size() == 2) {
        final AsyncEventListener l1 = listeners.get(0);
        final AsyncEventListener l2 = listeners.get(1);
        Awaitility.await().atMost(60000, TimeUnit.MILLISECONDS).until(() -> {
            Map listenerMap1 = ((MyGatewaySenderEventListener) l1).getEventsMap();
            Map listenerMap2 = ((MyGatewaySenderEventListener2) l2).getEventsMap();
            int listener1MapSize = listenerMap1.size();
            int listener2MapSize = listenerMap1.size();
            int expectedMapSize = map.size();
            boolean sizeCorrect = expectedMapSize == listener1MapSize;
            boolean keySetCorrect = listenerMap1.keySet().containsAll(map.keySet());
            boolean valuesCorrect = listenerMap1.values().containsAll(map.values());
            boolean sizeCorrect2 = expectedMapSize == listener2MapSize;
            boolean keySetCorrect2 = listenerMap2.keySet().containsAll(map.keySet());
            boolean valuesCorrect2 = listenerMap2.values().containsAll(map.values());
            assertEquals("Failed while waiting for all sites to get updated with the correct events. \nThe " + "size of listener 1's map = " + listener1MapSize + "\n The size of listener 2's map = " + "" + listener2MapSize + "\n The expected map size =" + expectedMapSize, true, sizeCorrect && keySetCorrect && valuesCorrect && sizeCorrect2 && keySetCorrect2 && valuesCorrect2);
        });
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) MyGatewaySenderEventListener(org.apache.geode.internal.cache.wan.MyGatewaySenderEventListener) MyGatewaySenderEventListener2(org.apache.geode.internal.cache.wan.MyGatewaySenderEventListener2) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) HashMap(java.util.HashMap) Map(java.util.Map) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 3 with MyGatewaySenderEventListener

use of org.apache.geode.internal.cache.wan.MyGatewaySenderEventListener in project geode by apache.

the class WANConfigurationJUnitTest method test_GatewaySenderWithGatewaySenderEventListener1.

@Test
public void test_GatewaySenderWithGatewaySenderEventListener1() {
    cache = new CacheFactory().set(MCAST_PORT, "0").create();
    InternalGatewaySenderFactory fact = (InternalGatewaySenderFactory) cache.createGatewaySenderFactory();
    AsyncEventListener listener = new MyGatewaySenderEventListener();
    ((InternalGatewaySenderFactory) fact).addAsyncEventListener(listener);
    try {
        fact.create("ln", 2);
        fail("Expected GatewaySenderException. When a sender is added , remoteDSId should not be provided.");
    } catch (Exception e) {
        if (e instanceof GatewaySenderException && e.getMessage().contains("cannot define a remote site because at least AsyncEventListener is already added.")) {
        } else {
            fail("Expected GatewaySenderException but received :" + e);
        }
    }
}
Also used : MyGatewaySenderEventListener(org.apache.geode.internal.cache.wan.MyGatewaySenderEventListener) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) InternalGatewaySenderFactory(org.apache.geode.internal.cache.wan.InternalGatewaySenderFactory) IOException(java.io.IOException) GatewayReceiverException(org.apache.geode.internal.cache.wan.GatewayReceiverException) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

AsyncEventListener (org.apache.geode.cache.asyncqueue.AsyncEventListener)3 MyGatewaySenderEventListener (org.apache.geode.internal.cache.wan.MyGatewaySenderEventListener)3 IOException (java.io.IOException)2 GatewayReceiverException (org.apache.geode.internal.cache.wan.GatewayReceiverException)2 GatewaySenderException (org.apache.geode.internal.cache.wan.GatewaySenderException)2 InternalGatewaySenderFactory (org.apache.geode.internal.cache.wan.InternalGatewaySenderFactory)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GatewaySender (org.apache.geode.cache.wan.GatewaySender)1 AbstractGatewaySender (org.apache.geode.internal.cache.wan.AbstractGatewaySender)1 MyGatewaySenderEventListener2 (org.apache.geode.internal.cache.wan.MyGatewaySenderEventListener2)1