From 16069460f1fbf09802072d6d958c29605307ed66 Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 14:03:06 +0800 Subject: [PATCH 01/15] [TD-2672]: optimized the JDBC test cases --- .../taosdata/jdbc/TSDBPreparedStatement.java | 4 +- .../java/com/taosdata/jdbc/TSDBStatement.java | 10 +- .../taosdata/jdbc/PreparedStatementTest.java | 50 ++--- .../java/com/taosdata/jdbc/SubscribeTest.java | 6 +- .../jdbc/TSDBPreparedStatementTest.java | 186 ++++++++++++++++++ 5 files changed, 217 insertions(+), 39 deletions(-) create mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java index 230943fd53..c6b41ce004 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBPreparedStatement.java @@ -100,7 +100,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat * order to process those supported SQLs. */ private void preprocessSql() { - /***** For processing some of Spark SQLs*****/ // should replace it first this.rawSql = this.rawSql.replaceAll("or (.*) is null", ""); @@ -149,7 +148,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat rawSql = rawSql.replace(matcher.group(1), tableFullName); } /***** for inner queries *****/ - } /** @@ -196,7 +194,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat @Override public void setNull(int parameterIndex, int sqlType) throws SQLException { - setObject(parameterIndex, new String("NULL")); + setObject(parameterIndex, "NULL"); } @Override diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index 381f1d3622..4c900b5fdc 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -52,12 +52,18 @@ public class TSDBStatement implements Statement { this.isClosed = false; } + @Override public T unwrap(Class iface) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + try { + return iface.cast(this); + } catch (ClassCastException cce) { + throw new SQLException("Unable to unwrap to " + iface.toString()); + } } + @Override public boolean isWrapperFor(Class iface) throws SQLException { - throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); + return iface.isInstance(this); } public ResultSet executeQuery(String sql) throws SQLException { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java index f52c50ff1a..a49ad05d05 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java @@ -1,9 +1,7 @@ package com.taosdata.jdbc; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; +import org.junit.*; +import org.junit.runners.MethodSorters; import java.sql.*; import java.util.Properties; @@ -11,14 +9,13 @@ import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -@FixMethodOrder() -public class PreparedStatementTest extends BaseTest { - static Connection connection = null; - static PreparedStatement statement = null; +@FixMethodOrder(value = MethodSorters.NAME_ASCENDING) +public class PreparedStatementTest { + static Connection connection; + static TSDBPreparedStatement statement; static String dbName = "test"; static String tName = "t0"; static String host = "localhost"; - static ResultSet resSet = null; @BeforeClass public static void createConnection() throws SQLException { @@ -28,19 +25,16 @@ public class PreparedStatementTest extends BaseTest { return; } Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); - String sql = "drop database if exists " + dbName; statement = (TSDBPreparedStatement) connection.prepareStatement(sql); - } @Test - public void createTableAndQuery() throws SQLException { + public void case001_createTableAndQuery() throws SQLException { long ts = System.currentTimeMillis(); statement.executeUpdate("create database if not exists " + dbName); @@ -48,47 +42,40 @@ public class PreparedStatementTest extends BaseTest { statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", 1)"); PreparedStatement selectStatement = connection.prepareStatement("select * from " + dbName + "." + tName); - ResultSet resultSet = selectStatement.executeQuery(); assertTrue(null != resultSet); boolean isClosed = statement.isClosed(); assertEquals(false, isClosed); + selectStatement.close(); } @Test - public void testPreparedStatement() throws SQLException { + public void case002_testPreparedStatement() throws SQLException { long ts = System.currentTimeMillis() + 20000; - PreparedStatement saveStatement = connection - .prepareStatement("insert into " + dbName + "." + tName + " values (" + ts + ", 1)"); + PreparedStatement saveStatement = connection.prepareStatement("insert into " + dbName + "." + tName + " values (" + ts + ", 1)"); int affectedRows = saveStatement.executeUpdate(); assertTrue(1 == affectedRows); + saveStatement.close(); } @Test - public void testSavedPreparedStatement() throws SQLException { + public void case003_testSavedPreparedStatement() throws SQLException { long ts = System.currentTimeMillis(); - - TSDBPreparedStatement saveStatement = (TSDBPreparedStatement) connection - .prepareStatement("insert into " + dbName + "." + tName + " values (?, ?)"); - + TSDBPreparedStatement saveStatement = (TSDBPreparedStatement) connection.prepareStatement("insert into " + dbName + "." + tName + " values (?, ?)"); saveStatement.setObject(1, ts + 10000); saveStatement.setObject(2, 3); int rows = saveStatement.executeUpdate(); assertEquals(1, rows); + saveStatement.close(); } @Test - public void testUnsupport() { - // if(null == resSet) { - // return; - // } - TSDBPreparedStatement tsdbStatement = (TSDBPreparedStatement) statement; - try { - tsdbStatement.unwrap(null); - } catch (SQLException e) { - } + public void case004_testUnsupport() throws SQLException { + TSDBPreparedStatement tsdbStatement = statement; + + Assert.assertNotNull(tsdbStatement.unwrap(TSDBPreparedStatement.class)); try { tsdbStatement.isWrapperFor(null); } catch (SQLException e) { @@ -180,6 +167,7 @@ public class PreparedStatementTest extends BaseTest { try { tsdbStatement.closeOnCompletion(); } catch (SQLException e) { + } try { tsdbStatement.isCloseOnCompletion(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java index 0a71c77d1d..1b09f6d502 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java @@ -10,9 +10,9 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; -public class SubscribeTest extends BaseTest { - Connection connection = null; - Statement statement = null; +public class SubscribeTest { + Connection connection; + Statement statement; String dbName = "test"; String tName = "t0"; String host = "localhost"; diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java new file mode 100644 index 0000000000..0e4ed67bf9 --- /dev/null +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java @@ -0,0 +1,186 @@ +package com.taosdata.jdbc; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class TSDBPreparedStatementTest { + private static final String host = "127.0.0.1"; + private static Connection conn; + + @Test + public void executeQuery() { + + } + + @Test + public void executeUpdate() { + + } + + @Test + public void setNull() { + } + + @Test + public void setBoolean() { + } + + @Test + public void setByte() { + } + + @Test + public void setShort() { + } + + @Test + public void setInt() { + } + + @Test + public void setLong() { + } + + @Test + public void setFloat() { + } + + @Test + public void setDouble() { + } + + @Test + public void setBigDecimal() { + } + + @Test + public void setString() { + } + + @Test + public void setBytes() { + } + + @Test + public void setDate() { + } + + @Test + public void setTime() { + } + + @Test + public void setTimestamp() { + } + + @Test + public void setAsciiStream() { + } + + @Test + public void setUnicodeStream() { + } + + @Test + public void setBinaryStream() { + } + + @Test + public void clearParameters() { + } + + @Test + public void setObject() { + + } + + @Test + public void execute() { + } + + @Test + public void addBatch() { + + } + + @Test + public void setCharacterStream() { + } + + @Test + public void setRef() { + } + + @Test + public void setBlob() { + } + + @Test + public void setClob() { + } + + @Test + public void setArray() { + } + + @Test + public void getMetaData() { + } + + @Test + public void setURL() { + } + + @Test + public void getParameterMetaData() { + } + + @Test + public void setRowId() { + } + + @Test + public void setNString() { + } + + @Test + public void setNCharacterStream() { + } + + @Test + public void setNClob() { + + } + + @Test + public void setSQLXML() { + + } + + + @BeforeClass + public static void beforeClass() { + try { + Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); + conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/jdbc_test?user=root&password=taosdata"); + } catch (ClassNotFoundException | SQLException e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void afterClass() { + try { + if (conn != null) + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file From c96e0ea42f31bc0c589a2836cb187eec2fb6ddf8 Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 14:10:19 +0800 Subject: [PATCH 02/15] change --- .../taosdata/jdbc/PreparedStatementTest.java | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java index a49ad05d05..8c9b258dcd 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/PreparedStatementTest.java @@ -73,104 +73,101 @@ public class PreparedStatementTest { @Test public void case004_testUnsupport() throws SQLException { - TSDBPreparedStatement tsdbStatement = statement; - Assert.assertNotNull(tsdbStatement.unwrap(TSDBPreparedStatement.class)); + Assert.assertNotNull(statement.unwrap(TSDBPreparedStatement.class)); + Assert.assertTrue(statement.isWrapperFor(TSDBPreparedStatement.class)); + try { - tsdbStatement.isWrapperFor(null); + statement.getMaxFieldSize(); } catch (SQLException e) { } try { - tsdbStatement.getMaxFieldSize(); + statement.setMaxFieldSize(0); } catch (SQLException e) { } try { - tsdbStatement.setMaxFieldSize(0); + statement.setEscapeProcessing(true); } catch (SQLException e) { } try { - tsdbStatement.setEscapeProcessing(true); + statement.cancel(); } catch (SQLException e) { } try { - tsdbStatement.cancel(); + statement.getWarnings(); } catch (SQLException e) { } try { - tsdbStatement.getWarnings(); + statement.clearWarnings(); } catch (SQLException e) { } try { - tsdbStatement.clearWarnings(); + statement.setCursorName(null); } catch (SQLException e) { } try { - tsdbStatement.setCursorName(null); + statement.getMoreResults(); } catch (SQLException e) { } try { - tsdbStatement.getMoreResults(); + statement.setFetchDirection(0); } catch (SQLException e) { } try { - tsdbStatement.setFetchDirection(0); + statement.getFetchDirection(); } catch (SQLException e) { } try { - tsdbStatement.getFetchDirection(); + statement.getResultSetConcurrency(); } catch (SQLException e) { } try { - tsdbStatement.getResultSetConcurrency(); + statement.getResultSetType(); } catch (SQLException e) { } try { - tsdbStatement.getResultSetType(); + statement.getConnection(); } catch (SQLException e) { } try { - tsdbStatement.getConnection(); + statement.getMoreResults(); } catch (SQLException e) { } try { - tsdbStatement.getMoreResults(); + statement.getGeneratedKeys(); } catch (SQLException e) { } try { - tsdbStatement.getGeneratedKeys(); + statement.executeUpdate(null, 0); } catch (SQLException e) { } try { - tsdbStatement.executeUpdate(null, 0); + statement.executeUpdate(null, new int[]{0}); } catch (SQLException e) { } try { - tsdbStatement.executeUpdate(null, new int[]{0}); + statement.executeUpdate(null, new String[]{"str1", "str2"}); } catch (SQLException e) { } try { - tsdbStatement.executeUpdate(null, new String[]{"str1", "str2"}); + statement.getResultSetHoldability(); } catch (SQLException e) { } try { - tsdbStatement.getResultSetHoldability(); + statement.setPoolable(true); } catch (SQLException e) { } try { - tsdbStatement.setPoolable(true); + statement.isPoolable(); } catch (SQLException e) { } try { - tsdbStatement.isPoolable(); - } catch (SQLException e) { - } - try { - tsdbStatement.closeOnCompletion(); + statement.closeOnCompletion(); } catch (SQLException e) { } try { - tsdbStatement.isCloseOnCompletion(); + statement.isCloseOnCompletion(); } catch (SQLException e) { } } From 8630797f46ec2702d436f947d74a31f112b51c4e Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 14:27:13 +0800 Subject: [PATCH 03/15] change --- .../java/com/taosdata/jdbc/QueryDataTest.java | 83 +++++++++---------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java index 611e21e887..e6b2eda271 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java @@ -6,76 +6,67 @@ import org.junit.Test; import java.sql.*; import java.util.Properties; -import java.util.Random; import static org.junit.Assert.assertEquals; -import java.util.Properties; -import java.util.concurrent.Executors; -import java.util.concurrent.*; -import static org.junit.Assert.assertTrue; +public class QueryDataTest { -public class QueryDataTest extends BaseTest { - - static Connection connection = null; - static Statement statement = null; + static Connection connection; + static Statement statement; static String dbName = "test"; static String stbName = "meters"; - static String host = "localhost"; - static int numOfTables = 30; - final static int numOfRecordsPerTable = 1000; - static long ts = 1496732686000l; - final static String tablePrefix = "t"; + static String host = "127.0.0.1"; @Before - public void createDatabase() throws SQLException { + public void createDatabase() { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); - } catch (ClassNotFoundException e) { + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); + + statement = connection.createStatement(); + statement.executeUpdate("drop database if exists " + dbName); + statement.executeUpdate("create database if not exists " + dbName); + statement.executeUpdate("use " + dbName); + + String createTableSql = "create table " + stbName + "(ts timestamp, name binary(64))"; + statement.executeUpdate(createTableSql); + + } catch (ClassNotFoundException | SQLException e) { return; } - - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); - - statement = connection.createStatement(); - statement.executeUpdate("drop database if exists " + dbName); - statement.executeUpdate("create database if not exists " + dbName); - statement.executeUpdate("use " + dbName); - - String createTableSql = "create table " + stbName + "(ts timestamp, name binary(6))"; - statement.executeUpdate(createTableSql); } - - @Test - public void testQueryBinaryData() throws SQLException{ - - String insertSql = "insert into " + stbName + " values(now, 'taosda')"; - System.out.println(insertSql); + @Test + public void testQueryBinaryData() throws SQLException { + String insertSql = "insert into " + stbName + " values(now, 'taosdata')"; + System.out.println(insertSql); statement.executeUpdate(insertSql); String querySql = "select * from " + stbName; - ResultSet rs = statement.executeQuery(querySql); + ResultSet rs = statement.executeQuery(querySql); - while(rs.next()) { + while (rs.next()) { String name = rs.getString(2) + "001"; System.out.println("name = " + name); assertEquals(name, "taosda001"); } - rs.close(); + rs.close(); } - @After - public void close() throws Exception { - statement.close(); - connection.close(); - Thread.sleep(10); + public void close() { + try { + if (statement != null) + statement.close(); + if (connection != null) + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } } - + } \ No newline at end of file From 42c802bda2fc912657bfaf0baf02a9d9e8ec118b Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 14:30:29 +0800 Subject: [PATCH 04/15] change --- .../jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java index e6b2eda271..37fbc28487 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/QueryDataTest.java @@ -50,9 +50,9 @@ public class QueryDataTest { ResultSet rs = statement.executeQuery(querySql); while (rs.next()) { - String name = rs.getString(2) + "001"; + String name = rs.getString(2); System.out.println("name = " + name); - assertEquals(name, "taosda001"); + assertEquals("taosdata", name); } rs.close(); } From efa75445a34c37e2c9ab6d30cb04574ef054bf1d Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 14:43:56 +0800 Subject: [PATCH 05/15] change --- .../test/java/com/taosdata/jdbc/BaseTest.java | 33 --------- .../java/com/taosdata/jdbc/ResultSetTest.java | 56 +++++++-------- .../java/com/taosdata/jdbc/StatementTest.java | 33 ++++----- .../java/com/taosdata/jdbc/SubscribeTest.java | 53 ++++++++------- .../jdbc/TSDBDatabaseMetaDataTest.java | 61 +++++++++-------- .../com/taosdata/jdbc/TSDBDriverTest.java | 68 +++++-------------- .../taosdata/jdbc/cases/BatchInsertTest.java | 45 ++++++++---- .../com/taosdata/jdbc/lib/TSDBCommon.java | 47 ------------- 8 files changed, 152 insertions(+), 244 deletions(-) delete mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java delete mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java deleted file mode 100644 index ce3735c128..0000000000 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.taosdata.jdbc; - -import com.taosdata.jdbc.utils.TDNodes; - -import org.junit.AfterClass; -import org.junit.BeforeClass; - -public abstract class BaseTest { - - private static boolean testCluster = false; - private static TDNodes nodes = new TDNodes(); - - @BeforeClass - public static void setupEnv() { - try { - if (nodes.getTDNode(1).getTaosdPid() != null) { - System.out.println("Kill taosd before running JDBC test"); - nodes.getTDNode(1).setRunning(1); - nodes.stop(1); - } - nodes.setTestCluster(testCluster); - nodes.deploy(1); - nodes.start(1); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void cleanUpEnv() { - nodes.stop(1); - } -} \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java index 8067c547df..b70bcd3c23 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java @@ -13,42 +13,37 @@ import java.util.Properties; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class ResultSetTest extends BaseTest { - static Connection connection = null; - static Statement statement = null; +public class ResultSetTest { + static Connection connection; + static Statement statement; static String dbName = "test"; static String tName = "t0"; static String host = "localhost"; - static ResultSet resSet = null; + static ResultSet resSet; @BeforeClass - public static void createDatabaseAndTable() throws SQLException { + public static void createDatabaseAndTable() { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); - } catch (ClassNotFoundException e) { + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); + statement = connection.createStatement(); + statement.executeUpdate("drop database if exists " + dbName); + statement.executeUpdate("create database if not exists " + dbName); + statement.execute("use " + dbName); + statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k1 int, k2 bigint, k3 float, k4 double, k5 binary(30), k6 smallint, k7 bool, k8 nchar(20))"); + } catch (ClassNotFoundException | SQLException e) { return; } - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); - - statement = connection.createStatement(); - statement.executeUpdate("drop database if exists " + dbName); - statement.executeUpdate("create database if not exists " + dbName); - statement.executeUpdate("create table if not exists " + dbName + "." + tName + - " (ts timestamp, k1 int, k2 bigint, k3 float, k4 double, k5 binary(30), k6 smallint, k7 bool, k8 nchar(20))"); - - statement.executeQuery("use " + dbName); } @Test public void testResultSet() { - String sql = null; + String sql; long ts = 1496732686000l; int v1 = 2147483600; long v2 = ts + 1000; @@ -815,13 +810,18 @@ public class ResultSetTest extends BaseTest { assertEquals(res.length, 2); statement.clearBatch(); } - @AfterClass - public static void close() throws Exception { - statement.executeUpdate("drop database " + dbName); - statement.close(); - connection.close(); - Thread.sleep(10); + @AfterClass + public static void close() { + try { + statement.executeUpdate("drop database " + dbName); + if (statement != null) + statement.close(); + if (connection != null) + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java index a79512984e..f78f899294 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java @@ -16,23 +16,22 @@ public class StatementTest { static String dbName = "test"; static String tName = "t0"; static String host = "localhost"; - static ResultSet resSet = null; @BeforeClass public static void createConnection() throws SQLException { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", properties); + statement = connection.createStatement(); + statement.executeUpdate("drop database if exists " + dbName); + } catch (ClassNotFoundException e) { return; } - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root&password=taosdata", properties); - - statement = connection.createStatement(); - statement.executeUpdate("drop database if exists " + dbName); } @Test @@ -49,7 +48,6 @@ public class StatementTest { } catch (SQLException e) { e.printStackTrace(); } - } @Test @@ -173,12 +171,15 @@ public class StatementTest { } @AfterClass - public static void close() throws Exception { - if (!statement.isClosed()) { - statement.executeUpdate("drop database if exists " + dbName); - statement.close(); - connection.close(); - Thread.sleep(10); + public static void close() { + try { + statement.execute("drop database if exists " + dbName); + if (statement != null) + statement.close(); + if (connection != null) + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); } } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java index 1b09f6d502..1d8ff08db6 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java @@ -19,27 +19,28 @@ public class SubscribeTest { String topic = "test"; @Before - public void createDatabase() throws SQLException { + public void createDatabase() { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); - } catch (ClassNotFoundException e) { - return; - } - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); - statement = connection.createStatement(); - statement.executeUpdate("create database if not exists " + dbName); - statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); - long ts = System.currentTimeMillis(); - for (int i = 0; i < 2; i++) { - ts += i; - String sql = "insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")"; - statement.executeUpdate(sql); + statement = connection.createStatement(); + statement.executeUpdate("create database if not exists " + dbName); + statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)"); + long ts = System.currentTimeMillis(); + for (int i = 0; i < 2; i++) { + ts += i; + String sql = "insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")"; + statement.executeUpdate(sql); + } + + } catch (ClassNotFoundException | SQLException e) { + return; } } @@ -79,10 +80,16 @@ public class SubscribeTest { } @After - public void close() throws Exception { - statement.executeQuery("drop database " + dbName); - statement.close(); - connection.close(); - Thread.sleep(10); + public void close() { + try { + statement.executeQuery("drop database " + dbName); + if (statement != null) + statement.close(); + if (connection != null) + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java index 8066b38573..e3f0d1b8b2 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java @@ -6,37 +6,9 @@ import java.sql.*; import java.util.Properties; public class TSDBDatabaseMetaDataTest { - private TSDBDatabaseMetaData metaData; private static final String host = "127.0.0.1"; - private Connection connection; - - @BeforeClass - public void before() { - try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties); - metaData = connection.getMetaData().unwrap(TSDBDatabaseMetaData.class); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - @AfterClass - public void after() { - try { - if (connection != null) - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } + private static Connection connection; + private static TSDBDatabaseMetaData metaData; @Test public void unwrap() throws SQLException { @@ -975,4 +947,33 @@ public class TSDBDatabaseMetaDataTest { public void generatedKeyAlwaysReturned() throws SQLException { Assert.assertFalse(metaData.generatedKeyAlwaysReturned()); } + + @BeforeClass + public static void before() { + try { + Class.forName("com.taosdata.jdbc.TSDBDriver"); + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", properties); + metaData = connection.getMetaData().unwrap(TSDBDatabaseMetaData.class); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + @AfterClass + public static void after() { + try { + if (connection != null) + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java index 8adcdefb29..445723f501 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDriverTest.java @@ -3,9 +3,6 @@ package com.taosdata.jdbc; import org.junit.BeforeClass; import org.junit.Test; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; import java.sql.*; import java.util.Properties; @@ -27,54 +24,15 @@ public class TSDBDriverTest { "jdbc:TAOS://:/test", "jdbc:TAOS://localhost:0/?user=root&password=taosdata" }; - private static boolean islibLoaded = false; - private static boolean isTaosdActived; private Connection conn; - @BeforeClass - public static void before() { - String osName = System.getProperty("os.name").toLowerCase(); - if (!osName.equals("linux")) - return; - // try to load taos lib - try { - System.loadLibrary("taos"); - islibLoaded = true; - } catch (UnsatisfiedLinkError error) { - System.out.println("load tdengine lib failed."); - error.printStackTrace(); - } - // check taosd is activated - try { - String[] cmd = {"/bin/bash", "-c", "ps -ef | grep taosd | grep -v \"grep\""}; - Process exec = Runtime.getRuntime().exec(cmd); - BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream())); - int lineCnt = 0; - while (reader.readLine() != null) { - lineCnt++; - } - if (lineCnt > 0) - isTaosdActived = true; - } catch (IOException e) { - e.printStackTrace(); - } - - try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - } - @Test public void testConnectWithJdbcURL() { final String url = "jdbc:TAOS://localhost:6030/log?user=root&password=taosdata"; try { - if (islibLoaded && isTaosdActived) { - conn = DriverManager.getConnection(url); - assertNotNull("failure - connection should not be null", conn); - } + conn = DriverManager.getConnection(url); + assertNotNull("failure - connection should not be null", conn); } catch (SQLException e) { e.printStackTrace(); fail("failure - should not throw Exception"); @@ -89,10 +47,8 @@ public class TSDBDriverTest { connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); try { - if (islibLoaded && isTaosdActived) { - conn = DriverManager.getConnection(jdbcUrl, connProps); - assertNotNull("failure - connection should not be null", conn); - } + conn = DriverManager.getConnection(jdbcUrl, connProps); + assertNotNull("failure - connection should not be null", conn); } catch (SQLException e) { e.printStackTrace(); fail("failure - should not throw Exception"); @@ -107,10 +63,8 @@ public class TSDBDriverTest { connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); try { - if (islibLoaded && isTaosdActived) { - conn = DriverManager.getConnection(jdbcUrl, connProps); - assertNotNull("failure - connection should not be null", conn); - } + conn = DriverManager.getConnection(jdbcUrl, connProps); + assertNotNull("failure - connection should not be null", conn); } catch (SQLException e) { e.printStackTrace(); fail("failure - should not throw Exception"); @@ -207,4 +161,14 @@ public class TSDBDriverTest { assertNull("failure - getParentLogger should be be null", new TSDBDriver().getParentLogger()); } + @BeforeClass + public static void before() { + try { + Class.forName("com.taosdata.jdbc.TSDBDriver"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java index 9608c4985d..66749d057c 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java @@ -1,14 +1,13 @@ package com.taosdata.jdbc.cases; +import com.taosdata.jdbc.TSDBDriver; import com.taosdata.jdbc.lib.TSDBCommon; import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; +import java.sql.*; +import java.util.Properties; import java.util.Random; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -18,30 +17,47 @@ import static org.junit.Assert.assertEquals; public class BatchInsertTest { - static String host = "localhost"; + static String host = "127.0.0.1"; static String dbName = "test"; static String stbName = "meters"; static int numOfTables = 30; final static int numOfRecordsPerTable = 1000; static long ts = 1496732686000l; final static String tablePrefix = "t"; - private Connection connection; @Before public void before() { try { - connection = TSDBCommon.getConn(host); - TSDBCommon.createDatabase(connection, dbName); - TSDBCommon.createStable(connection, stbName); - TSDBCommon.createTables(connection, numOfTables, stbName, tablePrefix); + Class.forName("com.taosdata.jdbc.TSDBDriver"); + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); + + Statement statement = connection.createStatement(); + statement.executeUpdate("drop database if exists " + dbName); + statement.executeUpdate("create database if not exists " + dbName); + statement.executeUpdate("use " + dbName); + // create stable + String createTableSql = "create table " + stbName + "(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))"; + statement.executeUpdate(createTableSql); + // create tables + for(int i = 0; i < numOfTables; i++) { + String loc = i % 2 == 0 ? "beijing" : "shanghai"; + String createSubTalbesSql = "create table " + tablePrefix + i + " using " + stbName + " tags(" + i + ", '" + loc + "')"; + statement.executeUpdate(createSubTalbesSql); + } + statement.close(); } catch (Exception e) { e.printStackTrace(); } } @Test - public void testBatchInsert(){ + public void testBatchInsert() { ExecutorService executorService = Executors.newFixedThreadPool(numOfTables); for (int i = 0; i < numOfTables; i++) { final int index = i; @@ -63,7 +79,7 @@ public class BatchInsertTest { statement.addBatch(sb.toString()); statement.executeBatch(); long endTime = System.currentTimeMillis(); - System.out.println("Thread " + index + " takes " + (endTime - startTime) + " microseconds"); + System.out.println("Thread " + index + " takes " + (endTime - startTime) + " microseconds"); connection.commit(); statement.close(); } catch (Exception e) { @@ -80,7 +96,7 @@ public class BatchInsertTest { e.printStackTrace(); } - try{ + try { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery("select * from meters"); int num = 0; @@ -89,7 +105,7 @@ public class BatchInsertTest { } assertEquals(num, numOfTables * numOfRecordsPerTable); rs.close(); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } } @@ -102,7 +118,6 @@ public class BatchInsertTest { } catch (SQLException e) { e.printStackTrace(); } - } } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java deleted file mode 100644 index 0e2613d617..0000000000 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/lib/TSDBCommon.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.taosdata.jdbc.lib; - -import com.taosdata.jdbc.TSDBDriver; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Properties; - -public class TSDBCommon { - - public static Connection getConn(String host) throws SQLException, ClassNotFoundException { - Class.forName("com.taosdata.jdbc.TSDBDriver"); - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - return DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); - } - - public static void createDatabase(Connection connection, String dbName) throws SQLException { - Statement statement = connection.createStatement(); - statement.executeUpdate("drop database if exists " + dbName); - statement.executeUpdate("create database if not exists " + dbName); - statement.executeUpdate("use " + dbName); - statement.close(); - } - - public static void createStable(Connection connection, String stbName) throws SQLException { - Statement statement = connection.createStatement(); - String createTableSql = "create table " + stbName + "(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))"; - statement.executeUpdate(createTableSql); - statement.close(); - } - - public static void createTables(Connection connection, int numOfTables, String stbName,String tablePrefix) throws SQLException { - Statement statement = connection.createStatement(); - for(int i = 0; i < numOfTables; i++) { - String loc = i % 2 == 0 ? "beijing" : "shanghai"; - String createSubTalbesSql = "create table " + tablePrefix + i + " using " + stbName + " tags(" + i + ", '" + loc + "')"; - statement.executeUpdate(createSubTalbesSql); - } - statement.close(); - } -} From 6942ddcf4fab863c5d7367b944ec55d78a8c6d66 Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 14:45:02 +0800 Subject: [PATCH 06/15] change --- .../src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java index 66749d057c..9f54e4b1ba 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java @@ -1,7 +1,6 @@ package com.taosdata.jdbc.cases; import com.taosdata.jdbc.TSDBDriver; -import com.taosdata.jdbc.lib.TSDBCommon; import org.junit.After; import org.junit.Before; import org.junit.Test; From 542dd5d4954af45d851d082556ff811a8ae06ede Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 14:50:59 +0800 Subject: [PATCH 07/15] change --- .../test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java index e3f0d1b8b2..9bb22ad577 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java @@ -33,7 +33,7 @@ public class TSDBDatabaseMetaDataTest { @Test public void getURL() throws SQLException { - Assert.assertEquals("jdbc:TAOS://localhost:6030/?user=root&password=taosdata", metaData.getURL()); + Assert.assertEquals("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata", metaData.getURL()); } @Test From ea4f3c9f1a2d9839907b96a713d2ae64196be53e Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 15:06:49 +0800 Subject: [PATCH 08/15] change --- src/connector/jdbc/pom.xml | 2 +- .../com/taosdata/jdbc/BatchInsertTest.java | 115 ------------------ .../jdbc/TSDBDatabaseMetaDataTest.java | 5 +- .../taosdata/jdbc/cases/BatchInsertTest.java | 43 +++---- 4 files changed, 23 insertions(+), 142 deletions(-) delete mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 6be0ca036e..1fb2c69524 100755 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -126,7 +126,7 @@ **/*Test.java - **/BatchInsertTest.java + **/AppMemoryLeakTest.java **/FailOverTest.java true diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java deleted file mode 100644 index 4046e3edf6..0000000000 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BatchInsertTest.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.taosdata.jdbc; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.sql.*; -import java.util.Properties; -import java.util.Random; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertEquals; - -public class BatchInsertTest { - - private Connection connection; - - private static String dbName = "test"; - private static String stbName = "meters"; - private static String host = "127.0.0.1"; - private static int numOfTables = 30; - private static int numOfRecordsPerTable = 1000; - private static long ts = 1496732686000l; - private static String tablePrefix = "t"; - - @Before - public void createDatabase() throws SQLException { - try { - Class.forName("com.taosdata.jdbc.TSDBDriver"); - } catch (ClassNotFoundException e) { - return; - } - - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); - - Statement stmt = connection.createStatement(); - stmt.execute("drop database if exists " + dbName); - stmt.execute("create database if not exists " + dbName); - stmt.execute("use " + dbName); - - String createTableSql = "create table " + stbName + "(ts timestamp, f1 int, f2 int, f3 int) tags(areaid int, loc binary(20))"; - stmt.execute(createTableSql); - - for (int i = 0; i < numOfTables; i++) { - String loc = i % 2 == 0 ? "beijing" : "shanghai"; - String createSubTalbesSql = "create table " + tablePrefix + i + " using " + stbName + " tags(" + i + ", '" + loc + "')"; - stmt.execute(createSubTalbesSql); - } - stmt.close(); - } - - @Test - public void testBatchInsert() throws SQLException { - ExecutorService executorService = Executors.newFixedThreadPool(numOfTables); - for (int i = 0; i < numOfTables; i++) { - final int index = i; - executorService.execute(() -> { - try { - long startTime = System.currentTimeMillis(); - Statement statement = connection.createStatement(); // get statement - StringBuilder sb = new StringBuilder(); - sb.append("INSERT INTO " + tablePrefix + index + " VALUES"); - Random rand = new Random(); - for (int j = 1; j <= numOfRecordsPerTable; j++) { - sb.append("(" + (ts + j) + ", "); - sb.append(rand.nextInt(100) + ", "); - sb.append(rand.nextInt(100) + ", "); - sb.append(rand.nextInt(100) + ")"); - } - statement.addBatch(sb.toString()); - statement.executeBatch(); - long endTime = System.currentTimeMillis(); - System.out.println("Thread " + index + " takes " + (endTime - startTime) + " microseconds"); - connection.commit(); - statement.close(); - } catch (Exception e) { - e.printStackTrace(); - } - }); - } - executorService.shutdown(); - - try { - executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - Statement statement = connection.createStatement(); - ResultSet rs = statement.executeQuery("select * from meters"); - int num = 0; - while (rs.next()) { - num++; - } - assertEquals(num, numOfTables * numOfRecordsPerTable); - rs.close(); - } - - @After - public void close() { - try { - if (connection != null) - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - -} \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java index 9bb22ad577..a7657fa3e5 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java @@ -949,11 +949,10 @@ public class TSDBDatabaseMetaDataTest { } @BeforeClass - public static void before() { + public static void beforeClass() { try { Class.forName("com.taosdata.jdbc.TSDBDriver"); Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); @@ -967,7 +966,7 @@ public class TSDBDatabaseMetaDataTest { } @AfterClass - public static void after() { + public static void afterClass() { try { if (connection != null) connection.close(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java index 9f54e4b1ba..472da34980 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java @@ -60,30 +60,27 @@ public class BatchInsertTest { ExecutorService executorService = Executors.newFixedThreadPool(numOfTables); for (int i = 0; i < numOfTables; i++) { final int index = i; - executorService.execute(new Runnable() { - @Override - public void run() { - try { - long startTime = System.currentTimeMillis(); - Statement statement = connection.createStatement(); // get statement - StringBuilder sb = new StringBuilder(); - sb.append("INSERT INTO " + tablePrefix + index + " VALUES"); - Random rand = new Random(); - for (int j = 1; j <= numOfRecordsPerTable; j++) { - sb.append("(" + (ts + j) + ", "); - sb.append(rand.nextInt(100) + ", "); - sb.append(rand.nextInt(100) + ", "); - sb.append(rand.nextInt(100) + ")"); - } - statement.addBatch(sb.toString()); - statement.executeBatch(); - long endTime = System.currentTimeMillis(); - System.out.println("Thread " + index + " takes " + (endTime - startTime) + " microseconds"); - connection.commit(); - statement.close(); - } catch (Exception e) { - e.printStackTrace(); + executorService.execute(() -> { + try { + long startTime = System.currentTimeMillis(); + Statement statement = connection.createStatement(); // get statement + StringBuilder sb = new StringBuilder(); + sb.append("INSERT INTO " + tablePrefix + index + " VALUES"); + Random rand = new Random(); + for (int j = 1; j <= numOfRecordsPerTable; j++) { + sb.append("(" + (ts + j) + ", "); + sb.append(rand.nextInt(100) + ", "); + sb.append(rand.nextInt(100) + ", "); + sb.append(rand.nextInt(100) + ")"); } + statement.addBatch(sb.toString()); + statement.executeBatch(); + long endTime = System.currentTimeMillis(); + System.out.println("Thread " + index + " takes " + (endTime - startTime) + " microseconds"); + connection.commit(); + statement.close(); + } catch (Exception e) { + e.printStackTrace(); } }); } From b76b45277c2e744b260ee55571df145393f4652a Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 15:12:44 +0800 Subject: [PATCH 09/15] change --- .../java/com/taosdata/jdbc/StableTest.java | 1 + .../java/com/taosdata/jdbc/StatementTest.java | 126 ++++-------------- 2 files changed, 29 insertions(+), 98 deletions(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java index c86a0b4c6a..0a1c548baa 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StableTest.java @@ -29,6 +29,7 @@ public class StableTest { properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); Statement statement = connection.createStatement(); + statement.execute("drop database if exists " + dbName); statement.execute("create database if not exists " + dbName); statement.execute("use " + dbName); statement.close(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java index f78f899294..f35c859540 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java @@ -1,6 +1,7 @@ package com.taosdata.jdbc; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -67,106 +68,35 @@ public class StatementTest { @Test public void testUnsupport() { - TSDBStatement tsdbStatement = (TSDBStatement) statement; try { - tsdbStatement.unwrap(null); - } catch (SQLException e) { - } - try { - tsdbStatement.isWrapperFor(null); - } catch (SQLException e) { - } - try { - tsdbStatement.getMaxFieldSize(); - } catch (SQLException e) { - } - try { - tsdbStatement.setMaxFieldSize(0); - } catch (SQLException e) { - } - try { - tsdbStatement.setEscapeProcessing(true); - } catch (SQLException e) { - } - try { - tsdbStatement.cancel(); - } catch (SQLException e) { - } - try { - tsdbStatement.getWarnings(); - } catch (SQLException e) { - } - try { - tsdbStatement.clearWarnings(); - } catch (SQLException e) { - } - try { - tsdbStatement.setCursorName(null); - } catch (SQLException e) { - } - try { - tsdbStatement.getMoreResults(); - } catch (SQLException e) { - } - try { - tsdbStatement.setFetchDirection(0); - } catch (SQLException e) { - } - try { - tsdbStatement.getFetchDirection(); - } catch (SQLException e) { - } - try { - tsdbStatement.getResultSetConcurrency(); - } catch (SQLException e) { - } - try { - tsdbStatement.getResultSetType(); - } catch (SQLException e) { - } - try { - tsdbStatement.getConnection(); - } catch (SQLException e) { - } - try { - tsdbStatement.getMoreResults(); - } catch (SQLException e) { - } - try { - tsdbStatement.getGeneratedKeys(); - } catch (SQLException e) { - } - try { - tsdbStatement.executeUpdate(null, 0); - } catch (SQLException e) { - } - try { - tsdbStatement.executeUpdate(null, new int[]{0}); - } catch (SQLException e) { - } - try { - tsdbStatement.executeUpdate(null, new String[]{"str1", "str2"}); - } catch (SQLException e) { - } - try { - tsdbStatement.getResultSetHoldability(); - } catch (SQLException e) { - } - try { - tsdbStatement.setPoolable(true); - } catch (SQLException e) { - } - try { - tsdbStatement.isPoolable(); - } catch (SQLException e) { - } - try { - tsdbStatement.closeOnCompletion(); - } catch (SQLException e) { - } - try { - tsdbStatement.isCloseOnCompletion(); + Assert.assertNotNull(statement.unwrap(TSDBStatement.class)); + Assert.assertTrue(statement.isWrapperFor(TSDBStatement.class)); + + statement.getMaxFieldSize(); + statement.setMaxFieldSize(0); + statement.setEscapeProcessing(true); + statement.cancel(); + statement.getWarnings(); + statement.clearWarnings(); + statement.setCursorName(null); + statement.getMoreResults(); + statement.setFetchDirection(0); + statement.getFetchDirection(); + statement.getResultSetConcurrency(); + statement.getResultSetType(); + statement.getConnection(); + statement.getMoreResults(); + statement.getGeneratedKeys(); + statement.executeUpdate(null, 0); + statement.executeUpdate(null, new int[]{0}); + statement.executeUpdate(null, new String[]{"str1", "str2"}); + statement.getResultSetHoldability(); + statement.setPoolable(true); + statement.isPoolable(); + statement.closeOnCompletion(); + statement.isCloseOnCompletion(); } catch (SQLException e) { + e.printStackTrace(); } } From e3cd70cf8e20d199321f65bffdf7ac7bddf6130b Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 15:17:36 +0800 Subject: [PATCH 10/15] change --- .../test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java index 0e4ed67bf9..ebacf6af6b 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBPreparedStatementTest.java @@ -167,7 +167,7 @@ public class TSDBPreparedStatementTest { public static void beforeClass() { try { Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); - conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/jdbc_test?user=root&password=taosdata"); + conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata"); } catch (ClassNotFoundException | SQLException e) { e.printStackTrace(); } From 3c83219fd905f9642949b1a1ec5550490f41e006 Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 15:19:50 +0800 Subject: [PATCH 11/15] change --- .../jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java index f35c859540..4ce29af020 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java @@ -66,7 +66,7 @@ public class StatementTest { assertEquals(false, isClosed); } - @Test + @Test(expected = SQLFeatureNotSupportedException.class) public void testUnsupport() { try { Assert.assertNotNull(statement.unwrap(TSDBStatement.class)); From b9da747d2d85c0c825dbc0fe252ca9ee525e7b85 Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 15:25:14 +0800 Subject: [PATCH 12/15] change --- .../java/com/taosdata/jdbc/TSDBConstants.java | 1 + .../java/com/taosdata/jdbc/TSDBStatement.java | 5 ++ .../taosdata/jdbc/rs/RestfulStatement.java | 47 +++++++++---------- .../java/com/taosdata/jdbc/StatementTest.java | 2 +- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java index 4f4911aad9..da297810fe 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBConstants.java @@ -19,6 +19,7 @@ import java.util.Map; public abstract class TSDBConstants { + public static final String STATEMENT_CLOSED = "Statement already closed."; public static final String DEFAULT_PORT = "6200"; public static final String UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!"; public static final String INVALID_VARIABLES = "invalid variables"; diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java index 4c900b5fdc..e7317b8e1d 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBStatement.java @@ -136,10 +136,15 @@ public class TSDBStatement implements Statement { } public void setMaxFieldSize(int max) throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } public int getMaxRows() throws SQLException { + if (isClosed()) + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); // always set maxRows to zero, meaning unlimitted rows in a resultSet return 0; } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index 8b2276fbb0..93712875b3 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -14,7 +14,6 @@ import java.util.stream.Collectors; public class RestfulStatement implements Statement { - private static final String STATEMENT_CLOSED = "Statement already closed."; private boolean closed; private String database; private final RestfulConnection conn; @@ -131,14 +130,14 @@ public class RestfulStatement implements Statement { @Override public int getMaxFieldSize() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return TSDBConstants.maxFieldSize; } @Override public void setMaxFieldSize(int max) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); if (max < 0) throw new SQLException(TSDBConstants.INVALID_VARIABLES); // nothing to do @@ -147,14 +146,14 @@ public class RestfulStatement implements Statement { @Override public int getMaxRows() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return 0; } @Override public void setMaxRows(int max) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); if (max < 0) throw new SQLException(TSDBConstants.INVALID_VARIABLES); // nothing to do @@ -163,20 +162,20 @@ public class RestfulStatement implements Statement { @Override public void setEscapeProcessing(boolean enable) throws SQLException { if (isClosed()) - throw new SQLException(RestfulStatement.STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); } @Override public int getQueryTimeout() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return 0; } @Override public void setQueryTimeout(int seconds) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); if (seconds < 0) throw new SQLException(TSDBConstants.INVALID_VARIABLES); } @@ -189,7 +188,7 @@ public class RestfulStatement implements Statement { @Override public SQLWarning getWarnings() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return null; } @@ -197,13 +196,13 @@ public class RestfulStatement implements Statement { public void clearWarnings() throws SQLException { // nothing to do if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); } @Override public void setCursorName(String name) throws SQLException { if (isClosed()) - throw new SQLException(RestfulStatement.STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG); } @@ -243,7 +242,7 @@ public class RestfulStatement implements Statement { @Override public ResultSet getResultSet() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return resultSet; } @@ -275,7 +274,7 @@ public class RestfulStatement implements Statement { @Override public void setFetchSize(int rows) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); if (rows < 0) throw new SQLException(TSDBConstants.INVALID_VARIABLES); //nothing to do @@ -284,28 +283,28 @@ public class RestfulStatement implements Statement { @Override public int getFetchSize() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return 0; } @Override public int getResultSetConcurrency() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return this.resultSet.getConcurrency(); } @Override public int getResultSetType() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return this.resultSet.getType(); } @Override public void addBatch(String sql) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); //TODO: } @@ -323,14 +322,14 @@ public class RestfulStatement implements Statement { @Override public Connection getConnection() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return this.conn; } @Override public boolean getMoreResults(int current) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); if (resultSet == null) return false; @@ -388,7 +387,7 @@ public class RestfulStatement implements Statement { @Override public int getResultSetHoldability() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return this.resultSet.getHoldability(); } @@ -400,28 +399,28 @@ public class RestfulStatement implements Statement { @Override public void setPoolable(boolean poolable) throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); //nothing to do } @Override public boolean isPoolable() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return false; } @Override public void closeOnCompletion() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); this.closeOnCompletion = true; } @Override public boolean isCloseOnCompletion() throws SQLException { if (isClosed()) - throw new SQLException(STATEMENT_CLOSED); + throw new SQLException(TSDBConstants.STATEMENT_CLOSED); return this.closeOnCompletion; } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java index 4ce29af020..7a9bc57dfa 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java @@ -66,7 +66,7 @@ public class StatementTest { assertEquals(false, isClosed); } - @Test(expected = SQLFeatureNotSupportedException.class) + @Test(expected = SQLException.class) public void testUnsupport() { try { Assert.assertNotNull(statement.unwrap(TSDBStatement.class)); From ecd22634ef130896fe4e8ff10cc0a6d0b484ebf2 Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 15:26:40 +0800 Subject: [PATCH 13/15] change --- .../java/com/taosdata/jdbc/StatementTest.java | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java index 7a9bc57dfa..b09482fb03 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/StatementTest.java @@ -67,37 +67,33 @@ public class StatementTest { } @Test(expected = SQLException.class) - public void testUnsupport() { - try { - Assert.assertNotNull(statement.unwrap(TSDBStatement.class)); - Assert.assertTrue(statement.isWrapperFor(TSDBStatement.class)); + public void testUnsupport() throws SQLException { + Assert.assertNotNull(statement.unwrap(TSDBStatement.class)); + Assert.assertTrue(statement.isWrapperFor(TSDBStatement.class)); - statement.getMaxFieldSize(); - statement.setMaxFieldSize(0); - statement.setEscapeProcessing(true); - statement.cancel(); - statement.getWarnings(); - statement.clearWarnings(); - statement.setCursorName(null); - statement.getMoreResults(); - statement.setFetchDirection(0); - statement.getFetchDirection(); - statement.getResultSetConcurrency(); - statement.getResultSetType(); - statement.getConnection(); - statement.getMoreResults(); - statement.getGeneratedKeys(); - statement.executeUpdate(null, 0); - statement.executeUpdate(null, new int[]{0}); - statement.executeUpdate(null, new String[]{"str1", "str2"}); - statement.getResultSetHoldability(); - statement.setPoolable(true); - statement.isPoolable(); - statement.closeOnCompletion(); - statement.isCloseOnCompletion(); - } catch (SQLException e) { - e.printStackTrace(); - } + statement.getMaxFieldSize(); + statement.setMaxFieldSize(0); + statement.setEscapeProcessing(true); + statement.cancel(); + statement.getWarnings(); + statement.clearWarnings(); + statement.setCursorName(null); + statement.getMoreResults(); + statement.setFetchDirection(0); + statement.getFetchDirection(); + statement.getResultSetConcurrency(); + statement.getResultSetType(); + statement.getConnection(); + statement.getMoreResults(); + statement.getGeneratedKeys(); + statement.executeUpdate(null, 0); + statement.executeUpdate(null, new int[]{0}); + statement.executeUpdate(null, new String[]{"str1", "str2"}); + statement.getResultSetHoldability(); + statement.setPoolable(true); + statement.isPoolable(); + statement.closeOnCompletion(); + statement.isCloseOnCompletion(); } @AfterClass From 030d4532e0702f123219ac9a01cd6b387ca6b0e5 Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 16:47:34 +0800 Subject: [PATCH 14/15] change --- .../test/java/com/taosdata/jdbc/ResultSetTest.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java index b70bcd3c23..3d80ff066c 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/ResultSetTest.java @@ -1,6 +1,7 @@ package com.taosdata.jdbc; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -114,16 +115,8 @@ public class ResultSetTest { public void testUnsupport() throws SQLException { statement.executeQuery("show databases"); resSet = statement.getResultSet(); - try { - resSet.unwrap(null); - } catch (SQLException e) { - assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); - } - try { - resSet.isWrapperFor(null); - } catch (SQLException e) { - assertTrue(e.getMessage().contains("this operation is NOT supported currently!")); - } + Assert.assertNotNull(resSet.unwrap(TSDBResultSet.class)); + Assert.assertTrue(resSet.isWrapperFor(TSDBResultSet.class)); try { resSet.getAsciiStream(0); } catch (SQLException e) { From 9bb353498b13111eb031446ae94056d14195beda Mon Sep 17 00:00:00 2001 From: zyyang Date: Tue, 26 Jan 2021 16:49:43 +0800 Subject: [PATCH 15/15] change --- .../java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java index c38958c6ce..ccb0941da0 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java @@ -16,10 +16,6 @@ public class SqlSyntaxValidatorTest { @Test public void isUseSQL() { Assert.assertTrue(SqlSyntaxValidator.isUseSql("use database test")); - Assert.assertTrue(SqlSyntaxValidator.isUseSql("create database test")); - Assert.assertTrue(SqlSyntaxValidator.isUseSql("create database if not exist test")); - Assert.assertTrue(SqlSyntaxValidator.isUseSql("drop database test")); - Assert.assertTrue(SqlSyntaxValidator.isUseSql("drop database if exist test")); } } \ No newline at end of file