Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Base64;
import java.util.List;
import java.util.Map;
Expand All @@ -59,22 +62,39 @@
@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class})
public class GrafanaApiServiceIT {

private int port = 18080;
private static int port = 18080;

@Before
public void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
BaseEnv baseEnv = EnvFactory.getEnv();
baseEnv.getConfig().getDataNodeConfig().setEnableRestService(true);
baseEnv.initClusterEnvironment();
DataNodeWrapper portConflictDataNodeWrapper = EnvFactory.getEnv().getDataNodeWrapper(0);
port = portConflictDataNodeWrapper.getRestServicePort();
}

@After
public void tearDown() throws Exception {
@AfterClass
public static void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}

private static void executeQuietly(Statement statement, String sql) {
try {
statement.execute(sql);
} catch (SQLException ignored) {
// ignore
}
}

private static void cleanupSg25() {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
executeQuietly(statement, "DELETE DATABASE root.sg25");
} catch (SQLException ignored) {
// ignore
}
}

private String getAuthorization(String username, String password) {
return Base64.getEncoder()
.encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8));
Expand Down Expand Up @@ -399,53 +419,69 @@ public void variable(CloseableHttpClient httpClient) {
@Test
public void expressionWithConditionControlTest() {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
rightInsertTablet(httpClient);
expressionWithConditionControl(httpClient);
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
rightInsertTablet(httpClient);
expressionWithConditionControl(httpClient);
} finally {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
cleanupSg25();
}
}

@Test
public void expressionTest() {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
rightInsertTablet(httpClient);
expression(httpClient);
// expressionGroupByLevel(httpClient);
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
rightInsertTablet(httpClient);
expression(httpClient);
// expressionGroupByLevel(httpClient);
} finally {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
cleanupSg25();
}
}

@Test
public void expressionWithControlTest() {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
rightInsertTablet(httpClient);
expressionWithControl(httpClient);
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
rightInsertTablet(httpClient);
expressionWithControl(httpClient);
} finally {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
cleanupSg25();
}
}

@Test
public void variableTest() {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
rightInsertTablet(httpClient);
variable(httpClient);
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
rightInsertTablet(httpClient);
variable(httpClient);
} finally {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
cleanupSg25();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
import org.apache.iotdb.itbase.category.RemoteIT;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
Expand All @@ -42,17 +42,25 @@
@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class})
public class IoTDBDatetimeFormatIT {

@Before
public void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecisionCheckEnabled(false);
EnvFactory.getEnv().initClusterEnvironment();
}

@After
public void tearDown() throws Exception {
@AfterClass
public static void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}

private static void executeQuietly(Statement statement, String sql) {
try {
statement.execute(sql);
} catch (SQLException ignored) {
// ignore: cleanup may fail if target does not exist
}
}

@Test
public void testDatetimeInputFormat() {
String[] datetimeStrings = {
Expand Down Expand Up @@ -87,25 +95,28 @@ public void testDatetimeInputFormat() {
};
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
try {
connection.setClientInfo("time_zone", "+08:00");

connection.setClientInfo("time_zone", "+08:00");
for (int i = 0; i < datetimeStrings.length; i++) {
String insertSql =
String.format(
"INSERT INTO root.sg1.d1(time, s1) values (%s, %d)", datetimeStrings[i], i);
statement.execute(insertSql);
}

for (int i = 0; i < datetimeStrings.length; i++) {
String insertSql =
String.format(
"INSERT INTO root.sg1.d1(time, s1) values (%s, %d)", datetimeStrings[i], i);
statement.execute(insertSql);
}

ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.sg1.d1");
Assert.assertNotNull(resultSet);
ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.sg1.d1");
Assert.assertNotNull(resultSet);

int cnt = 0;
while (resultSet.next()) {
Assert.assertEquals(timestamps[cnt], resultSet.getLong(1));
cnt++;
int cnt = 0;
while (resultSet.next()) {
Assert.assertEquals(timestamps[cnt], resultSet.getLong(1));
cnt++;
}
Assert.assertEquals(timestamps.length, cnt);
} finally {
executeQuietly(statement, "DELETE DATABASE root.sg1");
}
Assert.assertEquals(timestamps.length, cnt);
} catch (SQLException e) {
e.printStackTrace();
fail();
Expand All @@ -116,26 +127,33 @@ public void testDatetimeInputFormat() {
public void testBigDateTime() {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
statement.setFetchSize(5);
statement.execute("CREATE DATABASE root.sg");
try {
statement.setFetchSize(5);
statement.execute("CREATE DATABASE root.sg");

statement.execute("CREATE TIMESERIES root.sg.d1.s2 WITH DATATYPE=DOUBLE, ENCODING=PLAIN;");
statement.execute("CREATE TIMESERIES root.sg.d1.s2 WITH DATATYPE=DOUBLE, ENCODING=PLAIN;");

statement.execute("insert into root.sg.d1(time,s2) values (1618283005586000, 8.76);");
statement.execute("select * from root.sg.d1;");
statement.execute("select * from root.sg.d1 where time=53251-05-07T17:06:26.000+08:00");
statement.execute("insert into root.sg.d1(time,s2) values (1618283005586000, 8.76);");
statement.execute("select * from root.sg.d1;");
statement.execute("select * from root.sg.d1 where time=53251-05-07T17:06:26.000+08:00");
} catch (SQLException e) {
e.printStackTrace();
fail();
}
try (Connection connection2 = EnvFactory.getEnv().getConnection();
Statement statement2 = connection2.createStatement()) {
statement2.execute("insert into root.sg.d1(time,s2) values (16182830055860000000, 8.76);");
fail();
} catch (SQLException e) {
Assert.assertTrue(
e.getMessage()
.contains("please check whether the timestamp 16182830055860000000 is correct."));
} finally {
executeQuietly(statement, "DELETE DATABASE root.sg");
}
} catch (SQLException e) {
e.printStackTrace();
fail();
}
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
statement.execute("insert into root.sg.d1(time,s2) values (16182830055860000000, 8.76);");
fail();
} catch (SQLException e) {
Assert.assertTrue(
e.getMessage()
.contains("please check whether the timestamp 16182830055860000000 is correct."));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.itbase.category.LocalStandaloneIT;

import org.junit.After;
import org.junit.Before;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
Expand All @@ -41,13 +41,13 @@
@Category({LocalStandaloneIT.class, ClusterIT.class})
public class IoTDBDuplicateTimeIT {

@Before
public void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
EnvFactory.getEnv().initClusterEnvironment();
}

@After
public void tearDown() throws Exception {
@AfterClass
public static void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}

Expand Down
Loading
Loading