Search in sources :

Example 1 with EventListener

use of com.moilioncircle.redis.replicator.event.EventListener in project rocketmq-externals by apache.

the class ListenerTest method testEventListenerRetry2.

@Test
public void testEventListenerRetry2() {
    Config config = getConfig();
    RedisEventProcessor processor = getExceptionProcessor(config);
    EventListener eventListener = new RedisEventListener(config, processor);
    KeyValuePair pair = new KeyStringValueString();
    eventListener.onEvent(null, pair);
}
Also used : RedisEventProcessor(org.apache.rocketmq.connect.redis.processor.RedisEventProcessor) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor) KeyValuePair(com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair) Config(org.apache.rocketmq.connect.redis.common.Config) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString) EventListener(com.moilioncircle.redis.replicator.event.EventListener) RedisEventListener(org.apache.rocketmq.connect.redis.processor.RedisEventListener) RedisEventListener(org.apache.rocketmq.connect.redis.processor.RedisEventListener) Test(org.junit.Test)

Example 2 with EventListener

use of com.moilioncircle.redis.replicator.event.EventListener in project rocketmq-externals by apache.

the class ListenerTest method testEventListenerRetry1.

@Test
public void testEventListenerRetry1() {
    Config config = getConfig();
    RedisEventProcessor processor = getFailedProcessor(config);
    EventListener eventListener = new RedisEventListener(config, processor);
    KeyValuePair pair = new KeyStringValueString();
    eventListener.onEvent(null, pair);
}
Also used : RedisEventProcessor(org.apache.rocketmq.connect.redis.processor.RedisEventProcessor) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor) KeyValuePair(com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair) Config(org.apache.rocketmq.connect.redis.common.Config) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString) EventListener(com.moilioncircle.redis.replicator.event.EventListener) RedisEventListener(org.apache.rocketmq.connect.redis.processor.RedisEventListener) RedisEventListener(org.apache.rocketmq.connect.redis.processor.RedisEventListener) Test(org.junit.Test)

Example 3 with EventListener

use of com.moilioncircle.redis.replicator.event.EventListener in project rocketmq-externals by apache.

the class RocketMQRedisReplicatorTest method open.

@Test
public void open() throws Exception {
    Configure configure = new Configure(properties);
    Replicator replicator = new RocketMQRedisReplicator(configure);
    final RocketMQRedisProducer producer = new RocketMQRedisProducer(configure);
    producer.open();
    final AtomicInteger test = new AtomicInteger();
    replicator.addEventListener(new EventListener() {

        @Override
        public void onEvent(Replicator replicator, Event event) {
            if (event instanceof KeyValuePair<?, ?>) {
                try {
                    boolean success = producer.send(event);
                    if (success) {
                        test.incrementAndGet();
                    }
                } catch (Exception e) {
                    LOGGER.error("Fail to send KeyValuePair", e);
                }
            } else if (event instanceof Command) {
                try {
                    boolean success = producer.send(event);
                    if (success) {
                        test.incrementAndGet();
                    }
                } catch (Exception e) {
                    LOGGER.error("Fail to send command", e);
                }
            }
        }
    });
    replicator.addCloseListener(new CloseListener() {

        @Override
        public void handle(Replicator replicator) {
            producer.close();
        }
    });
    replicator.open();
    assertEquals(19, test.get());
}
Also used : Replicator(com.moilioncircle.redis.replicator.Replicator) RocketMQRedisProducer(org.apache.rocketmq.redis.replicator.mq.RocketMQRedisProducer) URISyntaxException(java.net.URISyntaxException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Command(com.moilioncircle.redis.replicator.cmd.Command) CloseListener(com.moilioncircle.redis.replicator.CloseListener) Configure(org.apache.rocketmq.redis.replicator.conf.Configure) Event(com.moilioncircle.redis.replicator.event.Event) EventListener(com.moilioncircle.redis.replicator.event.EventListener) Test(org.junit.Test)

Example 4 with EventListener

use of com.moilioncircle.redis.replicator.event.EventListener in project rocketmq-externals by apache.

the class ListenerTest method testEventListener.

@Test
public void testEventListener() {
    EventListener eventListener = new RedisEventListener(this.config, processor);
    KeyValuePair pair = new KeyStringValueString();
    eventListener.onEvent(null, pair);
}
Also used : KeyValuePair(com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString) EventListener(com.moilioncircle.redis.replicator.event.EventListener) RedisEventListener(org.apache.rocketmq.connect.redis.processor.RedisEventListener) RedisEventListener(org.apache.rocketmq.connect.redis.processor.RedisEventListener) Test(org.junit.Test)

Aggregations

EventListener (com.moilioncircle.redis.replicator.event.EventListener)4 Test (org.junit.Test)4 KeyStringValueString (com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString)3 KeyValuePair (com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair)3 RedisEventListener (org.apache.rocketmq.connect.redis.processor.RedisEventListener)3 Config (org.apache.rocketmq.connect.redis.common.Config)2 DefaultRedisEventProcessor (org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor)2 RedisEventProcessor (org.apache.rocketmq.connect.redis.processor.RedisEventProcessor)2 CloseListener (com.moilioncircle.redis.replicator.CloseListener)1 Replicator (com.moilioncircle.redis.replicator.Replicator)1 Command (com.moilioncircle.redis.replicator.cmd.Command)1 Event (com.moilioncircle.redis.replicator.event.Event)1 URISyntaxException (java.net.URISyntaxException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Configure (org.apache.rocketmq.redis.replicator.conf.Configure)1 RocketMQRedisProducer (org.apache.rocketmq.redis.replicator.mq.RocketMQRedisProducer)1