[TD-2672]<test>: optimized the JDBC test cases
This commit is contained in:
parent
c375572048
commit
16069460f1
|
@ -100,7 +100,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
|||
* order to process those supported SQLs.
|
||||
*/
|
||||
private void preprocessSql() {
|
||||
|
||||
/***** For processing some of Spark SQLs*****/
|
||||
// should replace it first
|
||||
this.rawSql = this.rawSql.replaceAll("or (.*) is null", "");
|
||||
|
@ -149,7 +148,6 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
|||
rawSql = rawSql.replace(matcher.group(1), tableFullName);
|
||||
}
|
||||
/***** for inner queries *****/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,7 +194,7 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
|||
|
||||
@Override
|
||||
public void setNull(int parameterIndex, int sqlType) throws SQLException {
|
||||
setObject(parameterIndex, new String("NULL"));
|
||||
setObject(parameterIndex, "NULL");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -52,12 +52,18 @@ public class TSDBStatement implements Statement {
|
|||
this.isClosed = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
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 {
|
||||
throw new SQLException(TSDBConstants.UNSUPPORT_METHOD_EXCEPTIONZ_MSG);
|
||||
return iface.isInstance(this);
|
||||
}
|
||||
|
||||
public ResultSet executeQuery(String sql) throws SQLException {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.*;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Properties;
|
||||
|
@ -11,14 +9,13 @@ import java.util.Properties;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@FixMethodOrder()
|
||||
public class PreparedStatementTest extends BaseTest {
|
||||
static Connection connection = null;
|
||||
static PreparedStatement statement = null;
|
||||
@FixMethodOrder(value = MethodSorters.NAME_ASCENDING)
|
||||
public class PreparedStatementTest {
|
||||
static Connection connection;
|
||||
static TSDBPreparedStatement statement;
|
||||
static String dbName = "test";
|
||||
static String tName = "t0";
|
||||
static String host = "localhost";
|
||||
static ResultSet resSet = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void createConnection() throws SQLException {
|
||||
|
@ -28,19 +25,16 @@ public class PreparedStatementTest extends BaseTest {
|
|||
return;
|
||||
}
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
||||
|
||||
String sql = "drop database if exists " + dbName;
|
||||
statement = (TSDBPreparedStatement) connection.prepareStatement(sql);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTableAndQuery() throws SQLException {
|
||||
public void case001_createTableAndQuery() throws SQLException {
|
||||
long ts = System.currentTimeMillis();
|
||||
|
||||
statement.executeUpdate("create database if not exists " + dbName);
|
||||
|
@ -48,47 +42,40 @@ public class PreparedStatementTest extends BaseTest {
|
|||
statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
|
||||
|
||||
PreparedStatement selectStatement = connection.prepareStatement("select * from " + dbName + "." + tName);
|
||||
|
||||
ResultSet resultSet = selectStatement.executeQuery();
|
||||
assertTrue(null != resultSet);
|
||||
|
||||
boolean isClosed = statement.isClosed();
|
||||
assertEquals(false, isClosed);
|
||||
selectStatement.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreparedStatement() throws SQLException {
|
||||
public void case002_testPreparedStatement() throws SQLException {
|
||||
long ts = System.currentTimeMillis() + 20000;
|
||||
PreparedStatement saveStatement = connection
|
||||
.prepareStatement("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
|
||||
|
||||
PreparedStatement saveStatement = connection.prepareStatement("insert into " + dbName + "." + tName + " values (" + ts + ", 1)");
|
||||
int affectedRows = saveStatement.executeUpdate();
|
||||
assertTrue(1 == affectedRows);
|
||||
saveStatement.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSavedPreparedStatement() throws SQLException {
|
||||
public void case003_testSavedPreparedStatement() throws SQLException {
|
||||
long ts = System.currentTimeMillis();
|
||||
|
||||
TSDBPreparedStatement saveStatement = (TSDBPreparedStatement) connection
|
||||
.prepareStatement("insert into " + dbName + "." + tName + " values (?, ?)");
|
||||
|
||||
TSDBPreparedStatement saveStatement = (TSDBPreparedStatement) connection.prepareStatement("insert into " + dbName + "." + tName + " values (?, ?)");
|
||||
saveStatement.setObject(1, ts + 10000);
|
||||
saveStatement.setObject(2, 3);
|
||||
int rows = saveStatement.executeUpdate();
|
||||
assertEquals(1, rows);
|
||||
saveStatement.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupport() {
|
||||
// if(null == resSet) {
|
||||
// return;
|
||||
// }
|
||||
TSDBPreparedStatement tsdbStatement = (TSDBPreparedStatement) statement;
|
||||
try {
|
||||
tsdbStatement.unwrap(null);
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
public void case004_testUnsupport() throws SQLException {
|
||||
TSDBPreparedStatement tsdbStatement = statement;
|
||||
|
||||
Assert.assertNotNull(tsdbStatement.unwrap(TSDBPreparedStatement.class));
|
||||
try {
|
||||
tsdbStatement.isWrapperFor(null);
|
||||
} catch (SQLException e) {
|
||||
|
@ -180,6 +167,7 @@ public class PreparedStatementTest extends BaseTest {
|
|||
try {
|
||||
tsdbStatement.closeOnCompletion();
|
||||
} catch (SQLException e) {
|
||||
|
||||
}
|
||||
try {
|
||||
tsdbStatement.isCloseOnCompletion();
|
||||
|
|
|
@ -10,9 +10,9 @@ import java.sql.SQLException;
|
|||
import java.sql.Statement;
|
||||
import java.util.Properties;
|
||||
|
||||
public class SubscribeTest extends BaseTest {
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
public class SubscribeTest {
|
||||
Connection connection;
|
||||
Statement statement;
|
||||
String dbName = "test";
|
||||
String tName = "t0";
|
||||
String host = "localhost";
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
package com.taosdata.jdbc;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class TSDBPreparedStatementTest {
|
||||
private static final String host = "127.0.0.1";
|
||||
private static Connection conn;
|
||||
|
||||
@Test
|
||||
public void executeQuery() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executeUpdate() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNull() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBoolean() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setByte() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setShort() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setInt() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setLong() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setFloat() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDouble() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBigDecimal() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setString() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBytes() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDate() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTime() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTimestamp() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAsciiStream() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setUnicodeStream() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBinaryStream() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearParameters() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setObject() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void execute() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addBatch() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCharacterStream() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setRef() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setBlob() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setClob() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setArray() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetaData() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setURL() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParameterMetaData() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setRowId() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNString() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNCharacterStream() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setNClob() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSQLXML() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
conn = DriverManager.getConnection("jdbc:TAOS://" + host + ":6030/jdbc_test?user=root&password=taosdata");
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() {
|
||||
try {
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue