Search in sources :

Example 6 with ConnectKeyValue

use of org.apache.rocketmq.connect.runtime.common.ConnectKeyValue in project rocketmq-externals by apache.

the class ConfigManagementServiceImplTest method testGetConnectorConfigs.

@Test
public void testGetConnectorConfigs() throws Exception {
    Map<String, ConnectKeyValue> connectorConfigs = configManagementService.getConnectorConfigs();
    ConnectKeyValue connectKeyValue = connectorConfigs.get(connectorName);
    assertNull(connectKeyValue);
    configManagementService.putConnectorConfig(connectorName, this.connectKeyValue);
    connectorConfigs = configManagementService.getConnectorConfigs();
    connectKeyValue = connectorConfigs.get(connectorName);
    assertNotNull(connectKeyValue);
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) Test(org.junit.Test)

Example 7 with ConnectKeyValue

use of org.apache.rocketmq.connect.runtime.common.ConnectKeyValue in project rocketmq-externals by apache.

the class DefaultAllocateConnAndTaskStrategyTest method testAllocate.

@Test
public void testAllocate() {
    DefaultAllocateConnAndTaskStrategy defaultAllocateConnAndTaskStrategy = new DefaultAllocateConnAndTaskStrategy();
    List<String> allWorker = new ArrayList<String>() {

        {
            add("workId1");
            add("workId2");
            add("workId3");
        }
    };
    String curWorker = "workId3";
    Map<String, ConnectKeyValue> connectorConfigs = new HashMap<String, ConnectKeyValue>() {

        {
            put("connectorConfig1", new ConnectKeyValue());
            put("connectorConfig2", new ConnectKeyValue());
            put("connectorConfig3", new ConnectKeyValue());
        }
    };
    ConnectKeyValue connectKeyValue1 = new ConnectKeyValue();
    ConnectKeyValue connectKeyValue2 = new ConnectKeyValue();
    ConnectKeyValue connectKeyValue3 = new ConnectKeyValue();
    ConnectKeyValue connectKeyValue4 = new ConnectKeyValue();
    ConnectKeyValue connectKeyValue5 = new ConnectKeyValue();
    ConnectKeyValue connectKeyValue6 = new ConnectKeyValue();
    List<ConnectKeyValue> taskConfig1 = new ArrayList<ConnectKeyValue>() {

        {
            add(connectKeyValue1);
        }
    };
    List<ConnectKeyValue> taskConfig2 = new ArrayList<ConnectKeyValue>() {

        {
            add(connectKeyValue2);
            add(connectKeyValue3);
        }
    };
    List<ConnectKeyValue> taskConfig3 = new ArrayList<ConnectKeyValue>() {

        {
            add(connectKeyValue4);
            add(connectKeyValue5);
            add(connectKeyValue6);
        }
    };
    Map<String, List<ConnectKeyValue>> taskConfigs = new HashMap<String, List<ConnectKeyValue>>() {

        {
            put("connectorConfig1", taskConfig1);
            put("connectorConfig2", taskConfig2);
            put("connectorConfig3", taskConfig3);
        }
    };
    ConnAndTaskConfigs allocate = defaultAllocateConnAndTaskStrategy.allocate(allWorker, curWorker, connectorConfigs, taskConfigs);
    assertNotNull(allocate);
    Map<String, ConnectKeyValue> connectorConfigs3 = allocate.getConnectorConfigs();
    assertNotNull(connectorConfigs3);
    assertNotNull(connectorConfigs3.get("connectorConfig3"));
    assertNull(connectorConfigs3.get("connectorConfig2"));
    assertNull(connectorConfigs3.get("connectorConfig1"));
    Map<String, List<ConnectKeyValue>> taskConfigs1 = allocate.getTaskConfigs();
    assertNotNull(taskConfigs1);
    assertNull(taskConfigs1.get("connectorConfig1"));
    List<ConnectKeyValue> connectorConfig1 = taskConfigs1.get("connectorConfig2");
    assertNotNull(connectorConfig1);
    assertEquals(1, connectorConfig1.size());
    assertEquals(connectKeyValue3, connectorConfig1.get(0));
    List<ConnectKeyValue> connectorConfig2 = taskConfigs1.get("connectorConfig3");
    assertNotNull(connectorConfig2);
    assertEquals(1, connectorConfig2.size());
    assertEquals(connectKeyValue6, connectorConfig2.get(0));
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ConnAndTaskConfigs(org.apache.rocketmq.connect.runtime.common.ConnAndTaskConfigs) Test(org.junit.Test)

Example 8 with ConnectKeyValue

use of org.apache.rocketmq.connect.runtime.common.ConnectKeyValue in project rocketmq-externals by apache.

the class WorkerTest method init.

@Before
public void init() {
    connectConfig = new ConnectConfig();
    connectConfig.setHttpPort(8081);
    connectConfig.setStorePathRootDir(System.getProperty("user.home") + File.separator + "testConnectorStore");
    connectConfig.setNamesrvAddr("localhost:9876");
    worker = new Worker(connectConfig, positionManagementService, offsetManagementService, plugin);
    Set<WorkerConnector> workingConnectors = new HashSet<>();
    for (int i = 0; i < 3; i++) {
        ConnectKeyValue connectKeyValue = new ConnectKeyValue();
        connectKeyValue.getProperties().put("key1", "TEST-CONN-" + i + "1");
        connectKeyValue.getProperties().put("key2", "TEST-CONN-" + i + "2");
        workingConnectors.add(new WorkerConnector("TEST-CONN-" + i, new TestConnector(), connectKeyValue, connectorContext));
    }
    worker.setWorkingConnectors(workingConnectors);
    assertThat(worker.getWorkingConnectors().size()).isEqualTo(3);
    Set<Runnable> runnables = new HashSet<>();
    for (int i = 0; i < 3; i++) {
        ConnectKeyValue connectKeyValue = new ConnectKeyValue();
        connectKeyValue.getProperties().put("key1", "TEST-TASK-" + i + "1");
        connectKeyValue.getProperties().put("key2", "TEST-TASK-" + i + "2");
        runnables.add(new WorkerSourceTask("TEST-CONN-" + i, new TestSourceTask(), connectKeyValue, new TestPositionManageServiceImpl(), new TestConverter(), producer, new AtomicReference(WorkerState.STARTED)));
    }
    worker.setWorkingTasks(runnables);
    assertThat(worker.getWorkingTasks().size()).isEqualTo(3);
    worker.start();
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) ConnectConfig(org.apache.rocketmq.connect.runtime.config.ConnectConfig) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 9 with ConnectKeyValue

use of org.apache.rocketmq.connect.runtime.common.ConnectKeyValue in project rocketmq-externals by apache.

the class WorkerTest method testStartConnectors.

@Test
public void testStartConnectors() throws Exception {
    Map<String, ConnectKeyValue> connectorConfigs = new HashMap<>();
    for (int i = 1; i < 4; i++) {
        ConnectKeyValue connectKeyValue = new ConnectKeyValue();
        connectKeyValue.getProperties().put("key1", "TEST-CONN-" + i + "1");
        connectKeyValue.getProperties().put("key2", "TEST-CONN-" + i + "2");
        connectKeyValue.getProperties().put(RuntimeConfigDefine.CONNECTOR_CLASS, TestConnector.class.getName());
        connectorConfigs.put("TEST-CONN-" + i, connectKeyValue);
    }
    worker.startConnectors(connectorConfigs, connectController);
    Set<WorkerConnector> connectors = worker.getWorkingConnectors();
    assertThat(connectors.size()).isEqualTo(3);
    for (WorkerConnector wc : connectors) {
        assertThat(wc.getConnectorName()).isIn("TEST-CONN-1", "TEST-CONN-2", "TEST-CONN-3");
    }
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with ConnectKeyValue

use of org.apache.rocketmq.connect.runtime.common.ConnectKeyValue in project rocketmq-externals by apache.

the class RestHandlerTest method init.

@Before
public void init() throws Exception {
    workerState = new AtomicReference<>(WorkerState.STARTED);
    when(connectController.getConnectConfig()).thenReturn(connectConfig);
    when(connectConfig.getHttpPort()).thenReturn(8081);
    when(connectController.getConfigManagementService()).thenReturn(configManagementService);
    when(configManagementService.putConnectorConfig(anyString(), any(ConnectKeyValue.class))).thenReturn("");
    String connectName = "testConnector";
    ConnectKeyValue connectKeyValue = new ConnectKeyValue();
    connectKeyValue.put(RuntimeConfigDefine.CONNECTOR_CLASS, "org.apache.rocketmq.connect.runtime.service.TestConnector");
    connectKeyValue.put(RuntimeConfigDefine.SOURCE_RECORD_CONVERTER, "source-record-converter");
    ConnectKeyValue connectKeyValue1 = new ConnectKeyValue();
    connectKeyValue1.put(RuntimeConfigDefine.CONNECTOR_CLASS, "org.apache.rocketmq.connect.runtime.service.TestConnector");
    connectKeyValue1.put(RuntimeConfigDefine.SOURCE_RECORD_CONVERTER, "source-record-converter1");
    List<ConnectKeyValue> connectKeyValues = new ArrayList<ConnectKeyValue>(8) {

        {
            add(connectKeyValue);
        }
    };
    connectorConfigs = new HashMap<String, ConnectKeyValue>() {

        {
            put(connectName, connectKeyValue);
        }
    };
    taskConfigs = new HashMap<String, List<ConnectKeyValue>>() {

        {
            put(connectName, connectKeyValues);
        }
    };
    when(configManagementService.getConnectorConfigs()).thenReturn(connectorConfigs);
    when(configManagementService.getTaskConfigs()).thenReturn(taskConfigs);
    aliveWorker = new ArrayList<String>() {

        {
            add("workerId1");
            add("workerId2");
        }
    };
    when(connectController.getClusterManagementService()).thenReturn(clusterManagementService);
    when(clusterManagementService.getAllAliveWorkers()).thenReturn(aliveWorker);
    sourcePartition = "127.0.0.13306".getBytes("UTF-8");
    JSONObject jsonObject = new JSONObject();
    // jsonObject.put(MysqlConstants.BINLOG_FILENAME, "binlogFilename");
    // jsonObject.put(MysqlConstants.NEXT_POSITION, "100");
    sourcePosition = jsonObject.toJSONString().getBytes();
    positions = new HashMap<ByteBuffer, ByteBuffer>() {

        {
            put(ByteBuffer.wrap(sourcePartition), ByteBuffer.wrap(sourcePosition));
        }
    };
    WorkerConnector workerConnector1 = new WorkerConnector("testConnectorName1", connector, connectKeyValue, new DefaultConnectorContext("testConnectorName1", connectController));
    WorkerConnector workerConnector2 = new WorkerConnector("testConnectorName2", connector, connectKeyValue1, new DefaultConnectorContext("testConnectorName2", connectController));
    workerConnectors = new HashSet<WorkerConnector>() {

        {
            add(workerConnector1);
            add(workerConnector2);
        }
    };
    WorkerSourceTask workerSourceTask1 = new WorkerSourceTask("testConnectorName1", sourceTask, connectKeyValue, positionManagementServiceImpl, converter, producer, workerState);
    WorkerSourceTask workerSourceTask2 = new WorkerSourceTask("testConnectorName2", sourceTask, connectKeyValue1, positionManagementServiceImpl, converter, producer, workerState);
    workerTasks = new HashSet<Runnable>() {

        {
            add(workerSourceTask1);
            add(workerSourceTask2);
        }
    };
    when(connectController.getWorker()).thenReturn(worker);
    when(worker.getWorkingConnectors()).thenReturn(workerConnectors);
    when(worker.getWorkingTasks()).thenReturn(workerTasks);
    restHandler = new RestHandler(connectController);
    httpClient = HttpClientBuilder.create().build();
}
Also used : WorkerConnector(org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector) WorkerSourceTask(org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerSourceTask) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) ByteBuffer(java.nio.ByteBuffer) ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) DefaultConnectorContext(org.apache.rocketmq.connect.runtime.service.DefaultConnectorContext) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) Before(org.junit.Before)

Aggregations

ConnectKeyValue (org.apache.rocketmq.connect.runtime.common.ConnectKeyValue)33 HashMap (java.util.HashMap)15 ArrayList (java.util.ArrayList)13 List (java.util.List)12 Test (org.junit.Test)12 Map (java.util.Map)9 ConnAndTaskConfigs (org.apache.rocketmq.connect.runtime.common.ConnAndTaskConfigs)8 Before (org.junit.Before)4 HashSet (java.util.HashSet)3 WorkerConnector (org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector)3 JSONObject (com.alibaba.fastjson.JSONObject)2 Connector (io.openmessaging.connector.api.Connector)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConnectConfig (org.apache.rocketmq.connect.runtime.config.ConnectConfig)2 DefaultConnectorContext (org.apache.rocketmq.connect.runtime.service.DefaultConnectorContext)2 PluginClassLoader (org.apache.rocketmq.connect.runtime.utils.PluginClassLoader)2 KeyValue (io.openmessaging.KeyValue)1 Task (io.openmessaging.connector.api.Task)1 Converter (io.openmessaging.connector.api.data.Converter)1 SinkTask (io.openmessaging.connector.api.sink.SinkTask)1