Search in sources :

Example 11 with KeyValue

use of io.openmessaging.KeyValue 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 12 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-externals by apache.

the class RedisSourceTaskTest method initAndStartTask.

@Before
public void initAndStartTask() {
    try {
        initKeyValue();
        this.task = new RedisSourceTask();
        this.task.initialize(new SourceTaskContext() {

            @Override
            public PositionStorageReader positionStorageReader() {
                return new PositionStorageReader() {

                    @Override
                    public ByteBuffer getPosition(ByteBuffer byteBuffer) {
                        return null;
                    }

                    @Override
                    public Map<ByteBuffer, ByteBuffer> getPositions(Collection<ByteBuffer> collection) {
                        return null;
                    }
                };
            }

            @Override
            public KeyValue configs() {
                return keyValue;
            }
        });
        this.task.start(this.keyValue);
    } catch (JedisConnectionException e) {
    }
}
Also used : KeyValue(io.openmessaging.KeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) SourceTaskContext(io.openmessaging.connector.api.source.SourceTaskContext) PositionStorageReader(io.openmessaging.connector.api.PositionStorageReader) RedisSourceTask(org.apache.rocketmq.connect.redis.connector.RedisSourceTask) ByteBuffer(java.nio.ByteBuffer) Map(java.util.Map) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Before(org.junit.Before)

Example 13 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-externals by apache.

the class RabbitmqSourceConnectorTest method verifyAndSetConfig.

@Test
public void verifyAndSetConfig() {
    KeyValue keyValue = new DefaultKeyValue();
    for (String requestKey : RabbitmqConfig.REQUEST_CONFIG) {
        assertEquals(rabbitmqSourceConnector.verifyAndSetConfig(keyValue), "Request config key: " + requestKey);
        keyValue.put(requestKey, requestKey);
    }
    assertEquals(rabbitmqSourceConnector.verifyAndSetConfig(keyValue), "");
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) Test(org.junit.Test)

Example 14 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-externals by apache.

the class RabbitmqSourceTaskTest method getPatternProcessor.

public void getPatternProcessor(Replicator replicator) {
    KeyValue kv = new DefaultKeyValue();
    kv.put("rabbitmqUrl", "amqp://112.74.48.251:5672");
    kv.put("rabbitmqUsername", "admin");
    kv.put("rabbitmqPassword", "admin");
    kv.put("destinationType", "queue");
    kv.put("destinationName", "test-queue");
    RabbitmqConfig config = new RabbitmqConfig();
    config.load(kv);
    replicator = new Replicator(config, null);
    RabbitmqSourceTask task = new RabbitmqSourceTask();
    assertEquals(RabbitMQPatternProcessor.class, task.getPatternProcessor(replicator).getClass());
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) KeyValue(io.openmessaging.KeyValue) DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) RabbitmqConfig(org.apache.rocketmq.connect.rabbitmq.RabbitmqConfig) Replicator(org.apache.rocketmq.connect.jms.Replicator)

Example 15 with KeyValue

use of io.openmessaging.KeyValue in project rocketmq-externals by apache.

the class WorkerDirectTask method starkSinkTask.

private void starkSinkTask() {
    sinkTask.initialize(new SinkTaskContext() {

        @Override
        public KeyValue configs() {
            return taskConfig;
        }

        @Override
        public void resetOffset(QueueMetaData queueMetaData, Long offset) {
        }

        @Override
        public void resetOffset(Map<QueueMetaData, Long> offsets) {
        }

        @Override
        public void pause(List<QueueMetaData> queues) {
        }

        @Override
        public void resume(List<QueueMetaData> queues) {
        }
    });
    sinkTask.start(taskConfig);
    log.info("Sink task start, config:{}", JSON.toJSONString(taskConfig));
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) KeyValue(io.openmessaging.KeyValue) SinkTaskContext(io.openmessaging.connector.api.sink.SinkTaskContext) QueueMetaData(io.openmessaging.connector.api.common.QueueMetaData)

Aggregations

KeyValue (io.openmessaging.KeyValue)39 DefaultKeyValue (io.openmessaging.internal.DefaultKeyValue)29 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)9 Map (java.util.Map)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ConnectKeyValue (org.apache.rocketmq.connect.runtime.common.ConnectKeyValue)5 BytesMessage (io.openmessaging.BytesMessage)4 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)4 PositionStorageReader (io.openmessaging.connector.api.PositionStorageReader)3 SourceTaskContext (io.openmessaging.connector.api.source.SourceTaskContext)3 ByteBuffer (java.nio.ByteBuffer)3 QueueMetaData (io.openmessaging.connector.api.common.QueueMetaData)2 SinkTaskContext (io.openmessaging.connector.api.sink.SinkTaskContext)2 BytesMessageImpl (io.openmessaging.rocketmq.domain.BytesMessageImpl)2 Set (java.util.Set)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)2 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)2