Search in sources :

Example 1 with RedisEntryConverter

use of org.apache.rocketmq.connect.redis.converter.RedisEntryConverter in project rocketmq-externals by apache.

the class RedisEntryConverterTest method testListSplit.

@Test
public void testListSplit() {
    KVEntryConverter converter = new RedisEntryConverter();
    KVEntry entry = getArrayKVEntry(999);
    Collection res = converter.kVEntryToDataEntries(entry);
    Assert.assertEquals(2, res.size());
    KVEntry entry1 = getArrayKVEntry(1001);
    Collection res1 = converter.kVEntryToDataEntries(entry1);
    Assert.assertEquals(3, res1.size());
    KVEntry entry2 = getArrayKVEntry(1000);
    Collection res2 = converter.kVEntryToDataEntries(entry2);
    Assert.assertEquals(2, res2.size());
}
Also used : RedisEntryConverter(org.apache.rocketmq.connect.redis.converter.RedisEntryConverter) KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) KVEntryConverter(org.apache.rocketmq.connect.redis.converter.KVEntryConverter) Collection(java.util.Collection) Test(org.junit.Test)

Example 2 with RedisEntryConverter

use of org.apache.rocketmq.connect.redis.converter.RedisEntryConverter in project rocketmq-externals by apache.

the class RedisEntryConverterTest method test.

@Test
public void test() {
    KVEntry entry = getKVEntry();
    KVEntryConverter converter = new RedisEntryConverter();
    Collection<SourceDataEntry> res = converter.kVEntryToDataEntries(entry);
    Assert.assertNotNull(res);
    Assert.assertEquals(1, res.size());
    Assert.assertEquals("key", ((List<SourceDataEntry>) res).get(0).getPayload()[1]);
    Assert.assertEquals("value", ((List<SourceDataEntry>) res).get(0).getPayload()[2]);
    Assert.assertEquals("set", ((List<SourceDataEntry>) res).get(0).getPayload()[0]);
    Map<String, Object> params = (Map<String, Object>) ((List<SourceDataEntry>) res).get(0).getPayload()[3];
    Assert.assertEquals("replId", params.get(Options.REDIS_REPLID.name()));
}
Also used : RedisEntryConverter(org.apache.rocketmq.connect.redis.converter.RedisEntryConverter) KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) SourceDataEntry(io.openmessaging.connector.api.data.SourceDataEntry) KVEntryConverter(org.apache.rocketmq.connect.redis.converter.KVEntryConverter) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with RedisEntryConverter

use of org.apache.rocketmq.connect.redis.converter.RedisEntryConverter 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 RedisEntryConverter

use of org.apache.rocketmq.connect.redis.converter.RedisEntryConverter in project rocketmq-externals by apache.

the class RedisEntryConverterTest method testMapSplit.

@Test
public void testMapSplit() {
    KVEntryConverter converter = new RedisEntryConverter();
    RedisEntry entry = RedisEntry.newEntry(FieldType.MAP);
    entry.queueName("queue1");
    entry.key("key");
    entry.entryType(EntryType.UPDATE);
    entry.offset(65535L);
    entry.param(Options.REDIS_INCREMENT, 15L);
    entry.sourceId("123");
    entry.command("set");
    Map<String, String> values = new HashMap<>();
    int num = 10001;
    for (int i = 0; i < num; i++) {
        values.put("a" + i, Integer.toString(i));
    }
    entry.value(values);
    List<SourceDataEntry> entryList = converter.kVEntryToDataEntries(entry);
    Assert.assertNotNull(entryList);
    Assert.assertEquals(21, entryList.size());
    Assert.assertEquals("set", entryList.get(0).getPayload()[0]);
}
Also used : RedisEntry(org.apache.rocketmq.connect.redis.pojo.RedisEntry) RedisEntryConverter(org.apache.rocketmq.connect.redis.converter.RedisEntryConverter) SourceDataEntry(io.openmessaging.connector.api.data.SourceDataEntry) KVEntryConverter(org.apache.rocketmq.connect.redis.converter.KVEntryConverter) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

RedisEntryConverter (org.apache.rocketmq.connect.redis.converter.RedisEntryConverter)4 KVEntryConverter (org.apache.rocketmq.connect.redis.converter.KVEntryConverter)3 Test (org.junit.Test)3 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)2 HashMap (java.util.HashMap)2 KVEntry (org.apache.rocketmq.connect.redis.pojo.KVEntry)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Config (org.apache.rocketmq.connect.redis.common.Config)1 DefaultRedisEventHandler (org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler)1 RedisEventHandler (org.apache.rocketmq.connect.redis.handler.RedisEventHandler)1 RedisEntry (org.apache.rocketmq.connect.redis.pojo.RedisEntry)1 DefaultRedisEventProcessor (org.apache.rocketmq.connect.redis.processor.DefaultRedisEventProcessor)1