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