Search in sources :

Example 1 with Event

use of com.moilioncircle.redis.replicator.event.Event 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 2 with Event

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

the class KryoEventSerializerTest method test.

@Test
public void test() {
    Event e = new PreRdbSyncEvent();
    Serializer<Event> serializer = new KryoEventSerializer();
    System.out.println(serializer.read(serializer.write(e)));
    KeyStringValueHash x = new KeyStringValueHash();
    x.setKey("key".getBytes());
    Map<byte[], byte[]> map1 = new ByteArrayMap();
    map1.put("field1".getBytes(), "value1".getBytes());
    map1.put("field2".getBytes(), "value2".getBytes());
    x.setValue(map1);
    KeyStringValueHash kv = (KeyStringValueHash) serializer.read(serializer.write(x));
    ByteArrayMap map2 = (ByteArrayMap) kv.getValue();
    assertNotNull(map2.get("field1".getBytes()));
    ZUnionStoreParser parser = new ZUnionStoreParser();
    ZUnionStoreCommand cmd = parser.parse(toObjectArray("zunionstore des 2 k1 k2 WEIGHTS 2 3 AGGREGATE min".split(" ")));
    ZUnionStoreCommand cmd1 = (ZUnionStoreCommand) serializer.read(serializer.write(cmd));
    for (byte[] bytes : cmd1.getKeys()) {
        System.out.println(new String(bytes));
    }
    System.out.println(cmd1);
}
Also used : ZUnionStoreParser(com.moilioncircle.redis.replicator.cmd.parser.ZUnionStoreParser) Event(com.moilioncircle.redis.replicator.event.Event) PreRdbSyncEvent(com.moilioncircle.redis.replicator.event.PreRdbSyncEvent) KeyStringValueHash(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueHash) ZUnionStoreCommand(com.moilioncircle.redis.replicator.cmd.impl.ZUnionStoreCommand) PreRdbSyncEvent(com.moilioncircle.redis.replicator.event.PreRdbSyncEvent) ByteArrayMap(com.moilioncircle.redis.replicator.util.ByteArrayMap) Test(org.junit.Test)

Aggregations

Event (com.moilioncircle.redis.replicator.event.Event)2 Test (org.junit.Test)2 CloseListener (com.moilioncircle.redis.replicator.CloseListener)1 Replicator (com.moilioncircle.redis.replicator.Replicator)1 Command (com.moilioncircle.redis.replicator.cmd.Command)1 ZUnionStoreCommand (com.moilioncircle.redis.replicator.cmd.impl.ZUnionStoreCommand)1 ZUnionStoreParser (com.moilioncircle.redis.replicator.cmd.parser.ZUnionStoreParser)1 EventListener (com.moilioncircle.redis.replicator.event.EventListener)1 PreRdbSyncEvent (com.moilioncircle.redis.replicator.event.PreRdbSyncEvent)1 KeyStringValueHash (com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueHash)1 ByteArrayMap (com.moilioncircle.redis.replicator.util.ByteArrayMap)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