Search in sources :

Example 1 with RedisURI

use of com.moilioncircle.redis.replicator.RedisURI in project rocketmq-externals by apache.

the class DefaultRedisEventProcessor method startReplicatorAsync.

/**
 * start redis replicator async
 *
 * @throws IOException
 */
private void startReplicatorAsync(String replId, Long offset) throws IllegalStateException, IOException {
    RedisURI uri = this.config.getRedisUri();
    if (uri == null) {
        throw new IllegalStateException("redis uri error.");
    }
    this.replicator = new com.moilioncircle.redis.replicator.RedisReplicator(uri);
    this.dress(this.replicator);
    // set listeners
    this.replicator.addEventListener(eventListener);
    this.replicator.addExceptionListener(exceptionListener);
    this.replicator.addCloseListener(closeListener);
    if (this.config.getReplId() != null) {
        this.replicator.getConfiguration().setReplId(replId);
    }
    if (this.config.getOffset() != null && this.config.getOffset() >= -1) {
        this.replicator.getConfiguration().setReplOffset(offset);
    }
    new Thread(() -> {
        try {
            this.replicator.open();
        } catch (IOException e) {
            LOGGER.error("start replicator error. {}", e);
            try {
                this.stop();
            } catch (IOException ie) {
            }
        }
    }).start();
}
Also used : RedisURI(com.moilioncircle.redis.replicator.RedisURI) IOException(java.io.IOException)

Example 2 with RedisURI

use of com.moilioncircle.redis.replicator.RedisURI in project rocketmq-externals by apache.

the class ConfigTest method test.

@Test
public void test() {
    Config config = new Config();
    config.setRedisAddr("127.0.0.1");
    config.setRedisPort(6379);
    config.setRedisPassword("123456");
    config.setTimeout(500);
    config.setSyncMod(SyncMod.CUSTOM_OFFSET.name());
    config.setOffset(65535L);
    config.setReplId("c18cece63c7b16851a6f387f52dbbb9eee07e46f");
    config.setCommands("SET,GET");
    config.setPosition(3926872L);
    config.setEventCommitRetryInterval(1000L);
    config.setEventCommitRetryTimes(10);
    Assert.assertEquals("127.0.0.1", config.getRedisAddr());
    Assert.assertEquals(6379, (int) config.getRedisPort());
    Assert.assertEquals("123456", config.getRedisPassword());
    Assert.assertEquals(500, (int) config.getTimeout());
    Assert.assertEquals(SyncMod.CUSTOM_OFFSET, config.getSyncMod());
    Assert.assertEquals(65535L, (long) config.getOffset());
    Assert.assertEquals("c18cece63c7b16851a6f387f52dbbb9eee07e46f", config.getReplId());
    Assert.assertEquals("SET,GET", config.getCommands());
    Assert.assertEquals(3926872L, (long) config.getPosition());
    Assert.assertEquals(1000L, (long) config.getEventCommitRetryInterval());
    RedisURI redisURI = config.getRedisUri();
    Assert.assertNotNull(redisURI);
    ByteBuffer byteBuffer = config.getPositionPartitionKey();
    Assert.assertNotNull(byteBuffer);
    Set<String> set = Config.getRequestConfig();
    Assert.assertNotNull(set);
    KeyValue keyValue = new DefaultKeyValue();
    keyValue.put("a", "B");
    String bo = Config.checkConfig(keyValue);
    Assert.assertNotNull(bo);
    keyValue.put("redisAddr", "127.0.0.1");
    keyValue.put("redisPort", "6379");
    bo = Config.checkConfig(keyValue);
    Assert.assertNotNull(bo);
    keyValue.put("redisPassword", "1234567");
    bo = Config.checkConfig(keyValue);
    Assert.assertNull(bo);
    keyValue.put("syncMod", SyncMod.LAST_OFFSET.name());
    Config config1 = new Config();
    config1.load(keyValue);
    Assert.assertEquals("127.0.0.1", config.getRedisAddr());
    Assert.assertTrue(6379 == config1.getRedisPort());
    Assert.assertEquals("1234567", config1.getRedisPassword());
    Assert.assertEquals(SyncMod.LAST_OFFSET, config1.getSyncMod());
    String err = config1.load(null);
    Assert.assertNotNull(err);
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) Config(org.apache.rocketmq.connect.redis.common.Config) RedisURI(com.moilioncircle.redis.replicator.RedisURI) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 3 with RedisURI

use of com.moilioncircle.redis.replicator.RedisURI in project rocketmq-externals by apache.

the class ConfigTest method testNull.

@Test
public void testNull() {
    Config config = new Config();
    RedisURI redisURI = config.getRedisUri();
    ByteBuffer po = config.getPositionPartitionKey();
    Assert.assertNull(redisURI);
    Assert.assertNull(po);
    config.setRedisAddr("127.0.0.1");
    redisURI = config.getRedisUri();
    po = config.getPositionPartitionKey();
    Assert.assertNull(redisURI);
    Assert.assertNull(po);
    config.setRedisPassword("123456");
    redisURI = config.getRedisUri();
    po = config.getPositionPartitionKey();
    Assert.assertNull(redisURI);
    Assert.assertNull(po);
    config.setRedisPort(6379);
    redisURI = config.getRedisUri();
    po = config.getPositionPartitionKey();
    Assert.assertNotNull(redisURI);
    Assert.assertNotNull(po);
}
Also used : Config(org.apache.rocketmq.connect.redis.common.Config) RedisURI(com.moilioncircle.redis.replicator.RedisURI) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

RedisURI (com.moilioncircle.redis.replicator.RedisURI)3 ByteBuffer (java.nio.ByteBuffer)2 Config (org.apache.rocketmq.connect.redis.common.Config)2 Test (org.junit.Test)2 KeyValue (io.openmessaging.KeyValue)1 DefaultKeyValue (io.openmessaging.internal.DefaultKeyValue)1 IOException (java.io.IOException)1