change
This commit is contained in:
parent
c8b6ff8689
commit
d96f57a89f
|
@ -12,69 +12,66 @@ import java.util.Properties;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class StableTest extends BaseTest {
|
public class StableTest {
|
||||||
static Connection connection = null;
|
|
||||||
static Statement statement = null;
|
static Connection connection;
|
||||||
static String dbName = "test";
|
static String dbName = "test";
|
||||||
static String stbName = "st";
|
static String stbName = "st";
|
||||||
static String host = "localhost";
|
static String host = "127.0.0.1";
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void createDatabase() throws SQLException {
|
public static void createDatabase() {
|
||||||
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/", properties);
|
||||||
|
Statement statement = connection.createStatement();
|
||||||
|
statement.execute("create database if not exists " + dbName);
|
||||||
|
statement.execute("use " + dbName);
|
||||||
|
statement.close();
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
return;
|
return;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
Properties properties = new Properties();
|
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
|
||||||
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
|
|
||||||
|
|
||||||
statement = connection.createStatement();
|
|
||||||
statement.executeUpdate("create database if not exists " + dbName);
|
|
||||||
statement.executeQuery("use " + dbName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
public void createStable() {
|
public void case001_createSuperTable() {
|
||||||
String sql = "create table " + stbName + " (ts timestamp, v1 int, v2 int) tags (tg nchar(20)) ";
|
try (Statement stmt = connection.createStatement()) {
|
||||||
|
final String sql = "create table " + stbName + " (ts timestamp, v1 int, v2 int) tags (tg nchar(20)) ";
|
||||||
try {
|
stmt.execute(sql);
|
||||||
statement.executeUpdate(sql);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
assert false : "error create stable" + e.getMessage();
|
assert false : "error create stable" + e.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
public void createTable() {
|
public void case002_createTable() {
|
||||||
String sql = "create table t1 using " + stbName + " tags (\"beijing\")";
|
try (Statement stmt = connection.createStatement()) {
|
||||||
|
final String sql = "create table t1 using " + stbName + " tags (\"beijing\")";
|
||||||
try {
|
stmt.execute(sql);
|
||||||
statement.executeUpdate(sql);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
assert false : "error create table" + e.getMessage();
|
assert false : "error create table" + e.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void describeSTable() {
|
public void case003_describeSTable() {
|
||||||
createStable();
|
|
||||||
String sql = "describe " + stbName;
|
|
||||||
int num = 0;
|
int num = 0;
|
||||||
System.out.println("describe stable");
|
try (Statement stmt = connection.createStatement()) {
|
||||||
try {
|
String sql = "describe " + stbName;
|
||||||
ResultSet res = statement.executeQuery(sql);
|
ResultSet rs = stmt.executeQuery(sql);
|
||||||
while (res.next()) {
|
while (rs.next()) {
|
||||||
for (int i = 1; i <= res.getMetaData().getColumnCount(); i++) {
|
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
|
||||||
System.out.printf("%d: %s\n", i, res.getString(i));
|
System.out.println(i + ":" + rs.getString(i));
|
||||||
}
|
}
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
res.close();
|
rs.close();
|
||||||
assertEquals(4, num);
|
assertEquals(4, num);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
assert false : "error describe stable" + e.getMessage();
|
assert false : "error describe stable" + e.getMessage();
|
||||||
|
@ -82,41 +79,31 @@ public class StableTest extends BaseTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void describeTable() {
|
public void case004_describeTable() {
|
||||||
createTable();
|
|
||||||
String sql = "describe t1";
|
|
||||||
int num = 0;
|
int num = 0;
|
||||||
System.out.println("describe table");
|
try (Statement stmt = connection.createStatement()) {
|
||||||
try {
|
ResultSet rs = stmt.executeQuery("describe t1");
|
||||||
ResultSet res = statement.executeQuery(sql);
|
while (rs.next()) {
|
||||||
while (res.next()) {
|
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
|
||||||
for (int i = 1; i <= res.getMetaData().getColumnCount(); i++) {
|
System.out.printf("%d: %s\n", i, rs.getString(i));
|
||||||
System.out.printf("%d: %s\n", i, res.getString(i));
|
|
||||||
}
|
}
|
||||||
num++;
|
num++;
|
||||||
}
|
}
|
||||||
res.close();
|
rs.close();
|
||||||
assertEquals(4, num);
|
assertEquals(4, num);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
assert false : "error describe stable" + e.getMessage();
|
assert false : "error describe stable" + e.getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
|
||||||
public void validCreateSql() {
|
|
||||||
String sql = "create table t2 using " + stbName + " tags (\"beijing\")";
|
|
||||||
boolean valid = ((TSDBConnection) connection).getConnection().validateCreateTableSql(sql);
|
|
||||||
assertEquals(true, valid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void close() throws Exception {
|
public static void close() {
|
||||||
if (!statement.isClosed()) {
|
try {
|
||||||
statement.executeUpdate("drop database " + dbName);
|
if (connection != null)
|
||||||
statement.close();
|
connection.close();
|
||||||
connection.close();
|
} catch (SQLException e) {
|
||||||
Thread.sleep(10);
|
e.printStackTrace();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue