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