This is an automated email from the ASF dual-hosted git repository.
jiangtian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new e4fad59a809 Optimize IoTDBRestServiceIT errorInsertRecords (#17371)
e4fad59a809 is described below
commit e4fad59a80945752b95144ab575b8e8d843edfaa
Author: Haonan <[email protected]>
AuthorDate: Mon Mar 30 11:09:34 2026 +0800
Optimize IoTDBRestServiceIT errorInsertRecords (#17371)
* Optimize IoTDBRestServiceIT errorInsertRecords
* windows fixing?
* windows fixing?
---
.../org/apache/iotdb/db/it/IoTDBRestServiceIT.java | 133 ++++++++-------------
1 file changed, 48 insertions(+), 85 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java
index 97287dfaba2..76a246149cd 100644
---
a/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBRestServiceIT.java
@@ -20,7 +20,6 @@ package org.apache.iotdb.db.it;
import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
import org.apache.iotdb.it.env.EnvFactory;
-import org.apache.iotdb.it.env.cluster.env.SimpleEnv;
import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
@@ -42,7 +41,6 @@ import org.apache.http.util.EntityUtils;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
@@ -52,7 +50,6 @@ import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
@@ -62,8 +59,6 @@ import java.util.Map;
import java.util.concurrent.TimeUnit;
import static
org.apache.iotdb.commons.schema.column.ColumnHeaderConstant.COLUMN_TTL;
-import static org.apache.iotdb.consensus.ConsensusFactory.IOT_CONSENSUS;
-import static org.apache.iotdb.consensus.ConsensusFactory.RATIS_CONSENSUS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -253,98 +248,66 @@ public class IoTDBRestServiceIT {
}
}
- @Ignore // Flaky test
@Test
- public void errorInsertRecords() throws SQLException, InterruptedException {
- SimpleEnv simpleEnv = new SimpleEnv();
- simpleEnv
- .getConfig()
- .getCommonConfig()
- .setSchemaRegionConsensusProtocolClass(RATIS_CONSENSUS)
- .setSchemaReplicationFactor(3)
- .setDataRegionConsensusProtocolClass(IOT_CONSENSUS)
- .setDataReplicationFactor(2);
- simpleEnv.getConfig().getDataNodeConfig().setEnableRestService(true);
- simpleEnv.initClusterEnvironment(1, 3);
-
+ public void errorInsertRecords() throws SQLException {
CloseableHttpResponse response = null;
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
- try {
- HttpPost httpPost =
- getHttpPost(
- "http://"
- + simpleEnv.getDataNodeWrapper(0).getIp()
- + ":"
- + simpleEnv.getDataNodeWrapper(0).getRestServicePort()
- + "/rest/v2/insertRecords");
- String json =
-
"{\"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\"]}";
- httpPost.setEntity(new StringEntity(json, Charset.defaultCharset()));
- for (int i = 0; i < 30; i++) {
- try {
- response = httpClient.execute(httpPost);
- break;
- } catch (Exception e) {
- if (i == 29) {
- throw e;
- }
+ for (int i = 0; i < EnvFactory.getEnv().getDataNodeWrapperList().size();
i++) {
+ DataNodeWrapper wrapper =
EnvFactory.getEnv().getDataNodeWrapperList().get(i);
+ try {
+ HttpPost httpPost =
+ getHttpPost(
+ "http://"
+ + wrapper.getIp()
+ + ":"
+ + wrapper.getRestServicePort()
+ + "/rest/v2/insertRecords");
+ String json =
+ "{\"timestamps\":["
+ + i
+ +
"],\"measurements_list\":[[\"s33\",\"s44\"]],\"data_types_list\":[[\"INT32\",\"INT64\"]],\"values_list\":[[1,false]],\"is_aligned\":false,\"devices\":[\"root.s1\"]}";
+ httpPost.setEntity(new StringEntity(json, Charset.defaultCharset()));
+ for (int j = 0; j < 30; j++) {
try {
- Thread.sleep(1000);
- } catch (InterruptedException ex) {
- throw new RuntimeException(ex);
+ response = httpClient.execute(httpPost);
+ break;
+ } catch (Exception e) {
+ if (i == 29) {
+ throw e;
+ }
+ try {
+ TimeUnit.SECONDS.sleep(1);
+ } catch (InterruptedException ex) {
+ throw new RuntimeException(ex);
+ }
}
}
- }
-
- HttpEntity responseEntity = response.getEntity();
- String message = EntityUtils.toString(responseEntity, "utf-8");
- JsonObject result = JsonParser.parseString(message).getAsJsonObject();
- assertEquals(507, Integer.parseInt(result.get("code").toString()));
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- } finally {
- try {
- if (response != null) {
- response.close();
- }
+ HttpEntity responseEntity = response.getEntity();
+ String message = EntityUtils.toString(responseEntity, "utf-8");
+ JsonObject result = JsonParser.parseString(message).getAsJsonObject();
+ assertEquals(507, Integer.parseInt(result.get("code").toString()));
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
- }
- }
- TimeUnit.SECONDS.sleep(5);
-
- try {
- for (DataNodeWrapper dataNodeWrapper :
simpleEnv.getDataNodeWrapperList()) {
- dataNodeWrapper.stop();
- try (Connection connectionAfterNodeDown =
simpleEnv.getAvailableConnection();
- Statement statementAfterNodeDown =
connectionAfterNodeDown.createStatement()) {
- int count = 0;
- try (ResultSet resultSet =
- statementAfterNodeDown.executeQuery(
- "select s88, s77, s66, s55, s44, s33 from root.s1")) {
- ResultSetMetaData metaData = resultSet.getMetaData();
- while (resultSet.next()) {
- StringBuilder row = new StringBuilder();
- for (int i = 0; i < metaData.getColumnCount(); i++) {
- row.append(resultSet.getString(i + 1)).append(",");
- }
- System.out.println(row);
- count++;
- }
+ } finally {
+ try {
+ if (response != null) {
+ response.close();
}
- assertEquals(3, count);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
}
- dataNodeWrapper.start();
- TimeUnit.SECONDS.sleep(1);
- }
- } catch (SQLException e) {
- if (!e.getMessage().contains("Maybe server is down")) {
- throw e;
}
- } finally {
- simpleEnv.cleanClusterEnvironment();
+ }
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+
+ ResultSet resultSet = statement.executeQuery("select count(s33) from
root.s1");
+ resultSet.next();
+ assertEquals(
+ EnvFactory.getEnv().getDataNodeWrapperList().size(),
+ resultSet.getInt("count(root.s1.s33)"));
}
}