Search in sources :

Example 1 with RedisEntry

use of org.apache.rocketmq.connect.redis.pojo.RedisEntry in project rocketmq-externals by apache.

the class KVEntryTest method testConstruct.

@Test
public void testConstruct() {
    KVEntry entry = new RedisEntry(FieldType.STRING);
    entry.value("value");
    Assert.assertEquals(String.class, entry.getValue().getClass());
    entry = new RedisEntry("partition", FieldType.ARRAY);
    entry.value(new ArrayList<>());
    Assert.assertEquals(ArrayList.class, entry.getValue().getClass());
    Assert.assertEquals("partition", entry.getPartition());
    entry = RedisEntry.newEntry(FieldType.MAP);
    entry.value(new HashMap());
    Assert.assertEquals(HashMap.class, entry.getValue().getClass());
    entry = RedisEntry.newEntry("partition", FieldType.INT64);
    entry.value(123L);
    Assert.assertEquals(Long.class, entry.getValue().getClass());
    Assert.assertTrue(123L == (long) entry.getValue());
    Assert.assertEquals("partition", entry.getPartition());
    Assert.assertNotNull(entry.toString());
    List<SourceDataEntry> entries = getConverter().kVEntryToDataEntries(entry);
    Assert.assertNotNull(entries);
}
Also used : RedisEntry(org.apache.rocketmq.connect.redis.pojo.RedisEntry) KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) SourceDataEntry(io.openmessaging.connector.api.data.SourceDataEntry) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with RedisEntry

use of org.apache.rocketmq.connect.redis.pojo.RedisEntry in project rocketmq-externals by apache.

the class KVEntryTest method test.

@Test
public void test() {
    RedisEntry entry = RedisEntry.newEntry(FieldType.STRING);
    entry.partition("partition");
    entry.queueName("queue1");
    entry.entryType(EntryType.UPDATE);
    entry.sourceId("replId");
    entry.offset(65535L);
    entry.command("set");
    entry.key("key");
    entry.valueType(FieldType.STRING);
    entry.value("value");
    entry.param(Options.REDIS_INCREMENT, 15L);
    Assert.assertEquals("partition", entry.getPartition());
    Assert.assertEquals("queue1", entry.getQueueName());
    Assert.assertEquals(EntryType.UPDATE, entry.getEntryType());
    Assert.assertEquals("replId", entry.getSourceId());
    Assert.assertEquals(65535L, (long) entry.getOffset());
    Assert.assertEquals("set", entry.getCommand());
    Assert.assertEquals("key", entry.getKey());
    Assert.assertEquals(FieldType.STRING, entry.getValueType());
    Assert.assertEquals("value", entry.getValue());
    Assert.assertEquals(15L, (long) entry.getParam(Options.REDIS_INCREMENT));
    Assert.assertEquals(15L, (long) entry.getParams().get(Options.REDIS_INCREMENT.name()));
}
Also used : RedisEntry(org.apache.rocketmq.connect.redis.pojo.RedisEntry) Test(org.junit.Test)

Example 3 with RedisEntry

use of org.apache.rocketmq.connect.redis.pojo.RedisEntry 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)

Example 4 with RedisEntry

use of org.apache.rocketmq.connect.redis.pojo.RedisEntry in project rocketmq-externals by apache.

the class RedisEntryConverterTest method getArrayKVEntry.

private KVEntry getArrayKVEntry(int size) {
    KVEntry entry = new RedisEntry(FieldType.ARRAY);
    List<String> values = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        values.add(Integer.toString(i));
    }
    return entry.key("key").value(values).command("set").sourceId("replId").offset(6000L);
}
Also used : RedisEntry(org.apache.rocketmq.connect.redis.pojo.RedisEntry) KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) ArrayList(java.util.ArrayList)

Aggregations

RedisEntry (org.apache.rocketmq.connect.redis.pojo.RedisEntry)4 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 ArrayList (java.util.ArrayList)1 KVEntryConverter (org.apache.rocketmq.connect.redis.converter.KVEntryConverter)1 RedisEntryConverter (org.apache.rocketmq.connect.redis.converter.RedisEntryConverter)1