Search in sources :

Example 11 with KVEntry

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

the class RedisEventHandlerTest method testListZipList.

@Test
public void testListZipList() {
    KVEntry builder = handlerTest(RDB_TYPE_LIST_ZIPLIST, () -> {
        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 12 with KVEntry

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

the class RedisEventHandlerTest method testModule.

@Test
public void testModule() {
    KVEntry builder = handlerTest(RDB_TYPE_MODULE, () -> {
        Module module = new Module() {

            @Override
            public int hashCode() {
                return super.hashCode();
            }

            @Override
            public boolean equals(Object obj) {
                return super.equals(obj);
            }

            @Override
            protected Object clone() throws CloneNotSupportedException {
                return super.clone();
            }

            @Override
            public String toString() {
                return super.toString();
            }

            @Override
            protected void finalize() throws Throwable {
                super.finalize();
            }
        };
        return module;
    });
    Module va = (Module) builder.getValue();
    Assert.assertNotNull(va);
}
Also used : KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) Module(com.moilioncircle.redis.replicator.rdb.datatype.Module) Test(org.junit.Test)

Example 13 with KVEntry

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

the class RedisEventHandlerTest method testHashZipList.

@Test
public void testHashZipList() {
    KVEntry builder = handlerTest(RDB_TYPE_HASH_ZIPLIST, () -> {
        Map<byte[], byte[]> values = new HashMap<>();
        values.put("k1".getBytes(), "v1".getBytes());
        values.put("k2".getBytes(), "v2".getBytes());
        return values;
    });
    Map<String, String> va = (Map<String, String>) builder.getValue();
    Assert.assertNotNull(va);
    Assert.assertEquals(2, va.size());
    Assert.assertEquals("v1", va.get("k1"));
    Assert.assertEquals("v2", va.get("k2"));
}
Also used : KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) HashMap(java.util.HashMap) 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) Test(org.junit.Test)

Example 14 with KVEntry

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

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

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