Search in sources :

Example 1 with KVEntry

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

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

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

the class RedisEventHandlerTest method testZSet2.

@Test
public void testZSet2() {
    KVEntry builder = handlerTest(RDB_TYPE_ZSET_2, () -> {
        Set<ZSetEntry> values = new HashSet<>();
        values.add(new ZSetEntry("key1".getBytes(), 100));
        values.add(new ZSetEntry("key2".getBytes(), 80));
        return values;
    });
    Map<String, Double> va = (Map<String, Double>) builder.getValue();
    Assert.assertNotNull(va);
    Assert.assertEquals(2, va.size());
    Assert.assertTrue(100 == va.get("key1"));
    Assert.assertTrue(80 == va.get("key2"));
}
Also used : ZSetEntry(com.moilioncircle.redis.replicator.rdb.datatype.ZSetEntry) KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) BatchedKeyStringValueString(com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyStringValueString) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with KVEntry

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

the class RedisEventHandlerTest method testListQuickList.

@Test
public void testListQuickList() {
    KVEntry builder = handlerTest(RDB_TYPE_LIST_QUICKLIST, () -> {
        List<byte[]> values = new ArrayList<>();
        values.add("v1".getBytes());
        values.add("v2".getBytes());
        return values;
    });
    List<String> va = (List<String>) builder.getValue();
    Assert.assertNotNull(va);
    Assert.assertEquals(2, va.size());
    Assert.assertEquals("v1", va.get(0));
    Assert.assertEquals("v2", va.get(1));
}
Also used : KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) KeyStringValueList(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueList) List(java.util.List) BatchedKeyStringValueString(com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyStringValueString) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString) Test(org.junit.Test)

Example 5 with KVEntry

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

the class RedisEventHandlerTest method testList.

@Test
public void testList() {
    KVEntry builder = handlerTest(RDB_TYPE_LIST, () -> {
        List<byte[]> values = new ArrayList<>();
        values.add("a".getBytes());
        return values;
    });
    List<String> va = (List) builder.getValue();
    Assert.assertNotNull(va);
    Assert.assertEquals(1, va.size());
    Assert.assertEquals("a", va.get(0));
}
Also used : KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) KeyStringValueList(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueList) List(java.util.List) BatchedKeyStringValueString(com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyStringValueString) KeyStringValueString(com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString) Test(org.junit.Test)

Aggregations

KVEntry (org.apache.rocketmq.connect.redis.pojo.KVEntry)118 Test (org.junit.Test)114 List (java.util.List)34 Map (java.util.Map)20 BatchedKeyStringValueString (com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyStringValueString)13 KeyStringValueString (com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueString)12 HashMap (java.util.HashMap)8 KeyStringValueList (com.moilioncircle.redis.replicator.rdb.datatype.KeyStringValueList)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 HSetParser (org.apache.rocketmq.connect.redis.parser.HSetParser)5 HmSetParser (org.apache.rocketmq.connect.redis.parser.HmSetParser)5 LSetParser (org.apache.rocketmq.connect.redis.parser.LSetParser)5 MSetParser (org.apache.rocketmq.connect.redis.parser.MSetParser)5 ZSetEntry (com.moilioncircle.redis.replicator.rdb.datatype.ZSetEntry)3 BatchedKeyValuePair (com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyValuePair)3 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)3 IOException (java.io.IOException)3 Config (org.apache.rocketmq.connect.redis.common.Config)3 DefaultRedisEventHandler (org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler)3