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"));
}
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));
}
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;
}
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);
}
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;
}
Aggregations