Search in sources :

Example 61 with KVEntry

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

the class RedisEventHandlerTest method test.

@Test
public void test() {
    Config config = getConfig();
    RedisEventHandler handler = new DefaultRedisEventHandler(config);
    KVEntry entry = getBuilder();
    KVEntry res = null;
    Exception ex = null;
    try {
        res = handler.handleCommand(replId, offset, entry);
    } catch (Exception e) {
        e.printStackTrace();
        ex = e;
    }
    Assert.assertEquals("c18cece63c7b16851a6f387f52dbbb9eee07e46f", res.getSourceId());
    Assert.assertTrue(res.getOffset() == 3926872L);
    Assert.assertNull(ex);
    AuxField auxField = new AuxField("a", "b");
    try {
        res = handler.handleOtherEvent(replId, offset, auxField);
    } catch (Exception e) {
        e.printStackTrace();
        ex = e;
    }
    Assert.assertNull(res);
    Assert.assertNull(ex);
    BatchedKeyValuePair pair = new BatchedKeyStringValueString();
    pair.setKey("A".getBytes());
    pair.setValue("B".getBytes());
    try {
        res = handler.handleBatchKVString(replId, offset, pair);
    } catch (Exception e) {
        e.printStackTrace();
        ex = e;
    }
    Assert.assertNull(res);
    Assert.assertNull(ex);
}
Also used : AuxField(com.moilioncircle.redis.replicator.rdb.datatype.AuxField) BatchedKeyStringValueString(com.moilioncircle.redis.replicator.rdb.iterable.datatype.BatchedKeyStringValueString) 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) Config(org.apache.rocketmq.connect.redis.common.Config) DefaultRedisEventHandler(org.apache.rocketmq.connect.redis.handler.DefaultRedisEventHandler) Test(org.junit.Test)

Example 62 with KVEntry

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

the class RedisEventHandlerTest method testSet.

@Test
public void testSet() {
    KVEntry builder = handlerTest(RDB_TYPE_SET, () -> {
        Set<byte[]> values = new HashSet<>();
        values.add("myValue".getBytes());
        values.add("myValue2".getBytes());
        return values;
    });
    List<String> va = (List<String>) builder.getValue();
    Assert.assertNotNull(va);
    Assert.assertEquals(2, va.size());
    Assert.assertTrue(va.contains("myValue"));
    Assert.assertTrue(va.contains("myValue2"));
}
Also used : KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 63 with KVEntry

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

the class RedisEventHandlerTest method testModule2.

@Test
public void testModule2() {
    KVEntry builder = handlerTest(RDB_TYPE_MODULE_2, () -> {
        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 64 with KVEntry

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

the class RedisEventHandlerTest method testSetIntSet.

@Test
public void testSetIntSet() {
    KVEntry builder = handlerTest(RDB_TYPE_SET_INTSET, () -> {
        Set<byte[]> values = new HashSet<>();
        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.assertTrue(va.contains("v1"));
    Assert.assertTrue(va.contains("v2"));
}
Also used : KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 65 with KVEntry

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

the class RedisEventHandlerTest method testKeyValuePair.

@Test
public void testKeyValuePair() {
    KVEntry kvEntry = handlerTest(RDB_TYPE_STRING, () -> "value".getBytes());
    Assert.assertEquals(replId, kvEntry.getSourceId());
    Assert.assertTrue(kvEntry.getOffset() == 3926872L);
    Assert.assertEquals("key", kvEntry.getKey());
    Assert.assertEquals("value", kvEntry.getValue());
}
Also used : KVEntry(org.apache.rocketmq.connect.redis.pojo.KVEntry) 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