tests:add import
This commit is contained in:
parent
db6f4514bc
commit
2bb969a9fb
|
@ -51,13 +51,17 @@ public class TSDBStatement implements Statement {
|
||||||
if (isClosed) {
|
if (isClosed) {
|
||||||
throw new SQLException("Invalid method call on a closed statement.");
|
throw new SQLException("Invalid method call on a closed statement.");
|
||||||
}
|
}
|
||||||
this.connecter.executeQuery(sql);
|
System.out.println(sql);
|
||||||
|
long res = this.connecter.executeQuery(sql);
|
||||||
|
|
||||||
long resultSetPointer = this.connecter.getResultSet();
|
long resultSetPointer = this.connecter.getResultSet();
|
||||||
|
|
||||||
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
|
if (resultSetPointer == TSDBConstants.JNI_CONNECTION_NULL) {
|
||||||
|
this.connecter.freeResultSet(res);
|
||||||
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
throw new SQLException(TSDBConstants.FixErrMsg(TSDBConstants.JNI_CONNECTION_NULL));
|
||||||
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
|
} else if (resultSetPointer == TSDBConstants.JNI_NULL_POINTER) {
|
||||||
|
// create/insert/update/del/alter
|
||||||
|
this.connecter.freeResultSet(res);
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return new TSDBResultSet(this.connecter, resultSetPointer);
|
return new TSDBResultSet(this.connecter, resultSetPointer);
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class TSDBAsyncSubscribeTest {
|
||||||
String topic = "test";
|
String topic = "test";
|
||||||
long subscribId = 0;
|
long subscribId = 0;
|
||||||
|
|
||||||
// @Before
|
@Before
|
||||||
public void createDatabase() throws SQLException {
|
public void createDatabase() throws SQLException {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
|
@ -43,7 +43,7 @@ public class TSDBAsyncSubscribeTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
public void subscribe() throws Exception {
|
public void subscribe() throws Exception {
|
||||||
TSDBSubscribe subscribe = null;
|
TSDBSubscribe subscribe = null;
|
||||||
try {
|
try {
|
||||||
|
@ -70,7 +70,6 @@ public class TSDBAsyncSubscribeTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(TSDBResultSet resultSet) {
|
public void invoke(TSDBResultSet resultSet) {
|
||||||
System.out.println("resultSet");
|
|
||||||
try {
|
try {
|
||||||
while (null != resultSet && resultSet.next()) {
|
while (null != resultSet && resultSet.next()) {
|
||||||
System.out.print("callback_" + name + ": ");
|
System.out.print("callback_" + name + ": ");
|
||||||
|
@ -87,7 +86,7 @@ public class TSDBAsyncSubscribeTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @After
|
@After
|
||||||
public void close() throws Exception {
|
public void close() throws Exception {
|
||||||
statement.executeQuery("drop database test");
|
statement.executeQuery("drop database test");
|
||||||
statement.close();
|
statement.close();
|
||||||
|
|
|
@ -4,10 +4,7 @@ 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.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -40,20 +37,33 @@ public class TSDBImportTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void insertInto() throws Exception {
|
public void insertInto() throws Exception {
|
||||||
long ts = System.currentTimeMillis();
|
long ts = 1496732686000l;
|
||||||
|
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
ts += i;
|
ts ++;
|
||||||
int row = statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")");
|
int row = statement.executeUpdate("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")");
|
||||||
System.out.println("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")" + "\t" + row);
|
System.out.println("insert into " + dbName + "." + tName + " values (" + ts + ", " + (100 + i) + ", " + i + ")\t" + row);
|
||||||
assertEquals(1, row);
|
assertEquals(1, row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void selectData() throws Exception {
|
||||||
|
String sql = "select * from test.t0";
|
||||||
|
ResultSet resSet = statement.executeQuery(sql);
|
||||||
|
|
||||||
|
while (resSet.next()) {
|
||||||
|
for (int i = 1; i <= resSet.getMetaData().getColumnCount(); i++) {
|
||||||
|
System.out.printf(i + ": " + resSet.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resSet.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void importInto() throws Exception {
|
public void importInto() throws Exception {
|
||||||
// 避免时间重复
|
// 避免时间重复
|
||||||
long ts = System.currentTimeMillis() + 1000;
|
long ts = 1496732686000l;
|
||||||
|
|
||||||
StringBuilder sqlBuilder = new StringBuilder("insert into ").append(dbName).append(".").append(tName).append(" values ");
|
StringBuilder sqlBuilder = new StringBuilder("insert into ").append(dbName).append(".").append(tName).append(" values ");
|
||||||
|
|
||||||
|
@ -68,9 +78,9 @@ public class TSDBImportTest {
|
||||||
assertEquals(10, rows);
|
assertEquals(10, rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
// @After
|
||||||
public void close() throws Exception {
|
public void close() throws Exception {
|
||||||
statement.executeQuery("drop database " + dbName);
|
statement.executeUpdate("drop database " + dbName);
|
||||||
statement.close();
|
statement.close();
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class TSDBSubscribeTest {
|
||||||
String host = "localhost";
|
String host = "localhost";
|
||||||
String topic = "test";
|
String topic = "test";
|
||||||
|
|
||||||
// @Before
|
@Before
|
||||||
public void createDatabase() throws SQLException {
|
public void createDatabase() throws SQLException {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
|
@ -42,7 +42,7 @@ public class TSDBSubscribeTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
public void subscribe() throws Exception {
|
public void subscribe() throws Exception {
|
||||||
TSDBSubscribe subscribe = null;
|
TSDBSubscribe subscribe = null;
|
||||||
long subscribId = 0;
|
long subscribId = 0;
|
||||||
|
@ -81,7 +81,7 @@ public class TSDBSubscribeTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @After
|
@After
|
||||||
public void close() throws Exception {
|
public void close() throws Exception {
|
||||||
statement.executeQuery("drop database " + dbName);
|
statement.executeQuery("drop database " + dbName);
|
||||||
statement.close();
|
statement.close();
|
||||||
|
|
Loading…
Reference in New Issue