-
Notifications
You must be signed in to change notification settings - Fork 24
/
StandaloneTest.java
59 lines (49 loc) · 2.34 KB
/
StandaloneTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.rrc.bigdata;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.kafka.connect.cli.ConnectStandalone;
import org.junit.Test;
public class StandaloneTest {
@Test
public void runTest() throws Exception {
String[] params = new String[2];
String standalone = this.getClass().getClassLoader().getResource("connect-standalone.properties").getPath();
System.out.println(standalone);
params[0] = standalone;
String sink = this.getClass().getClassLoader().getResource("json-sink-clickhouse.properties").getPath();
System.out.println(sink);
params[1] = sink;
ConnectStandalone.main(params);
}
@Test
public void validateTest() throws Exception {
String host = "localhost:8083";
String connectorClass = "com.rrc.bigdata.connector.JsonSinkClickHouseConnector";
String params = String.format("{" +
" \"name\": \"SinkClickHouseConnector\"," +
" \"connector.class\": \"%s\"," +
" \"topics\": \"topic\"," +
" \"tasks.max\": \"1\"," +
" \"clickhouse.jdbc.port\": \"\"," +
" \"clickhouse.optimize\": \"\"," +
" \"clickhouse.sink.tables\": \"\"," +
" \"clickhouse.hosts\": \"s\"," +
" \"clickhouse.sink.database\": \"\"" +
" }", connectorClass);
String url = String.format("http://%s/connector-plugins/%s/config/validate", host, connectorClass);
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPut put = new HttpPut(url);
StringEntity stringEntity = new StringEntity(params);
put.setEntity(stringEntity);
put.setHeader("Content-Type", "application/json;charset=UTF-8");
CloseableHttpResponse httpResponse = httpClient.execute(put);
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity, "UTF-8");
System.out.println(result);
}
}