Search in sources :

Example 1 with RedisEventHandler

use of org.apache.rocketmq.connect.redis.handler.RedisEventHandler in project rocketmq-externals by apache.

the class RedisEventHandlerTest method handlerTest.

private <T> KVEntry handlerTest(int rdbType, ValueSetter<T> setter) {
    KVEntry res = null;
    Exception ex = null;
    Config config = getConfig();
    RedisEventHandler handler = new DefaultRedisEventHandler(config);
    KeyValuePair keyValuePair = new KeyStringValueList();
    keyValuePair.setValueRdbType(rdbType);
    keyValuePair.setKey("key".getBytes());
    Object value = setter.getValue();
    keyValuePair.setValue(value);
    try {
        res = handler.handleKVString(replId, offset, keyValuePair);
    } catch (Exception e) {
        e.printStackTrace();
        ex = e;
    }
    Assert.assertNull(ex);
    return res;
}
Also used : KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) RedisEventHandler(org.apache.rocketmq.connect.redis.handler.RedisEventHandler) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) BatchedKeyValuePair(com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyValuePair) KeyValuePair(com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair) Config(org.apache.rocketmq.connect.redis.common.Config) KeyStringValueList(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueList) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler)

Example 2 with RedisEventHandler

use of org.apache.rocketmq.connect.redis.handler.RedisEventHandler in project rocketmq-externals by apache.

the class RedisEventHandlerTest method testNull.

@Test
public void testNull() {
    Config config = getConfig();
    RedisEventHandler handler = new DefaultRedisEventHandler(config);
    KVEntry res = null;
    Exception ex = null;
    // 测试increment下的rdb数据处理
    config.setSyncMod(SyncMod.LAST_OFFSET.name());
    KeyValuePair keyValuePair = new KeyStringValueString();
    keyValuePair.setKey("key".getBytes());
    keyValuePair.setValue("value".getBytes());
    try {
        res = handler.handleKVString(replId, offset, keyValuePair);
    } catch (Exception e) {
        e.printStackTrace();
        ex = e;
    }
    Assert.assertNull(res);
    Assert.assertNull(ex);
    // 测试未指定的command
    GetSetCommand command = new GetSetCommand();
    command.setKey("key".getBytes());
    command.setValue("value".getBytes());
    try {
        res = handler.handleCommand(replId, offset, command);
    } catch (Exception e) {
        ex = e;
    }
    Assert.assertNull(res);
    Assert.assertNull(ex);
}
Also used : RedisEventHandler(org.apache.rocketmq.connect.redis.handler.RedisEventHandler) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) BatchedKeyValuePair(com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyValuePair) KeyValuePair(com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair) Config(org.apache.rocketmq.connect.redis.common.Config) BatchedKeyStringValueString(com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyStringValueString) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) GetSetCommand(com.moilioncircle.redis.replicator.cmd.impl.GetSetCommand) Test(org.junit.Test)

Example 3 with RedisEventHandler

use of org.apache.rocketmq.connect.redis.handler.RedisEventHandler in project rocketmq-externals by apache.

the class RedisSourceTask method start.

@Override
public void start(KeyValue keyValue) {
    this.kvEntryConverter = new RedisEntryConverter();
    this.config = new Config();
    this.config.load(keyValue);
    LOGGER.info("task config msg: {}", this.config.toString());
    // get position info
    ByteBuffer byteBuffer = this.context.positionStorageReader().getPosition(this.config.getPositionPartitionKey());
    Long position = RedisPositionConverter.jsonToLong(byteBuffer);
    if (position != null && position >= -1) {
        this.config.setPosition(position);
    }
    LOGGER.info("task load connector runtime position: {}", this.config.getPosition());
    this.eventProcessor = new DefaultRedisEventProcessor(config);
    RedisEventHandler eventHandler = new DefaultRedisEventHandler(this.config);
    this.eventProcessor.registEventHandler(eventHandler);
    this.eventProcessor.registProcessorCallback(new DefaultRedisEventProcessorCallback());
    try {
        this.eventProcessor.start();
        LOGGER.info("Redis task start.");
    } catch (IOException e) {
        LOGGER.error("processor start error: {}", e);
        this.stop();
    }
}
Also used : RedisEntryConverter(org.apache.rocketmq.connect.redis.converter.RedisEntryConverter) RedisEventHandler(org.apache.rocketmq.connect.redis.handler.RedisEventHandler) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) Config(org.apache.rocketmq.connect.redis.common.Config) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) IOException(java.io.IOException) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor) ByteBuffer(java.nio.ByteBuffer)

Example 4 with RedisEventHandler

use of org.apache.rocketmq.connect.redis.handler.RedisEventHandler in project rocketmq-externals by apache.

the class ListenerTest method getProcessor.

private RedisEventProcessor getProcessor() {
    Config config = getConfig();
    RedisEventHandler eventHandler = new DefaultRedisEventHandler(config);
    RedisEventProcessor processor = new DefaultRedisEventProcessor(config);
    processor.registEventHandler(eventHandler);
    return processor;
}
Also used : RedisEventProcessor(org.apache.rocketmq.connect.redis.processor.RedisEventProcessor) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor) RedisEventHandler(org.apache.rocketmq.connect.redis.handler.RedisEventHandler) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) Config(org.apache.rocketmq.connect.redis.common.Config) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor)

Example 5 with RedisEventHandler

use of org.apache.rocketmq.connect.redis.handler.RedisEventHandler in project rocketmq-externals by apache.

the class ListenerTest method getFailedProcessor.

private RedisEventProcessor getFailedProcessor(Config config) {
    RedisEventHandler eventHandler = new DefaultRedisEventHandler(config);
    RedisEventProcessor processor = mock(DefaultRedisEventProcessor.class);
    processor.registEventHandler(eventHandler);
    try {
        when(processor.commit(any())).thenReturn(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return processor;
}
Also used : RedisEventProcessor(org.apache.rocketmq.connect.redis.processor.RedisEventProcessor) DefaultRedisEventProcessor(org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor) RedisEventHandler(org.apache.rocketmq.connect.redis.handler.RedisEventHandler) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) IOException(java.io.IOException)

Aggregations

DefaultRedisEventHandler (org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler)8 RedisEventHandler (org.apache.rocketmq.connect.redis.handler.RedisEventHandler)8 Config (org.apache.rocketmq.connect.redis.common.Config)5 DefaultRedisEventProcessor (org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor)5 RedisEventProcessor (org.apache.rocketmq.connect.redis.processor.RedisEventProcessor)4 BatchedKeyValuePair (com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyValuePair)3 IOException (java.io.IOException)3 KVEntry (org.apache.rocketmq.connect.redis.pojo.KVEntry)3 KeyValuePair (com.moilioncircle.redis.replicator.rdb.datatype.KeyValuePair)2 BatchedKeyStringValueString (com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyStringValueString)2 Test (org.junit.Test)2 GetSetCommand (com.moilioncircle.redis.replicator.cmd.impl.GetSetCommand)1 AuxField (com.moilioncircle.redis.replicator.rdb.datatype.AuxField)1 KeyStringValueList (com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueList)1 KeyStringValueString (com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString)1 ByteBuffer (java.nio.ByteBuffer)1 RedisEntryConverter (org.apache.rocketmq.connect.redis.converter.RedisEntryConverter)1