This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch optimize_IoTDBRestServiceIT_errorInsertRecords in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit a58786934e60b356be33fb0114f204668dc023e7 Author: HTHou <[email protected]> AuthorDate: Fri Mar 27 12:41:27 2026 +0800 Optimize IoTDBRestServiceIT errorInsertRecords --- .../org/apache/iotdb/db/it/IoTDBRestServiceIT.java | 124 ++++++--------------- 1 file changed, 36 insertions(+), 88 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..8bc1dc74444 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,18 +50,14 @@ 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; import java.util.Base64; import java.util.List; 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 +247,52 @@ 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; - } - try { - Thread.sleep(1000); - } 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 { + for (int i = 0; i < EnvFactory.getEnv().getDataNodeWrapperList().size(); i++) { + DataNodeWrapper wrapper = EnvFactory.getEnv().getDataNodeWrapperList().get(i); try { - if (response != null) { - response.close(); - } + 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())); + response = httpClient.execute(httpPost); + 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)")); } }
