未验证 提交 52516028 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #8872 from taosdata/hotfix/TS-601

change test cases for TS-601
...@@ -2,7 +2,6 @@ package com.taosdata.jdbc.cases; ...@@ -2,7 +2,6 @@ package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBErrorNumbers; import com.taosdata.jdbc.TSDBErrorNumbers;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
...@@ -59,38 +58,31 @@ public class AuthenticationTest { ...@@ -59,38 +58,31 @@ public class AuthenticationTest {
@Test @Test
public void test() throws SQLException { public void test() throws SQLException {
// change password // change password
String url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata"; conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=" + user + "&password=taosdata");
try (Connection conn = DriverManager.getConnection(url); Statement stmt = conn.createStatement();
Statement stmt = conn.createStatement();) { stmt.execute("alter user " + user + " pass '" + password + "'");
stmt.execute("alter user " + user + " pass '" + password + "'"); stmt.close();
} conn.close();
// use new to login and execute query // use new to login and execute query
url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password; conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=" + user + "&password=" + password);
try (Connection conn = DriverManager.getConnection(url); stmt = conn.createStatement();
Statement stmt = conn.createStatement()) { stmt.execute("show databases");
stmt.execute("show databases"); ResultSet rs = stmt.getResultSet();
ResultSet rs = stmt.getResultSet(); ResultSetMetaData meta = rs.getMetaData();
ResultSetMetaData meta = rs.getMetaData(); while (rs.next()) {
while (rs.next()) { for (int i = 1; i <= meta.getColumnCount(); i++) {
System.out.print(meta.getColumnLabel(i) + ":" + rs.getString(i) + "\t");
} }
System.out.println();
} }
// change password back // change password back
url = "jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password; conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=" + user + "&password=" + password);
try (Connection conn = DriverManager.getConnection(url); stmt = conn.createStatement();
Statement stmt = conn.createStatement()) { stmt.execute("alter user " + user + " pass 'taosdata'");
stmt.execute("alter user " + user + " pass 'taosdata'"); stmt.close();
} conn.close();
}
@Before
public void before() {
try {
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} }
} }
...@@ -18,9 +18,8 @@ public class InsertDbwithoutUseDbTest { ...@@ -18,9 +18,8 @@ public class InsertDbwithoutUseDbTest {
private static final Random random = new Random(System.currentTimeMillis()); private static final Random random = new Random(System.currentTimeMillis());
@Test @Test
public void case001() throws ClassNotFoundException, SQLException { public void case001() throws SQLException {
// prepare schema // prepare schema
Class.forName("com.taosdata.jdbc.TSDBDriver");
String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata"; String url = "jdbc:TAOS://127.0.0.1:6030/?user=root&password=taosdata";
Connection conn = DriverManager.getConnection(url, properties); Connection conn = DriverManager.getConnection(url, properties);
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
...@@ -51,9 +50,8 @@ public class InsertDbwithoutUseDbTest { ...@@ -51,9 +50,8 @@ public class InsertDbwithoutUseDbTest {
} }
@Test @Test
public void case002() throws ClassNotFoundException, SQLException { public void case002() throws SQLException {
// prepare the schema // prepare the schema
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
final String url = "jdbc:TAOS-RS://" + host + ":6041/inWithoutDb?user=root&password=taosdata"; final String url = "jdbc:TAOS-RS://" + host + ":6041/inWithoutDb?user=root&password=taosdata";
Connection conn = DriverManager.getConnection(url, properties); Connection conn = DriverManager.getConnection(url, properties);
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
......
...@@ -25,7 +25,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -25,7 +25,7 @@ public class TimestampPrecisonInNanoRestTest {
private static final String date4 = format.format(new Date(timestamp1 + 10L)); private static final String date4 = format.format(new Date(timestamp1 + 10L));
private static final String date2 = date1 + "123455"; private static final String date2 = date1 + "123455";
private static final String date3 = date4 + "123456"; private static final String date3 = date4 + "123456";
private static Connection conn; private static Connection conn;
...@@ -43,7 +43,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -43,7 +43,7 @@ public class TimestampPrecisonInNanoRestTest {
stmt.execute("drop database if exists " + ns_timestamp_db); stmt.execute("drop database if exists " + ns_timestamp_db);
stmt.execute("create database if not exists " + ns_timestamp_db + " precision 'ns'"); stmt.execute("create database if not exists " + ns_timestamp_db + " precision 'ns'");
stmt.execute("create table " + ns_timestamp_db + ".weather(ts timestamp, ts2 timestamp, f1 int)"); stmt.execute("create table " + ns_timestamp_db + ".weather(ts timestamp, ts2 timestamp, f1 int)");
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date3 + "\", \"" + date3 + "\", 128)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date3 + "\", \"" + date3 + "\", 128)");
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(" + timestamp2 + "," + timestamp2 + ", 127)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(" + timestamp2 + "," + timestamp2 + ", 127)");
stmt.close(); stmt.close();
} }
...@@ -54,7 +54,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -54,7 +54,7 @@ public class TimestampPrecisonInNanoRestTest {
stmt.execute("drop database if exists " + ns_timestamp_db); stmt.execute("drop database if exists " + ns_timestamp_db);
stmt.execute("create database if not exists " + ns_timestamp_db + " precision 'ns'"); stmt.execute("create database if not exists " + ns_timestamp_db + " precision 'ns'");
stmt.execute("create table " + ns_timestamp_db + ".weather(ts timestamp, ts2 timestamp, f1 int)"); stmt.execute("create table " + ns_timestamp_db + ".weather(ts timestamp, ts2 timestamp, f1 int)");
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date3 + "\", \"" + date3 + "\", 128)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date3 + "\", \"" + date3 + "\", 128)");
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(" + timestamp2 + "," + timestamp2 + ", 127)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(" + timestamp2 + "," + timestamp2 + ", 127)");
stmt.close(); stmt.close();
} }
...@@ -105,7 +105,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -105,7 +105,7 @@ public class TimestampPrecisonInNanoRestTest {
@Test @Test
public void canImportTimestampAndQueryByEqualToInDateTypeInBothFirstAndSecondCol() { public void canImportTimestampAndQueryByEqualToInDateTypeInBothFirstAndSecondCol() {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("import into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date1 + "123123\", \"" + date1 + "123123\", 127)"); stmt.executeUpdate("import into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(\"" + date1 + "123123\", \"" + date1 + "123123\", 127)");
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + date1 + "123123'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + date1 + "123123'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts = '" + date1 + "123123'"); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts = '" + date1 + "123123'");
...@@ -139,7 +139,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -139,7 +139,7 @@ public class TimestampPrecisonInNanoRestTest {
public void canImportTimestampAndQueryByEqualToInNumberTypeInBothFirstAndSecondCol() { public void canImportTimestampAndQueryByEqualToInNumberTypeInBothFirstAndSecondCol() {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
long timestamp4 = timestamp1 * 1000_000 + 123123; long timestamp4 = timestamp1 * 1000_000 + 123123;
stmt.executeUpdate("import into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(" + timestamp4 + ", " + timestamp4 + ", 127)"); stmt.executeUpdate("import into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(" + timestamp4 + ", " + timestamp4 + ", 127)");
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + timestamp4 + "'"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather where ts = '" + timestamp4 + "'");
checkCount(1l, rs); checkCount(1l, rs);
rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts = '" + timestamp4 + "'"); rs = stmt.executeQuery("select ts from " + ns_timestamp_db + ".weather where ts = '" + timestamp4 + "'");
...@@ -215,7 +215,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -215,7 +215,7 @@ public class TimestampPrecisonInNanoRestTest {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLargerThanInNumberTypeForFirstCol() { public void canQueryLargerThanInNumberTypeForFirstCol() {
...@@ -279,7 +279,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -279,7 +279,7 @@ public class TimestampPrecisonInNanoRestTest {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLessThanInDateTypeForFirstCol() { public void canQueryLessThanInDateTypeForFirstCol() {
...@@ -347,7 +347,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -347,7 +347,7 @@ public class TimestampPrecisonInNanoRestTest {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test @Test
public void canQueryLessThanOrEqualToInNumberTypeForFirstCol() { public void canQueryLessThanOrEqualToInNumberTypeForFirstCol() {
...@@ -466,7 +466,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -466,7 +466,7 @@ public class TimestampPrecisonInNanoRestTest {
} }
@Test @Test
public void canInsertTimestampWithNowAndNsOffsetInBothFirstAndSecondCol(){ public void canInsertTimestampWithNowAndNsOffsetInBothFirstAndSecondCol() {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(now + 1000b, now - 1000b, 128)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(now + 1000b, now - 1000b, 128)");
ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather"); ResultSet rs = stmt.executeQuery("select count(*) from " + ns_timestamp_db + ".weather");
...@@ -477,7 +477,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -477,7 +477,7 @@ public class TimestampPrecisonInNanoRestTest {
} }
@Test @Test
public void canIntervalAndSlidingAcceptNsUnitForFirstCol(){ public void canIntervalAndSlidingAcceptNsUnitForFirstCol() {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select sum(f1) from " + ns_timestamp_db + ".weather where ts >= '" + date2 + "' and ts <= '" + date3 + "' interval(10000000b) sliding(10000000b)"); ResultSet rs = stmt.executeQuery("select sum(f1) from " + ns_timestamp_db + ".weather where ts >= '" + date2 + "' and ts <= '" + date3 + "' interval(10000000b) sliding(10000000b)");
rs.next(); rs.next();
...@@ -492,7 +492,7 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -492,7 +492,7 @@ public class TimestampPrecisonInNanoRestTest {
} }
@Test @Test
public void canIntervalAndSlidingAcceptNsUnitForSecondCol(){ public void canIntervalAndSlidingAcceptNsUnitForSecondCol() {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("select sum(f1) from " + ns_timestamp_db + ".weather where ts2 >= '" + date2 + "' and ts <= '" + date3 + "' interval(10000000b) sliding(10000000b)"); ResultSet rs = stmt.executeQuery("select sum(f1) from " + ns_timestamp_db + ".weather where ts2 >= '" + date2 + "' and ts <= '" + date3 + "' interval(10000000b) sliding(10000000b)");
rs.next(); rs.next();
...@@ -506,21 +506,17 @@ public class TimestampPrecisonInNanoRestTest { ...@@ -506,21 +506,17 @@ public class TimestampPrecisonInNanoRestTest {
} }
} }
@Test @Test(expected = SQLException.class)
public void testDataOutOfRangeExceptionForFirstCol() { public void testDataOutOfRangeExceptionForFirstCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(123456789012345678, 1234567890123456789, 127)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(123456789012345678, 1234567890123456789, 127)");
} catch (SQLException e) {
Assert.assertEquals("TDengine ERROR (60b): Timestamp data out of range", e.getMessage());
} }
} }
@Test @Test(expected = SQLException.class)
public void testDataOutOfRangeExceptionForSecondCol() { public void testDataOutOfRangeExceptionForSecondCol() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(1234567890123456789, 123456789012345678, 127)"); stmt.executeUpdate("insert into " + ns_timestamp_db + ".weather(ts, ts2, f1) values(1234567890123456789, 123456789012345678, 127)");
} catch (SQLException e) {
Assert.assertEquals("TDengine ERROR (60b): Timestamp data out of range", e.getMessage());
} }
} }
......
...@@ -373,11 +373,12 @@ public class RestfulConnectionTest { ...@@ -373,11 +373,12 @@ public class RestfulConnectionTest {
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/log?user=root&password=taosdata", properties); conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata", properties);
// create test database for test cases // create test database for test cases
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.execute("create database if not exists test"); stmt.execute("create database if not exists test");
} }
} }
@AfterClass @AfterClass
......
...@@ -9,9 +9,10 @@ import java.util.Random; ...@@ -9,9 +9,10 @@ import java.util.Random;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RestfulJDBCTest { public class RestfulJDBCTest {
private static final String host = "127.0.0.1"; // private static final String host = "127.0.0.1";
private final Random random = new Random(System.currentTimeMillis()); private static final String host = "master";
private Connection connection; private static final Random random = new Random(System.currentTimeMillis());
private static Connection connection;
@Test @Test
public void testCase001() throws SQLException { public void testCase001() throws SQLException {
...@@ -129,15 +130,23 @@ public class RestfulJDBCTest { ...@@ -129,15 +130,23 @@ public class RestfulJDBCTest {
} }
} }
@Before @BeforeClass
public void before() throws SQLException { public static void beforeClass() {
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata&httpKeepAlive=false"); try {
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
} catch (SQLException e) {
e.printStackTrace();
}
} }
@After @AfterClass
public void after() throws SQLException { public static void afterClass() throws SQLException {
if (connection != null) if (connection != null) {
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists restful_test");
stmt.close();
connection.close(); connection.close();
}
} }
} }
...@@ -186,22 +186,17 @@ public class RestfulResultSetMetaDataTest { ...@@ -186,22 +186,17 @@ public class RestfulResultSetMetaDataTest {
} }
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() throws SQLException {
try { conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); stmt = conn.createStatement();
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata"); stmt.execute("create database if not exists restful_test");
stmt = conn.createStatement(); stmt.execute("use restful_test");
stmt.execute("create database if not exists restful_test"); stmt.execute("drop table if exists weather");
stmt.execute("use restful_test"); stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))");
stmt.execute("drop table if exists weather"); stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')");
stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))"); rs = stmt.executeQuery("select * from restful_test.weather");
stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"); rs.next();
rs = stmt.executeQuery("select * from restful_test.weather"); meta = rs.getMetaData();
rs.next();
meta = rs.getMetaData();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
} }
@AfterClass @AfterClass
......
...@@ -17,7 +17,8 @@ import java.text.SimpleDateFormat; ...@@ -17,7 +17,8 @@ import java.text.SimpleDateFormat;
public class RestfulResultSetTest { public class RestfulResultSetTest {
private static final String host = "127.0.0.1"; // private static final String host = "127.0.0.1";
private static final String host = "master";
private static Connection conn; private static Connection conn;
private static Statement stmt; private static Statement stmt;
private static ResultSet rs; private static ResultSet rs;
...@@ -658,35 +659,29 @@ public class RestfulResultSetTest { ...@@ -658,35 +659,29 @@ public class RestfulResultSetTest {
} }
@BeforeClass @BeforeClass
public static void beforeClass() { public static void beforeClass() throws SQLException {
try { conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata"); stmt = conn.createStatement();
stmt = conn.createStatement(); stmt.execute("drop database if exists restful_test");
stmt.execute("create database if not exists restful_test"); stmt.execute("create database if not exists restful_test");
stmt.execute("use restful_test"); stmt.execute("use restful_test");
stmt.execute("drop table if exists weather"); stmt.execute("drop table if exists weather");
stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))"); stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))");
stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')"); stmt.execute("insert into restful_test.weather values('2021-01-01 00:00:00.000', 1, 100, 3.1415, 3.1415926, 'abc', 10, 10, true, '涛思数据')");
rs = stmt.executeQuery("select * from restful_test.weather"); rs = stmt.executeQuery("select * from restful_test.weather");
rs.next(); rs.next();
} catch (SQLException e) {
e.printStackTrace();
}
} }
@AfterClass @AfterClass
public static void afterClass() { public static void afterClass() throws SQLException {
try { if (rs != null)
if (rs != null) rs.close();
rs.close(); if (stmt != null) {
if (stmt != null) stmt.execute("drop database if exists restful_test");
stmt.close(); stmt.close();
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} }
if (conn != null)
conn.close();
} }
} }
\ No newline at end of file
...@@ -572,11 +572,14 @@ public class SQLTest { ...@@ -572,11 +572,14 @@ public class SQLTest {
@BeforeClass @BeforeClass
public static void before() throws SQLException { public static void before() throws SQLException {
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata"); connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
} }
@AfterClass @AfterClass
public static void after() throws SQLException { public static void after() throws SQLException {
Statement stmt = connection.createStatement();
stmt.execute("drop database if exists restful_test");
stmt.close();
connection.close(); connection.close();
} }
......
package com.taosdata.jdbc.rs; package com.taosdata.jdbc.rs;
import org.junit.*; import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.sql.*; import java.sql.*;
...@@ -9,9 +12,8 @@ public class WasNullTest { ...@@ -9,9 +12,8 @@ public class WasNullTest {
private static final String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private Connection conn; private Connection conn;
@Test @Test
public void testGetTimestamp() { public void testGetTimestamp() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.execute("drop table if exists weather"); stmt.execute("drop table if exists weather");
stmt.execute("create table if not exists weather(f1 timestamp, f2 timestamp, f3 int)"); stmt.execute("create table if not exists weather(f1 timestamp, f2 timestamp, f3 int)");
...@@ -34,14 +36,11 @@ public class WasNullTest { ...@@ -34,14 +36,11 @@ public class WasNullTest {
} }
} }
} }
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Test @Test
public void testGetObject() { public void testGetObject() throws SQLException {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
stmt.execute("drop table if exists weather"); stmt.execute("drop table if exists weather");
stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))"); stmt.execute("create table if not exists weather(f1 timestamp, f2 int, f3 bigint, f4 float, f5 double, f6 binary(64), f7 smallint, f8 tinyint, f9 bool, f10 nchar(64))");
...@@ -63,32 +62,25 @@ public class WasNullTest { ...@@ -63,32 +62,25 @@ public class WasNullTest {
} }
} }
} catch (SQLException e) {
e.printStackTrace();
} }
} }
@Before @Before
public void before() { public void before() throws SQLException {
try { conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata");
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata"); try (Statement stmt = conn.createStatement()) {
Statement stmt = conn.createStatement();
stmt.execute("drop database if exists restful_test"); stmt.execute("drop database if exists restful_test");
stmt.execute("create database if not exists restful_test"); stmt.execute("create database if not exists restful_test");
} catch (SQLException e) { stmt.execute("use restful_test");
e.printStackTrace();
} }
} }
@After @After
public void after() { public void after() throws SQLException {
try { if (conn != null) {
Statement statement = conn.createStatement(); Statement statement = conn.createStatement();
statement.execute("drop database if exists restful_test"); statement.execute("drop database if exists restful_test");
if (conn != null) conn.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册