diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 7a421eff2296cc8b61ec6e07174747ef8e224ff0..f1e013e864f4617e04be0c8c5b892c4396c66e79 100755 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -102,6 +102,7 @@ **/*Test.java + **/DatetimeBefore1970Test.java **/AppMemoryLeakTest.java **/AuthenticationTest.java **/TaosInfoMonitorTest.java diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5e4f16a73c3c93456ed67450752af094cd96938c --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBJNIConnectorTest.java @@ -0,0 +1,130 @@ +package com.taosdata.jdbc; + +import org.junit.Test; + +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +public class TSDBJNIConnectorTest { + + public static void main(String[] args) { + try { + TSDBJNIConnector.init("/etc/taos/taos.cfg", "en_US.UTF-8", "", ""); + TSDBJNIConnector connector = new TSDBJNIConnector(); + connector.connect("127.0.0.1", 6030, "test", "root", "taosdata"); + long pSql = connector.executeQuery("show dnodes"); + // if pSql is create/insert/update/delete/alter SQL + if (connector.isUpdateQuery(pSql)) { + connector.freeResultSet(pSql); + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_WITH_EXECUTEQUERY); + } + + List columnMetaDataList = new ArrayList<>(); + + int code = connector.getSchemaMetaData(pSql, columnMetaDataList); + if (code == TSDBConstants.JNI_CONNECTION_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL)); + } + if (code == TSDBConstants.JNI_RESULT_SET_NULL) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_RESULT_SET_NULL)); + } + if (code == TSDBConstants.JNI_NUM_OF_FIELDS_0) { + throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_NUM_OF_FIELDS_0)); + } + + } catch (SQLWarning throwables) { + throwables.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + + @Test + public void isClosed() { + } + + @Test + public void isResultsetClosed() { + } + + @Test + public void init() { + } + + @Test + public void initImp() { + } + + @Test + public void setOptions() { + } + + @Test + public void getTsCharset() { + } + + @Test + public void connect() { + } + + @Test + public void executeQuery() { + } + + @Test + public void getErrCode() { + } + + @Test + public void getErrMsg() { + } + + @Test + public void isUpdateQuery() { + } + + @Test + public void freeResultSet() { + } + + @Test + public void getAffectedRows() { + } + + @Test + public void getSchemaMetaData() { + } + + @Test + public void fetchRow() { + } + + @Test + public void fetchBlock() { + } + + @Test + public void closeConnection() { + } + + @Test + public void subscribe() { + } + + @Test + public void consume() { + } + + @Test + public void unsubscribe() { + } + + @Test + public void validateCreateTableSql() { + } +} \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/FailOverTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/FailOverTest.java index 83295df5274a669ca2fc7fdbba506a97a01cc55c..be2ff94e02e10c14f1229b63762f5a6af7082318 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/FailOverTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/FailOverTest.java @@ -4,7 +4,6 @@ import org.junit.Test; import java.sql.*; import java.text.SimpleDateFormat; -import java.util.Date; import java.util.concurrent.TimeUnit; public class FailOverTest { @@ -18,13 +17,17 @@ public class FailOverTest { long end = System.currentTimeMillis() + 1000 * 60 * 5; while (System.currentTimeMillis() < end) { - try (Connection conn = DriverManager.getConnection(url)) { - Statement stmt = conn.createStatement(); - ResultSet resultSet = stmt.executeQuery("select server_status()"); - resultSet.next(); - int status = resultSet.getInt("server_status()"); - System.out.println(">>>>>>>>>" + sdf.format(new Date()) + " status : " + status); - stmt.close(); + try (Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement()) { + ResultSet rs = stmt.executeQuery("show dnodes"); + ResultSetMetaData meta = rs.getMetaData(); + while (rs.next()) { + for (int i = 1; i <= meta.getColumnCount(); i++) { + System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t"); + } + System.out.println(); + } + System.out.println("======================="); + rs.close(); TimeUnit.SECONDS.sleep(5); } catch (SQLException | InterruptedException e) { e.printStackTrace();