Skip to content

Commit 9293710

Browse files
committed
Merge remote-tracking branch 'origin/master' into fix-like-dynamic-pattern
# Conflicts: # integration-test/src/test/java/org/apache/iotdb/pipe/it/dual/treemodel/auto/basic/IoTDBPipeReceiverAutoCreateDisabledIT.java
2 parents dd861a5 + e81a432 commit 9293710

46 files changed

Lines changed: 4851 additions & 3938 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

integration-test/src/test/java/org/apache/iotdb/db/it/GrafanaApiServiceIT.java

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@
3737
import org.apache.http.impl.client.CloseableHttpClient;
3838
import org.apache.http.impl.client.HttpClientBuilder;
3939
import org.apache.http.util.EntityUtils;
40-
import org.junit.After;
40+
import org.junit.AfterClass;
4141
import org.junit.Assert;
42-
import org.junit.Before;
42+
import org.junit.BeforeClass;
4343
import org.junit.Test;
4444
import org.junit.experimental.categories.Category;
4545
import org.junit.runner.RunWith;
4646

4747
import java.io.IOException;
4848
import java.nio.charset.Charset;
4949
import java.nio.charset.StandardCharsets;
50+
import java.sql.Connection;
51+
import java.sql.SQLException;
52+
import java.sql.Statement;
5053
import java.util.Base64;
5154
import java.util.List;
5255
import java.util.Map;
@@ -59,22 +62,39 @@
5962
@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class})
6063
public class GrafanaApiServiceIT {
6164

62-
private int port = 18080;
65+
private static int port = 18080;
6366

64-
@Before
65-
public void setUp() throws Exception {
67+
@BeforeClass
68+
public static void setUp() throws Exception {
6669
BaseEnv baseEnv = EnvFactory.getEnv();
6770
baseEnv.getConfig().getDataNodeConfig().setEnableRestService(true);
6871
baseEnv.initClusterEnvironment();
6972
DataNodeWrapper portConflictDataNodeWrapper = EnvFactory.getEnv().getDataNodeWrapper(0);
7073
port = portConflictDataNodeWrapper.getRestServicePort();
7174
}
7275

73-
@After
74-
public void tearDown() throws Exception {
76+
@AfterClass
77+
public static void tearDown() throws Exception {
7578
EnvFactory.getEnv().cleanClusterEnvironment();
7679
}
7780

81+
private static void executeQuietly(Statement statement, String sql) {
82+
try {
83+
statement.execute(sql);
84+
} catch (SQLException ignored) {
85+
// ignore
86+
}
87+
}
88+
89+
private static void cleanupSg25() {
90+
try (Connection connection = EnvFactory.getEnv().getConnection();
91+
Statement statement = connection.createStatement()) {
92+
executeQuietly(statement, "DELETE DATABASE root.sg25");
93+
} catch (SQLException ignored) {
94+
// ignore
95+
}
96+
}
97+
7898
private String getAuthorization(String username, String password) {
7999
return Base64.getEncoder()
80100
.encodeToString((username + ":" + password).getBytes(StandardCharsets.UTF_8));
@@ -399,53 +419,69 @@ public void variable(CloseableHttpClient httpClient) {
399419
@Test
400420
public void expressionWithConditionControlTest() {
401421
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
402-
rightInsertTablet(httpClient);
403-
expressionWithConditionControl(httpClient);
404422
try {
405-
httpClient.close();
406-
} catch (IOException e) {
407-
e.printStackTrace();
408-
fail(e.getMessage());
423+
rightInsertTablet(httpClient);
424+
expressionWithConditionControl(httpClient);
425+
} finally {
426+
try {
427+
httpClient.close();
428+
} catch (IOException e) {
429+
e.printStackTrace();
430+
fail(e.getMessage());
431+
}
432+
cleanupSg25();
409433
}
410434
}
411435

412436
@Test
413437
public void expressionTest() {
414438
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
415-
rightInsertTablet(httpClient);
416-
expression(httpClient);
417-
// expressionGroupByLevel(httpClient);
418439
try {
419-
httpClient.close();
420-
} catch (IOException e) {
421-
e.printStackTrace();
422-
fail(e.getMessage());
440+
rightInsertTablet(httpClient);
441+
expression(httpClient);
442+
// expressionGroupByLevel(httpClient);
443+
} finally {
444+
try {
445+
httpClient.close();
446+
} catch (IOException e) {
447+
e.printStackTrace();
448+
fail(e.getMessage());
449+
}
450+
cleanupSg25();
423451
}
424452
}
425453

426454
@Test
427455
public void expressionWithControlTest() {
428456
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
429-
rightInsertTablet(httpClient);
430-
expressionWithControl(httpClient);
431457
try {
432-
httpClient.close();
433-
} catch (IOException e) {
434-
e.printStackTrace();
435-
fail(e.getMessage());
458+
rightInsertTablet(httpClient);
459+
expressionWithControl(httpClient);
460+
} finally {
461+
try {
462+
httpClient.close();
463+
} catch (IOException e) {
464+
e.printStackTrace();
465+
fail(e.getMessage());
466+
}
467+
cleanupSg25();
436468
}
437469
}
438470

439471
@Test
440472
public void variableTest() {
441473
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
442-
rightInsertTablet(httpClient);
443-
variable(httpClient);
444474
try {
445-
httpClient.close();
446-
} catch (IOException e) {
447-
e.printStackTrace();
448-
fail(e.getMessage());
475+
rightInsertTablet(httpClient);
476+
variable(httpClient);
477+
} finally {
478+
try {
479+
httpClient.close();
480+
} catch (IOException e) {
481+
e.printStackTrace();
482+
fail(e.getMessage());
483+
}
484+
cleanupSg25();
449485
}
450486
}
451487
}

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBDatetimeFormatIT.java

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
2525
import org.apache.iotdb.itbase.category.RemoteIT;
2626

27-
import org.junit.After;
27+
import org.junit.AfterClass;
2828
import org.junit.Assert;
29-
import org.junit.Before;
29+
import org.junit.BeforeClass;
3030
import org.junit.Test;
3131
import org.junit.experimental.categories.Category;
3232
import org.junit.runner.RunWith;
@@ -42,17 +42,25 @@
4242
@Category({LocalStandaloneIT.class, ClusterIT.class, RemoteIT.class})
4343
public class IoTDBDatetimeFormatIT {
4444

45-
@Before
46-
public void setUp() throws Exception {
45+
@BeforeClass
46+
public static void setUp() throws Exception {
4747
EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecisionCheckEnabled(false);
4848
EnvFactory.getEnv().initClusterEnvironment();
4949
}
5050

51-
@After
52-
public void tearDown() throws Exception {
51+
@AfterClass
52+
public static void tearDown() throws Exception {
5353
EnvFactory.getEnv().cleanClusterEnvironment();
5454
}
5555

56+
private static void executeQuietly(Statement statement, String sql) {
57+
try {
58+
statement.execute(sql);
59+
} catch (SQLException ignored) {
60+
// ignore: cleanup may fail if target does not exist
61+
}
62+
}
63+
5664
@Test
5765
public void testDatetimeInputFormat() {
5866
String[] datetimeStrings = {
@@ -87,25 +95,28 @@ public void testDatetimeInputFormat() {
8795
};
8896
try (Connection connection = EnvFactory.getEnv().getConnection();
8997
Statement statement = connection.createStatement()) {
98+
try {
99+
connection.setClientInfo("time_zone", "+08:00");
90100

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

93-
for (int i = 0; i < datetimeStrings.length; i++) {
94-
String insertSql =
95-
String.format(
96-
"INSERT INTO root.sg1.d1(time, s1) values (%s, %d)", datetimeStrings[i], i);
97-
statement.execute(insertSql);
98-
}
99-
100-
ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.sg1.d1");
101-
Assert.assertNotNull(resultSet);
108+
ResultSet resultSet = statement.executeQuery("SELECT s1 FROM root.sg1.d1");
109+
Assert.assertNotNull(resultSet);
102110

103-
int cnt = 0;
104-
while (resultSet.next()) {
105-
Assert.assertEquals(timestamps[cnt], resultSet.getLong(1));
106-
cnt++;
111+
int cnt = 0;
112+
while (resultSet.next()) {
113+
Assert.assertEquals(timestamps[cnt], resultSet.getLong(1));
114+
cnt++;
115+
}
116+
Assert.assertEquals(timestamps.length, cnt);
117+
} finally {
118+
executeQuietly(statement, "DELETE DATABASE root.sg1");
107119
}
108-
Assert.assertEquals(timestamps.length, cnt);
109120
} catch (SQLException e) {
110121
e.printStackTrace();
111122
fail();
@@ -116,26 +127,33 @@ public void testDatetimeInputFormat() {
116127
public void testBigDateTime() {
117128
try (Connection connection = EnvFactory.getEnv().getConnection();
118129
Statement statement = connection.createStatement()) {
119-
statement.setFetchSize(5);
120-
statement.execute("CREATE DATABASE root.sg");
130+
try {
131+
statement.setFetchSize(5);
132+
statement.execute("CREATE DATABASE root.sg");
121133

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

124-
statement.execute("insert into root.sg.d1(time,s2) values (1618283005586000, 8.76);");
125-
statement.execute("select * from root.sg.d1;");
126-
statement.execute("select * from root.sg.d1 where time=53251-05-07T17:06:26.000+08:00");
136+
statement.execute("insert into root.sg.d1(time,s2) values (1618283005586000, 8.76);");
137+
statement.execute("select * from root.sg.d1;");
138+
statement.execute("select * from root.sg.d1 where time=53251-05-07T17:06:26.000+08:00");
139+
} catch (SQLException e) {
140+
e.printStackTrace();
141+
fail();
142+
}
143+
try (Connection connection2 = EnvFactory.getEnv().getConnection();
144+
Statement statement2 = connection2.createStatement()) {
145+
statement2.execute("insert into root.sg.d1(time,s2) values (16182830055860000000, 8.76);");
146+
fail();
147+
} catch (SQLException e) {
148+
Assert.assertTrue(
149+
e.getMessage()
150+
.contains("please check whether the timestamp 16182830055860000000 is correct."));
151+
} finally {
152+
executeQuietly(statement, "DELETE DATABASE root.sg");
153+
}
127154
} catch (SQLException e) {
128155
e.printStackTrace();
129156
fail();
130157
}
131-
try (Connection connection = EnvFactory.getEnv().getConnection();
132-
Statement statement = connection.createStatement()) {
133-
statement.execute("insert into root.sg.d1(time,s2) values (16182830055860000000, 8.76);");
134-
fail();
135-
} catch (SQLException e) {
136-
Assert.assertTrue(
137-
e.getMessage()
138-
.contains("please check whether the timestamp 16182830055860000000 is correct."));
139-
}
140158
}
141159
}

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBDuplicateTimeIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import org.apache.iotdb.itbase.category.ClusterIT;
2525
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
2626

27-
import org.junit.After;
28-
import org.junit.Before;
27+
import org.junit.AfterClass;
28+
import org.junit.BeforeClass;
2929
import org.junit.Test;
3030
import org.junit.experimental.categories.Category;
3131
import org.junit.runner.RunWith;
@@ -41,13 +41,13 @@
4141
@Category({LocalStandaloneIT.class, ClusterIT.class})
4242
public class IoTDBDuplicateTimeIT {
4343

44-
@Before
45-
public void setUp() throws Exception {
44+
@BeforeClass
45+
public static void setUp() throws Exception {
4646
EnvFactory.getEnv().initClusterEnvironment();
4747
}
4848

49-
@After
50-
public void tearDown() throws Exception {
49+
@AfterClass
50+
public static void tearDown() throws Exception {
5151
EnvFactory.getEnv().cleanClusterEnvironment();
5252
}
5353

0 commit comments

Comments
 (0)