commit
9e3196c48d
|
@ -126,7 +126,7 @@
|
||||||
<include>**/*Test.java</include>
|
<include>**/*Test.java</include>
|
||||||
</includes>
|
</includes>
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>**/BatchInsertTest.java</exclude>
|
<exclude>**/AppMemoryLeakTest.java</exclude>
|
||||||
<exclude>**/FailOverTest.java</exclude>
|
<exclude>**/FailOverTest.java</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
<testFailureIgnore>true</testFailureIgnore>
|
<testFailureIgnore>true</testFailureIgnore>
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.Map;
|
||||||
|
|
||||||
public abstract class TSDBConstants {
|
public abstract class TSDBConstants {
|
||||||
|
|
||||||
|
public static final String STATEMENT_CLOSED = "Statement already closed.";
|
||||||
public static final String DEFAULT_PORT = "6200";
|
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 UNSUPPORT_METHOD_EXCEPTIONZ_MSG = "this operation is NOT supported currently!";
|
||||||
public static final String INVALID_VARIABLES = "invalid variables";
|
public static final String INVALID_VARIABLES = "invalid variables";
|
||||||
|
|
|
@ -100,7 +100,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
* order to process those supported SQLs.
|
* order to process those supported SQLs.
|
||||||
*/
|
*/
|
||||||
private void preprocessSql() {
|
private void preprocessSql() {
|
||||||
|
|
||||||
/***** For processing some of Spark SQLs*****/
|
/***** For processing some of Spark SQLs*****/
|
||||||
// should replace it first
|
// should replace it first
|
||||||
this.rawSql = this.rawSql.replaceAll("or (.*) is null", "");
|
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);
|
rawSql = rawSql.replace(matcher.group(1), tableFullName);
|
||||||
}
|
}
|
||||||
/***** for inner queries *****/
|
/***** for inner queries *****/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,7 +194,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNull(int parameterIndex, int sqlType) throws SQLException {
|
public void setNull(int parameterIndex, int sqlType) throws SQLException {
|
||||||
setObject(parameterIndex, new String("NULL"));
|
setObject(parameterIndex, "NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -52,12 +52,18 @@ public class TSDBStatement implements Statement {
|
||||||
this.isClosed = false;
|
this.isClosed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
public <T> T unwrap(Class<T> 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 {
|
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 {
|
public ResultSet executeQuery(String sql) throws SQLException {
|
||||||
|
@ -130,10 +136,15 @@ public class TSDBStatement implements Statement {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxFieldSize(int max) throws SQLException {
|
public void setMaxFieldSize(int max) throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
|
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxRows() throws SQLException {
|
public int getMaxRows() throws SQLException {
|
||||||
|
if (isClosed())
|
||||||
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
// always set maxRows to zero, meaning unlimitted rows in a resultSet
|
// always set maxRows to zero, meaning unlimitted rows in a resultSet
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class RestfulStatement implements Statement {
|
public class RestfulStatement implements Statement {
|
||||||
|
|
||||||
private static final String STATEMENT_CLOSED = "Statement already closed.";
|
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
private String database;
|
private String database;
|
||||||
private final RestfulConnection conn;
|
private final RestfulConnection conn;
|
||||||
|
@ -108,14 +107,14 @@ public class RestfulStatement implements Statement {
|
||||||
@Override
|
@Override
|
||||||
public int getMaxFieldSize() throws SQLException {
|
public int getMaxFieldSize() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return TSDBConstants.maxFieldSize;
|
return TSDBConstants.maxFieldSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMaxFieldSize(int max) throws SQLException {
|
public void setMaxFieldSize(int max) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
if (max < 0)
|
if (max < 0)
|
||||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||||
// nothing to do
|
// nothing to do
|
||||||
|
@ -124,14 +123,14 @@ public class RestfulStatement implements Statement {
|
||||||
@Override
|
@Override
|
||||||
public int getMaxRows() throws SQLException {
|
public int getMaxRows() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMaxRows(int max) throws SQLException {
|
public void setMaxRows(int max) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
if (max < 0)
|
if (max < 0)
|
||||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||||
// nothing to do
|
// nothing to do
|
||||||
|
@ -140,20 +139,20 @@ public class RestfulStatement implements Statement {
|
||||||
@Override
|
@Override
|
||||||
public void setEscapeProcessing(boolean enable) throws SQLException {
|
public void setEscapeProcessing(boolean enable) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(RestfulStatement.STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getQueryTimeout() throws SQLException {
|
public int getQueryTimeout() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setQueryTimeout(int seconds) throws SQLException {
|
public void setQueryTimeout(int seconds) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
if (seconds < 0)
|
if (seconds < 0)
|
||||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||||
}
|
}
|
||||||
|
@ -166,7 +165,7 @@ public class RestfulStatement implements Statement {
|
||||||
@Override
|
@Override
|
||||||
public SQLWarning getWarnings() throws SQLException {
|
public SQLWarning getWarnings() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,13 +173,13 @@ public class RestfulStatement implements Statement {
|
||||||
public void clearWarnings() throws SQLException {
|
public void clearWarnings() throws SQLException {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCursorName(String name) throws SQLException {
|
public void setCursorName(String name) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(RestfulStatement.STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,7 +259,7 @@ public class RestfulStatement implements Statement {
|
||||||
@Override
|
@Override
|
||||||
public ResultSet getResultSet() throws SQLException {
|
public ResultSet getResultSet() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return resultSet;
|
return resultSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +291,7 @@ public class RestfulStatement implements Statement {
|
||||||
@Override
|
@Override
|
||||||
public void setFetchSize(int rows) throws SQLException {
|
public void setFetchSize(int rows) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
if (rows < 0)
|
if (rows < 0)
|
||||||
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
throw new SQLException(TSDBConstants.INVALID_VARIABLES);
|
||||||
//nothing to do
|
//nothing to do
|
||||||
|
@ -301,28 +300,28 @@ public class RestfulStatement implements Statement {
|
||||||
@Override
|
@Override
|
||||||
public int getFetchSize() throws SQLException {
|
public int getFetchSize() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getResultSetConcurrency() throws SQLException {
|
public int getResultSetConcurrency() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return this.resultSet.getConcurrency();
|
return this.resultSet.getConcurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getResultSetType() throws SQLException {
|
public int getResultSetType() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return this.resultSet.getType();
|
return this.resultSet.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addBatch(String sql) throws SQLException {
|
public void addBatch(String sql) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
//TODO:
|
//TODO:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,14 +339,14 @@ public class RestfulStatement implements Statement {
|
||||||
@Override
|
@Override
|
||||||
public Connection getConnection() throws SQLException {
|
public Connection getConnection() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return this.conn;
|
return this.conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getMoreResults(int current) throws SQLException {
|
public boolean getMoreResults(int current) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
if (resultSet == null)
|
if (resultSet == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -405,7 +404,7 @@ public class RestfulStatement implements Statement {
|
||||||
@Override
|
@Override
|
||||||
public int getResultSetHoldability() throws SQLException {
|
public int getResultSetHoldability() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return this.resultSet.getHoldability();
|
return this.resultSet.getHoldability();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,28 +416,28 @@ public class RestfulStatement implements Statement {
|
||||||
@Override
|
@Override
|
||||||
public void setPoolable(boolean poolable) throws SQLException {
|
public void setPoolable(boolean poolable) throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
//nothing to do
|
//nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isPoolable() throws SQLException {
|
public boolean isPoolable() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeOnCompletion() throws SQLException {
|
public void closeOnCompletion() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
this.closeOnCompletion = true;
|
this.closeOnCompletion = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCloseOnCompletion() throws SQLException {
|
public boolean isCloseOnCompletion() throws SQLException {
|
||||||
if (isClosed())
|
if (isClosed())
|
||||||
throw new SQLException(STATEMENT_CLOSED);
|
throw new SQLException(TSDBConstants.STATEMENT_CLOSED);
|
||||||
return this.closeOnCompletion;
|
return this.closeOnCompletion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,9 +1,7 @@
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.*;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.runners.MethodSorters;
|
||||||
import org.junit.FixMethodOrder;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -11,14 +9,13 @@ import java.util.Properties;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@FixMethodOrder()
|
@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
|
||||||
public class PreparedStatementTest extends BaseTest {
|
public class PreparedStatementTest {
|
||||||
static Connection connection = null;
|
static Connection connection;
|
||||||
static PreparedStatement statement = null;
|
static TSDBPreparedStatement statement;
|
||||||
static String dbName = "test";
|
static String dbName = "test";
|
||||||
static String tName = "t0";
|
static String tName = "t0";
|
||||||
static String host = "localhost";
|
static String host = "localhost";
|
||||||
static ResultSet resSet = null;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void createConnection() throws SQLException {
|
public static void createConnection() throws SQLException {
|
||||||
|
@ -28,19 +25,16 @@ public class PreparedStatementTest extends BaseTest {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Properties properties = new 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_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");
|
||||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||||
|
|
||||||
String sql = "drop database if exists " + dbName;
|
String sql = "drop database if exists " + dbName;
|
||||||
statement = (TSDBPreparedStatement) connection.prepareStatement(sql);
|
statement = (TSDBPreparedStatement) connection.prepareStatement(sql);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createTableAndQuery() throws SQLException {
|
public void case001_createTableAndQuery() throws SQLException {
|
||||||
long ts = System.currentTimeMillis();
|
long ts = System.currentTimeMillis();
|
||||||
|
|
||||||
statement.executeUpdate("create database if not exists " + dbName);
|
statement.executeUpdate("create database if not exists " + dbName);
|
||||||
|
@ -48,141 +42,132 @@ public class PreparedStatementTest extends BaseTest {
|
||||||
statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
|
statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
|
||||||
|
|
||||||
PreparedStatement selectStatement = connection.prepareStatement("select * from " + dbName + "." + tName);
|
PreparedStatement selectStatement = connection.prepareStatement("select * from " + dbName + "." + tName);
|
||||||
|
|
||||||
ResultSet resultSet = selectStatement.executeQuery();
|
ResultSet resultSet = selectStatement.executeQuery();
|
||||||
assertTrue(null != resultSet);
|
assertTrue(null != resultSet);
|
||||||
|
|
||||||
boolean isClosed = statement.isClosed();
|
boolean isClosed = statement.isClosed();
|
||||||
assertEquals(false, isClosed);
|
assertEquals(false, isClosed);
|
||||||
|
selectStatement.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreparedStatement() throws SQLException {
|
public void case002_testPreparedStatement() throws SQLException {
|
||||||
long ts = System.currentTimeMillis() + 20000;
|
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();
|
int affectedRows = saveStatement.executeUpdate();
|
||||||
assertTrue(1 == affectedRows);
|
assertTrue(1 == affectedRows);
|
||||||
|
saveStatement.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSavedPreparedStatement() throws SQLException {
|
public void case003_testSavedPreparedStatement() throws SQLException {
|
||||||
long ts = System.currentTimeMillis();
|
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(1, ts + 10000);
|
||||||
saveStatement.setObject(2, 3);
|
saveStatement.setObject(2, 3);
|
||||||
int rows = saveStatement.executeUpdate();
|
int rows = saveStatement.executeUpdate();
|
||||||
assertEquals(1, rows);
|
assertEquals(1, rows);
|
||||||
|
saveStatement.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnsupport() {
|
public void case004_testUnsupport() throws SQLException {
|
||||||
// if(null == resSet) {
|
|
||||||
// return;
|
Assert.assertNotNull(statement.unwrap(TSDBPreparedStatement.class));
|
||||||
// }
|
Assert.assertTrue(statement.isWrapperFor(TSDBPreparedStatement.class));
|
||||||
TSDBPreparedStatement tsdbStatement = (TSDBPreparedStatement) statement;
|
|
||||||
try {
|
try {
|
||||||
tsdbStatement.unwrap(null);
|
statement.getMaxFieldSize();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.isWrapperFor(null);
|
statement.setMaxFieldSize(0);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.getMaxFieldSize();
|
statement.setEscapeProcessing(true);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.setMaxFieldSize(0);
|
statement.cancel();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.setEscapeProcessing(true);
|
statement.getWarnings();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.cancel();
|
statement.clearWarnings();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.getWarnings();
|
statement.setCursorName(null);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.clearWarnings();
|
statement.getMoreResults();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.setCursorName(null);
|
statement.setFetchDirection(0);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.getMoreResults();
|
statement.getFetchDirection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.setFetchDirection(0);
|
statement.getResultSetConcurrency();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.getFetchDirection();
|
statement.getResultSetType();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.getResultSetConcurrency();
|
statement.getConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.getResultSetType();
|
statement.getMoreResults();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.getConnection();
|
statement.getGeneratedKeys();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.getMoreResults();
|
statement.executeUpdate(null, 0);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.getGeneratedKeys();
|
statement.executeUpdate(null, new int[]{0});
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.executeUpdate(null, 0);
|
statement.executeUpdate(null, new String[]{"str1", "str2"});
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.executeUpdate(null, new int[]{0});
|
statement.getResultSetHoldability();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.executeUpdate(null, new String[]{"str1", "str2"});
|
statement.setPoolable(true);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.getResultSetHoldability();
|
statement.isPoolable();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.setPoolable(true);
|
statement.closeOnCompletion();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
tsdbStatement.isPoolable();
|
statement.isCloseOnCompletion();
|
||||||
} catch (SQLException e) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
tsdbStatement.closeOnCompletion();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
tsdbStatement.isCloseOnCompletion();
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,76 +6,67 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
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;
|
||||||
|
static Statement statement;
|
||||||
static Connection connection = null;
|
|
||||||
static Statement statement = null;
|
|
||||||
static String dbName = "test";
|
static String dbName = "test";
|
||||||
static String stbName = "meters";
|
static String stbName = "meters";
|
||||||
static String host = "localhost";
|
static String host = "127.0.0.1";
|
||||||
static int numOfTables = 30;
|
|
||||||
final static int numOfRecordsPerTable = 1000;
|
|
||||||
static long ts = 1496732686000l;
|
|
||||||
final static String tablePrefix = "t";
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createDatabase() throws SQLException {
|
public void createDatabase() {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
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;
|
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);
|
statement.executeUpdate(insertSql);
|
||||||
|
|
||||||
String querySql = "select * from " + stbName;
|
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";
|
String name = rs.getString(2);
|
||||||
System.out.println("name = " + name);
|
System.out.println("name = " + name);
|
||||||
assertEquals(name, "taosda001");
|
assertEquals("taosdata", name);
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void close() throws Exception {
|
public void close() {
|
||||||
statement.close();
|
try {
|
||||||
connection.close();
|
if (statement != null)
|
||||||
Thread.sleep(10);
|
statement.close();
|
||||||
|
if (connection != null)
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -13,42 +14,37 @@ import java.util.Properties;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class ResultSetTest extends BaseTest {
|
public class ResultSetTest {
|
||||||
static Connection connection = null;
|
static Connection connection;
|
||||||
static Statement statement = null;
|
static Statement statement;
|
||||||
static String dbName = "test";
|
static String dbName = "test";
|
||||||
static String tName = "t0";
|
static String tName = "t0";
|
||||||
static String host = "localhost";
|
static String host = "localhost";
|
||||||
static ResultSet resSet = null;
|
static ResultSet resSet;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void createDatabaseAndTable() throws SQLException {
|
public static void createDatabaseAndTable() {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
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;
|
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
|
@Test
|
||||||
public void testResultSet() {
|
public void testResultSet() {
|
||||||
String sql = null;
|
String sql;
|
||||||
long ts = 1496732686000l;
|
long ts = 1496732686000l;
|
||||||
int v1 = 2147483600;
|
int v1 = 2147483600;
|
||||||
long v2 = ts + 1000;
|
long v2 = ts + 1000;
|
||||||
|
@ -119,16 +115,8 @@ public class ResultSetTest extends BaseTest {
|
||||||
public void testUnsupport() throws SQLException {
|
public void testUnsupport() throws SQLException {
|
||||||
statement.executeQuery("show databases");
|
statement.executeQuery("show databases");
|
||||||
resSet = statement.getResultSet();
|
resSet = statement.getResultSet();
|
||||||
try {
|
Assert.assertNotNull(resSet.unwrap(TSDBResultSet.class));
|
||||||
resSet.unwrap(null);
|
Assert.assertTrue(resSet.isWrapperFor(TSDBResultSet.class));
|
||||||
} 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!"));
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
resSet.getAsciiStream(0);
|
resSet.getAsciiStream(0);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
@ -815,13 +803,18 @@ public class ResultSetTest extends BaseTest {
|
||||||
assertEquals(res.length, 2);
|
assertEquals(res.length, 2);
|
||||||
statement.clearBatch();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class StableTest {
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
|
statement.execute("drop database if exists " + dbName);
|
||||||
statement.execute("create database if not exists " + dbName);
|
statement.execute("create database if not exists " + dbName);
|
||||||
statement.execute("use " + dbName);
|
statement.execute("use " + dbName);
|
||||||
statement.close();
|
statement.close();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.taosdata.jdbc;
|
package com.taosdata.jdbc;
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -16,23 +17,22 @@ public class StatementTest {
|
||||||
static String dbName = "test";
|
static String dbName = "test";
|
||||||
static String tName = "t0";
|
static String tName = "t0";
|
||||||
static String host = "localhost";
|
static String host = "localhost";
|
||||||
static ResultSet resSet = null;
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void createConnection() throws SQLException {
|
public static void createConnection() throws SQLException {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
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) {
|
} catch (ClassNotFoundException e) {
|
||||||
return;
|
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
|
@Test
|
||||||
|
@ -49,7 +49,6 @@ public class StatementTest {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -67,118 +66,46 @@ public class StatementTest {
|
||||||
assertEquals(false, isClosed);
|
assertEquals(false, isClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = SQLException.class)
|
||||||
public void testUnsupport() {
|
public void testUnsupport() throws SQLException {
|
||||||
TSDBStatement tsdbStatement = (TSDBStatement) statement;
|
Assert.assertNotNull(statement.unwrap(TSDBStatement.class));
|
||||||
try {
|
Assert.assertTrue(statement.isWrapperFor(TSDBStatement.class));
|
||||||
tsdbStatement.unwrap(null);
|
|
||||||
} catch (SQLException e) {
|
statement.getMaxFieldSize();
|
||||||
}
|
statement.setMaxFieldSize(0);
|
||||||
try {
|
statement.setEscapeProcessing(true);
|
||||||
tsdbStatement.isWrapperFor(null);
|
statement.cancel();
|
||||||
} catch (SQLException e) {
|
statement.getWarnings();
|
||||||
}
|
statement.clearWarnings();
|
||||||
try {
|
statement.setCursorName(null);
|
||||||
tsdbStatement.getMaxFieldSize();
|
statement.getMoreResults();
|
||||||
} catch (SQLException e) {
|
statement.setFetchDirection(0);
|
||||||
}
|
statement.getFetchDirection();
|
||||||
try {
|
statement.getResultSetConcurrency();
|
||||||
tsdbStatement.setMaxFieldSize(0);
|
statement.getResultSetType();
|
||||||
} catch (SQLException e) {
|
statement.getConnection();
|
||||||
}
|
statement.getMoreResults();
|
||||||
try {
|
statement.getGeneratedKeys();
|
||||||
tsdbStatement.setEscapeProcessing(true);
|
statement.executeUpdate(null, 0);
|
||||||
} catch (SQLException e) {
|
statement.executeUpdate(null, new int[]{0});
|
||||||
}
|
statement.executeUpdate(null, new String[]{"str1", "str2"});
|
||||||
try {
|
statement.getResultSetHoldability();
|
||||||
tsdbStatement.cancel();
|
statement.setPoolable(true);
|
||||||
} catch (SQLException e) {
|
statement.isPoolable();
|
||||||
}
|
statement.closeOnCompletion();
|
||||||
try {
|
statement.isCloseOnCompletion();
|
||||||
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();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void close() throws Exception {
|
public static void close() {
|
||||||
if (!statement.isClosed()) {
|
try {
|
||||||
statement.executeUpdate("drop database if exists " + dbName);
|
statement.execute("drop database if exists " + dbName);
|
||||||
statement.close();
|
if (statement != null)
|
||||||
connection.close();
|
statement.close();
|
||||||
Thread.sleep(10);
|
if (connection != null)
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,36 +10,37 @@ import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class SubscribeTest extends BaseTest {
|
public class SubscribeTest {
|
||||||
Connection connection = null;
|
Connection connection;
|
||||||
Statement statement = null;
|
Statement statement;
|
||||||
String dbName = "test";
|
String dbName = "test";
|
||||||
String tName = "t0";
|
String tName = "t0";
|
||||||
String host = "localhost";
|
String host = "localhost";
|
||||||
String topic = "test";
|
String topic = "test";
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createDatabase() throws SQLException {
|
public void createDatabase() {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
} catch (ClassNotFoundException e) {
|
Properties properties = new Properties();
|
||||||
return;
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||||
}
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||||
Properties properties = new Properties();
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||||
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 = connection.createStatement();
|
||||||
statement.executeUpdate("create database if not exists " + dbName);
|
statement.executeUpdate("create database if not exists " + dbName);
|
||||||
statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
|
statement.executeUpdate("create table if not exists " + dbName + "." + tName + " (ts timestamp, k int, v int)");
|
||||||
long ts = System.currentTimeMillis();
|
long ts = System.currentTimeMillis();
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
ts += i;
|
ts += i;
|
||||||
String sql = "insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")";
|
String sql = "insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")";
|
||||||
statement.executeUpdate(sql);
|
statement.executeUpdate(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,10 +80,16 @@ public class SubscribeTest extends BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void close() throws Exception {
|
public void close() {
|
||||||
statement.executeQuery("drop database " + dbName);
|
try {
|
||||||
statement.close();
|
statement.executeQuery("drop database " + dbName);
|
||||||
connection.close();
|
if (statement != null)
|
||||||
Thread.sleep(10);
|
statement.close();
|
||||||
|
if (connection != null)
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,37 +6,9 @@ import java.sql.*;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class TSDBDatabaseMetaDataTest {
|
public class TSDBDatabaseMetaDataTest {
|
||||||
private TSDBDatabaseMetaData metaData;
|
|
||||||
private static final String host = "127.0.0.1";
|
private static final String host = "127.0.0.1";
|
||||||
private Connection connection;
|
private static Connection connection;
|
||||||
|
private static TSDBDatabaseMetaData metaData;
|
||||||
@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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unwrap() throws SQLException {
|
public void unwrap() throws SQLException {
|
||||||
|
@ -61,7 +33,7 @@ public class TSDBDatabaseMetaDataTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getURL() throws SQLException {
|
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
|
@Test
|
||||||
|
@ -975,4 +947,32 @@ public class TSDBDatabaseMetaDataTest {
|
||||||
public void generatedKeyAlwaysReturned() throws SQLException {
|
public void generatedKeyAlwaysReturned() throws SQLException {
|
||||||
Assert.assertFalse(metaData.generatedKeyAlwaysReturned());
|
Assert.assertFalse(metaData.generatedKeyAlwaysReturned());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() {
|
||||||
|
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 + ":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 afterClass() {
|
||||||
|
try {
|
||||||
|
if (connection != null)
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,9 +3,6 @@ package com.taosdata.jdbc;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
@ -27,54 +24,15 @@ public class TSDBDriverTest {
|
||||||
"jdbc:TAOS://:/test",
|
"jdbc:TAOS://:/test",
|
||||||
"jdbc:TAOS://localhost:0/?user=root&password=taosdata"
|
"jdbc:TAOS://localhost:0/?user=root&password=taosdata"
|
||||||
};
|
};
|
||||||
private static boolean islibLoaded = false;
|
|
||||||
private static boolean isTaosdActived;
|
|
||||||
|
|
||||||
private Connection conn;
|
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
|
@Test
|
||||||
public void testConnectWithJdbcURL() {
|
public void testConnectWithJdbcURL() {
|
||||||
final String url = "jdbc:TAOS://localhost:6030/log?user=root&password=taosdata";
|
final String url = "jdbc:TAOS://localhost:6030/log?user=root&password=taosdata";
|
||||||
try {
|
try {
|
||||||
if (islibLoaded && isTaosdActived) {
|
conn = DriverManager.getConnection(url);
|
||||||
conn = DriverManager.getConnection(url);
|
assertNotNull("failure - connection should not be null", conn);
|
||||||
assertNotNull("failure - connection should not be null", conn);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail("failure - should not throw Exception");
|
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_LOCALE, "en_US.UTF-8");
|
||||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
try {
|
try {
|
||||||
if (islibLoaded && isTaosdActived) {
|
conn = DriverManager.getConnection(jdbcUrl, connProps);
|
||||||
conn = DriverManager.getConnection(jdbcUrl, connProps);
|
assertNotNull("failure - connection should not be null", conn);
|
||||||
assertNotNull("failure - connection should not be null", conn);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail("failure - should not throw Exception");
|
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_LOCALE, "en_US.UTF-8");
|
||||||
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
try {
|
try {
|
||||||
if (islibLoaded && isTaosdActived) {
|
conn = DriverManager.getConnection(jdbcUrl, connProps);
|
||||||
conn = DriverManager.getConnection(jdbcUrl, connProps);
|
assertNotNull("failure - connection should not be null", conn);
|
||||||
assertNotNull("failure - connection should not be null", conn);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail("failure - should not throw Exception");
|
fail("failure - should not throw Exception");
|
||||||
|
@ -207,4 +161,14 @@ public class TSDBDriverTest {
|
||||||
assertNull("failure - getParentLogger should be be null", new TSDBDriver().getParentLogger());
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -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/?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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,14 +1,12 @@
|
||||||
package com.taosdata.jdbc.cases;
|
package com.taosdata.jdbc.cases;
|
||||||
|
|
||||||
import com.taosdata.jdbc.lib.TSDBCommon;
|
import com.taosdata.jdbc.TSDBDriver;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.ResultSet;
|
import java.util.Properties;
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
@ -18,57 +16,71 @@ import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class BatchInsertTest {
|
public class BatchInsertTest {
|
||||||
|
|
||||||
static String host = "localhost";
|
static String host = "127.0.0.1";
|
||||||
static String dbName = "test";
|
static String dbName = "test";
|
||||||
static String stbName = "meters";
|
static String stbName = "meters";
|
||||||
static int numOfTables = 30;
|
static int numOfTables = 30;
|
||||||
final static int numOfRecordsPerTable = 1000;
|
final static int numOfRecordsPerTable = 1000;
|
||||||
static long ts = 1496732686000l;
|
static long ts = 1496732686000l;
|
||||||
final static String tablePrefix = "t";
|
final static String tablePrefix = "t";
|
||||||
|
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() {
|
public void before() {
|
||||||
try {
|
try {
|
||||||
connection = TSDBCommon.getConn(host);
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
TSDBCommon.createDatabase(connection, dbName);
|
Properties properties = new Properties();
|
||||||
TSDBCommon.createStable(connection, stbName);
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||||
TSDBCommon.createTables(connection, numOfTables, stbName, tablePrefix);
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchInsert(){
|
public void testBatchInsert() {
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(numOfTables);
|
ExecutorService executorService = Executors.newFixedThreadPool(numOfTables);
|
||||||
for (int i = 0; i < numOfTables; i++) {
|
for (int i = 0; i < numOfTables; i++) {
|
||||||
final int index = i;
|
final int index = i;
|
||||||
executorService.execute(new Runnable() {
|
executorService.execute(() -> {
|
||||||
@Override
|
try {
|
||||||
public void run() {
|
long startTime = System.currentTimeMillis();
|
||||||
try {
|
Statement statement = connection.createStatement(); // get statement
|
||||||
long startTime = System.currentTimeMillis();
|
StringBuilder sb = new StringBuilder();
|
||||||
Statement statement = connection.createStatement(); // get statement
|
sb.append("INSERT INTO " + tablePrefix + index + " VALUES");
|
||||||
StringBuilder sb = new StringBuilder();
|
Random rand = new Random();
|
||||||
sb.append("INSERT INTO " + tablePrefix + index + " VALUES");
|
for (int j = 1; j <= numOfRecordsPerTable; j++) {
|
||||||
Random rand = new Random();
|
sb.append("(" + (ts + j) + ", ");
|
||||||
for (int j = 1; j <= numOfRecordsPerTable; j++) {
|
sb.append(rand.nextInt(100) + ", ");
|
||||||
sb.append("(" + (ts + j) + ", ");
|
sb.append(rand.nextInt(100) + ", ");
|
||||||
sb.append(rand.nextInt(100) + ", ");
|
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();
|
|
||||||
}
|
}
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -80,7 +92,7 @@ public class BatchInsertTest {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try {
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
ResultSet rs = statement.executeQuery("select * from meters");
|
ResultSet rs = statement.executeQuery("select * from meters");
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
@ -89,7 +101,7 @@ public class BatchInsertTest {
|
||||||
}
|
}
|
||||||
assertEquals(num, numOfTables * numOfRecordsPerTable);
|
assertEquals(num, numOfTables * numOfRecordsPerTable);
|
||||||
rs.close();
|
rs.close();
|
||||||
}catch (Exception e){
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +114,6 @@ public class BatchInsertTest {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,10 +16,6 @@ public class SqlSyntaxValidatorTest {
|
||||||
@Test
|
@Test
|
||||||
public void isUseSQL() {
|
public void isUseSQL() {
|
||||||
Assert.assertTrue(SqlSyntaxValidator.isUseSql("use database test"));
|
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"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue