Search in sources :

Example 1 with WorkerSourceTask

use of org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerSourceTask 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

JSONObject (com.alibaba.fastjson.JSONObject)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConnectKeyValue (org.apache.rocketmq.connect.runtime.common.ConnectKeyValue)1 WorkerConnector (org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerConnector)1 WorkerSourceTask (org.apache.rocketmq.connect.runtime.connectorwrapper.WorkerSourceTask)1 DefaultConnectorContext (org.apache.rocketmq.connect.runtime.service.DefaultConnectorContext)1 Before (org.junit.Before)1 Mockito.anyString (org.mockito.Mockito.anyString)1