Search in sources :

Example 11 with ConnectKeyValue

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

the class TransferUtilsTest method testKeyValueList2String2KeyValueList.

@Test
public void testKeyValueList2String2KeyValueList() {
    ConnectKeyValue connectKeyValue = new ConnectKeyValue();
    connectKeyValue.put("key1", 1);
    connectKeyValue.put("key2", 2L);
    connectKeyValue.put("key3", 3.0);
    connectKeyValue.put("key4", "4");
    List<ConnectKeyValue> connectKeyValues = new ArrayList<ConnectKeyValue>(8) {

        {
            add(connectKeyValue);
        }
    };
    String s = TransferUtils.keyValueListToString(connectKeyValues);
    List<ConnectKeyValue> connectKeyValues1 = TransferUtils.stringToKeyValueList(s);
    assertNotNull(connectKeyValues1);
    ConnectKeyValue connectKeyValue1 = connectKeyValues1.get(0);
    assertEquals(1, connectKeyValue1.getInt("key1"));
    assertEquals(2L, connectKeyValue1.getLong("key2"));
    assertTrue(Objects.equals(3.0, connectKeyValue1.getDouble("key3")));
    assertEquals("4", connectKeyValue1.getString("key4"));
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with ConnectKeyValue

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

the class TransferUtilsTest method testToJsonStringToConnAndTaskConfigs.

@Test
public void testToJsonStringToConnAndTaskConfigs() {
    String connectName = "testConnector";
    ConnectKeyValue connectKeyValue = new ConnectKeyValue();
    connectKeyValue.put(RuntimeConfigDefine.CONNECTOR_CLASS, "io.openmessaging.connect.runtime.service.TestConnector");
    connectKeyValue.put(RuntimeConfigDefine.SOURCE_RECORD_CONVERTER, "source-record-converter");
    List<ConnectKeyValue> connectKeyValues = new ArrayList<ConnectKeyValue>(8) {

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

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

        {
            put(connectName, connectKeyValues);
        }
    };
    ConnAndTaskConfigs connAndTaskConfigs = new ConnAndTaskConfigs();
    connAndTaskConfigs.setConnectorConfigs(connectorConfigs);
    connAndTaskConfigs.setTaskConfigs(taskConfigs);
    Map<String, String> connectorMap = new HashMap<>();
    Map<String, String> taskMap = new HashMap<>();
    for (String key : connAndTaskConfigs.getConnectorConfigs().keySet()) {
        connectorMap.put(key, TransferUtils.keyValueToString(connAndTaskConfigs.getConnectorConfigs().get(key)));
    }
    for (String key : connAndTaskConfigs.getTaskConfigs().keySet()) {
        taskMap.put(key, TransferUtils.keyValueListToString(connAndTaskConfigs.getTaskConfigs().get(key)));
    }
    String s = TransferUtils.toJsonString(connectorMap, taskMap);
    ConnAndTaskConfigs connAndTaskConfigs1 = TransferUtils.toConnAndTaskConfigs(s);
    Map<String, ConnectKeyValue> connectorConfigs1 = connAndTaskConfigs1.getConnectorConfigs();
    assertNotNull(connAndTaskConfigs1);
    ConnectKeyValue connectKeyValue1 = connectorConfigs1.get(connectName);
    assertNotNull(connectKeyValue1);
    assertEquals("io.openmessaging.connect.runtime.service.TestConnector", connectKeyValue1.getString(RuntimeConfigDefine.CONNECTOR_CLASS));
    assertEquals("source-record-converter", connectKeyValue1.getString(RuntimeConfigDefine.SOURCE_RECORD_CONVERTER));
    Map<String, List<ConnectKeyValue>> taskConfigs1 = connAndTaskConfigs1.getTaskConfigs();
    List<ConnectKeyValue> connectKeyValues1 = taskConfigs1.get(connectName);
    assertNotNull(connectKeyValues1);
    ConnectKeyValue connectKeyValue2 = connectKeyValues1.get(0);
    assertNotNull(connectKeyValue2);
    assertEquals("io.openmessaging.connect.runtime.service.TestConnector", connectKeyValue2.getString(RuntimeConfigDefine.CONNECTOR_CLASS));
    assertEquals("source-record-converter", connectKeyValue2.getString(RuntimeConfigDefine.SOURCE_RECORD_CONVERTER));
}
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 13 with ConnectKeyValue

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

the class TransferUtils method stringToKeyValueList.

public static List<ConnectKeyValue> stringToKeyValueList(String json) {
    List<ConnectKeyValue> resultList = new ArrayList<>();
    if (null == json) {
        return resultList;
    }
    List<Map<String, String>> list = JSON.parseObject(json, List.class);
    for (Map<String, String> map : list) {
        ConnectKeyValue keyValue = new ConnectKeyValue();
        for (String key : map.keySet()) {
            keyValue.put(key, map.get(key));
        }
        resultList.add(keyValue);
    }
    return resultList;
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 14 with ConnectKeyValue

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

the class TransferUtils method keyValueListToString.

public static String keyValueListToString(List<ConnectKeyValue> keyValueList) {
    List<Map<String, String>> resList = new ArrayList<>();
    if (null == keyValueList || 0 == keyValueList.size()) {
        return JSON.toJSONString(resList);
    }
    for (ConnectKeyValue keyValue : keyValueList) {
        Map<String, String> resMap = new HashMap<>();
        for (String key : keyValue.keySet()) {
            resMap.put(key, keyValue.getString(key));
        }
        resList.add(resMap);
    }
    return JSON.toJSONString(resList);
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with ConnectKeyValue

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

the class TransferUtils method stringToKeyValue.

public static ConnectKeyValue stringToKeyValue(String json) {
    if (null == json) {
        return new ConnectKeyValue();
    }
    Map<String, String> map = JSON.parseObject(json, Map.class);
    ConnectKeyValue keyValue = new ConnectKeyValue();
    for (String key : map.keySet()) {
        keyValue.put(key, map.get(key));
    }
    return keyValue;
}
Also used : ConnectKeyValue(org.apache.rocketmq.connect.runtime.common.ConnectKeyValue)

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