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());
}
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);
}
Aggregations