change test case

This commit is contained in:
zyyang 2021-10-12 17:47:08 +08:00
parent 5da6e34d5c
commit ff87a6bcff
4 changed files with 20 additions and 9 deletions

View File

@ -38,7 +38,7 @@ public class JniConnection {
} }
} }
public long open(String host, int port, String dbname, String user, String password) { public void open(String host, int port, String dbname, String user, String password) {
if (this.psql != JNI_NULL_POINTER) { if (this.psql != JNI_NULL_POINTER) {
close(); close();
this.psql = JNI_NULL_POINTER; this.psql = JNI_NULL_POINTER;
@ -49,7 +49,13 @@ public class JniConnection {
String errMsg = getErrMsgImp(0); String errMsg = getErrMsgImp(0);
throw new RuntimeException(errMsg); throw new RuntimeException(errMsg);
} }
return this.psql; }
public long insertOpentsdbJson(String json) {
if (this.psql == JNI_NULL_POINTER) {
throw new RuntimeException("JNI connection is NULL");
}
return insertOpentsdbJson(json, this.psql);
} }
public void close() { public void close() {

View File

@ -73,11 +73,6 @@ public class TDengineWriter extends Writer {
String user = this.writerSliceConfig.getString(USER); String user = this.writerSliceConfig.getString(USER);
String password = this.writerSliceConfig.getString(PASSWORD); String password = this.writerSliceConfig.getString(PASSWORD);
JniConnection connection = new JniConnection(new Properties());
long psql = connection.open(host, port, dbname, user, password);
System.out.println("psql: " + psql);
connection.close();
try { try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8));

View File

@ -81,6 +81,14 @@ JNIEXPORT jint JNICALL Java_com_alibaba_datax_plugin_writer_JniConnection_getAff
JNIEXPORT jint JNICALL Java_com_alibaba_datax_plugin_writer_JniConnection_closeConnectionImp JNIEXPORT jint JNICALL Java_com_alibaba_datax_plugin_writer_JniConnection_closeConnectionImp
(JNIEnv *, jobject, jlong); (JNIEnv *, jobject, jlong);
/*
* Class: com_alibaba_datax_plugin_writer_JniConnection
* Method: insertOpentsdbJson
* Signature: (Ljava/lang/String;J)J
*/
JNIEXPORT jlong JNICALL Java_com_alibaba_datax_plugin_writer_JniConnection_insertOpentsdbJson
(JNIEnv *, jobject, jstring, jlong);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -10,8 +10,10 @@ public class JniConnectionTest {
public void test() { public void test() {
JniConnection connection = new JniConnection(new Properties()); JniConnection connection = new JniConnection(new Properties());
long psql = connection.open("192.168.56.107", 6030, "log", "root", "taosdata"); connection.open("192.168.56.105", 6030, "log", "root", "taosdata");
System.out.println("psql: " + psql);
String json = "{\"metric\":\"weather.temperature\",\"timestamp\":1609430400000,\"value\":123,\"tags\":{\"location\":\"beijing\",\"id\":123}}";
connection.insertOpentsdbJson(json);
connection.close(); connection.close();
} }