Skip to content

Commit e4fad59

Browse files
authored
Optimize IoTDBRestServiceIT errorInsertRecords (#17371)
* Optimize IoTDBRestServiceIT errorInsertRecords * windows fixing? * windows fixing?
1 parent d19de74 commit e4fad59

1 file changed

Lines changed: 48 additions & 85 deletions

File tree

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

Lines changed: 48 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
2222
import org.apache.iotdb.it.env.EnvFactory;
23-
import org.apache.iotdb.it.env.cluster.env.SimpleEnv;
2423
import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
2524
import org.apache.iotdb.it.framework.IoTDBTestRunner;
2625
import org.apache.iotdb.itbase.category.ClusterIT;
@@ -42,7 +41,6 @@
4241
import org.junit.After;
4342
import org.junit.Assert;
4443
import org.junit.Before;
45-
import org.junit.Ignore;
4644
import org.junit.Test;
4745
import org.junit.experimental.categories.Category;
4846
import org.junit.runner.RunWith;
@@ -52,7 +50,6 @@
5250
import java.nio.charset.StandardCharsets;
5351
import java.sql.Connection;
5452
import java.sql.ResultSet;
55-
import java.sql.ResultSetMetaData;
5653
import java.sql.SQLException;
5754
import java.sql.Statement;
5855
import java.util.ArrayList;
@@ -62,8 +59,6 @@
6259
import java.util.concurrent.TimeUnit;
6360

6461
import static org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.COLUMN_TTL;
65-
import static org.apache.iotdb.consensus.ConsensusFactory.IOT_CONSENSUS;
66-
import static org.apache.iotdb.consensus.ConsensusFactory.RATIS_CONSENSUS;
6762
import static org.junit.Assert.assertEquals;
6863
import static org.junit.Assert.assertTrue;
6964
import static org.junit.Assert.fail;
@@ -253,98 +248,66 @@ public void errorInsertRecords(CloseableHttpClient httpClient, String json, Http
253248
}
254249
}
255250

256-
@Ignore // Flaky test
257251
@Test
258-
public void errorInsertRecords() throws SQLException, InterruptedException {
259-
SimpleEnv simpleEnv = new SimpleEnv();
260-
simpleEnv
261-
.getConfig()
262-
.getCommonConfig()
263-
.setSchemaRegionConsensusProtocolClass(RATIS_CONSENSUS)
264-
.setSchemaReplicationFactor(3)
265-
.setDataRegionConsensusProtocolClass(IOT_CONSENSUS)
266-
.setDataReplicationFactor(2);
267-
simpleEnv.getConfig().getDataNodeConfig().setEnableRestService(true);
268-
simpleEnv.initClusterEnvironment(1, 3);
269-
252+
public void errorInsertRecords() throws SQLException {
270253
CloseableHttpResponse response = null;
271254
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
272-
try {
273-
HttpPost httpPost =
274-
getHttpPost(
275-
"http://"
276-
+ simpleEnv.getDataNodeWrapper(0).getIp()
277-
+ ":"
278-
+ simpleEnv.getDataNodeWrapper(0).getRestServicePort()
279-
+ "/rest/v2/insertRecords");
280-
String json =
281-
"{\"timestamps\":[1635232113960,1635232151960,1635232143960,1635232143960],\"measurements_list\":[[\"s33\",\"s44\"],[\"s55\",\"s66\"],[\"s77\",\"s88\"],[\"s771\",\"s881\"]],\"data_types_list\":[[\"INT32\",\"INT64\"],[\"FLOAT\",\"DOUBLE\"],[\"FLOAT\",\"DOUBLE\"],[\"BOOLEAN\",\"TEXT\"]],\"values_list\":[[1,false],[2.1,2],[4,6],[false,\"cccccc\"]],\"is_aligned\":false,\"devices\":[\"root.s1\",\"root.s1\",\"root.s1\",\"root.s3\"]}";
282-
httpPost.setEntity(new StringEntity(json, Charset.defaultCharset()));
283-
for (int i = 0; i < 30; i++) {
284-
try {
285-
response = httpClient.execute(httpPost);
286-
break;
287-
} catch (Exception e) {
288-
if (i == 29) {
289-
throw e;
290-
}
255+
for (int i = 0; i < EnvFactory.getEnv().getDataNodeWrapperList().size(); i++) {
256+
DataNodeWrapper wrapper = EnvFactory.getEnv().getDataNodeWrapperList().get(i);
257+
try {
258+
HttpPost httpPost =
259+
getHttpPost(
260+
"http://"
261+
+ wrapper.getIp()
262+
+ ":"
263+
+ wrapper.getRestServicePort()
264+
+ "/rest/v2/insertRecords");
265+
String json =
266+
"{\"timestamps\":["
267+
+ i
268+
+ "],\"measurements_list\":[[\"s33\",\"s44\"]],\"data_types_list\":[[\"INT32\",\"INT64\"]],\"values_list\":[[1,false]],\"is_aligned\":false,\"devices\":[\"root.s1\"]}";
269+
httpPost.setEntity(new StringEntity(json, Charset.defaultCharset()));
270+
for (int j = 0; j < 30; j++) {
291271
try {
292-
Thread.sleep(1000);
293-
} catch (InterruptedException ex) {
294-
throw new RuntimeException(ex);
272+
response = httpClient.execute(httpPost);
273+
break;
274+
} catch (Exception e) {
275+
if (i == 29) {
276+
throw e;
277+
}
278+
try {
279+
TimeUnit.SECONDS.sleep(1);
280+
} catch (InterruptedException ex) {
281+
throw new RuntimeException(ex);
282+
}
295283
}
296284
}
297-
}
298-
299-
HttpEntity responseEntity = response.getEntity();
300-
String message = EntityUtils.toString(responseEntity, "utf-8");
301-
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
302-
assertEquals(507, Integer.parseInt(result.get("code").toString()));
303-
} catch (IOException e) {
304-
e.printStackTrace();
305-
fail(e.getMessage());
306-
} finally {
307-
try {
308-
if (response != null) {
309-
response.close();
310-
}
285+
HttpEntity responseEntity = response.getEntity();
286+
String message = EntityUtils.toString(responseEntity, "utf-8");
287+
JsonObject result = JsonParser.parseString(message).getAsJsonObject();
288+
assertEquals(507, Integer.parseInt(result.get("code").toString()));
311289
} catch (IOException e) {
312290
e.printStackTrace();
313291
fail(e.getMessage());
314-
}
315-
}
316-
TimeUnit.SECONDS.sleep(5);
317-
318-
try {
319-
for (DataNodeWrapper dataNodeWrapper : simpleEnv.getDataNodeWrapperList()) {
320-
dataNodeWrapper.stop();
321-
try (Connection connectionAfterNodeDown = simpleEnv.getAvailableConnection();
322-
Statement statementAfterNodeDown = connectionAfterNodeDown.createStatement()) {
323-
int count = 0;
324-
try (ResultSet resultSet =
325-
statementAfterNodeDown.executeQuery(
326-
"select s88, s77, s66, s55, s44, s33 from root.s1")) {
327-
ResultSetMetaData metaData = resultSet.getMetaData();
328-
while (resultSet.next()) {
329-
StringBuilder row = new StringBuilder();
330-
for (int i = 0; i < metaData.getColumnCount(); i++) {
331-
row.append(resultSet.getString(i + 1)).append(",");
332-
}
333-
System.out.println(row);
334-
count++;
335-
}
292+
} finally {
293+
try {
294+
if (response != null) {
295+
response.close();
336296
}
337-
assertEquals(3, count);
297+
} catch (IOException e) {
298+
e.printStackTrace();
299+
fail(e.getMessage());
338300
}
339-
dataNodeWrapper.start();
340-
TimeUnit.SECONDS.sleep(1);
341-
}
342-
} catch (SQLException e) {
343-
if (!e.getMessage().contains("Maybe server is down")) {
344-
throw e;
345301
}
346-
} finally {
347-
simpleEnv.cleanClusterEnvironment();
302+
}
303+
try (Connection connection = EnvFactory.getEnv().getConnection();
304+
Statement statement = connection.createStatement()) {
305+
306+
ResultSet resultSet = statement.executeQuery("select count(s33) from root.s1");
307+
resultSet.next();
308+
assertEquals(
309+
EnvFactory.getEnv().getDataNodeWrapperList().size(),
310+
resultSet.getInt("count(root.s1.s33)"));
348311
}
349312
}
350313

0 commit comments

Comments
 (0)