|
20 | 20 |
|
21 | 21 | import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant; |
22 | 22 | import org.apache.iotdb.it.env.EnvFactory; |
23 | | -import org.apache.iotdb.it.env.cluster.env.SimpleEnv; |
24 | 23 | import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper; |
25 | 24 | import org.apache.iotdb.it.framework.IoTDBTestRunner; |
26 | 25 | import org.apache.iotdb.itbase.category.ClusterIT; |
|
42 | 41 | import org.junit.After; |
43 | 42 | import org.junit.Assert; |
44 | 43 | import org.junit.Before; |
45 | | -import org.junit.Ignore; |
46 | 44 | import org.junit.Test; |
47 | 45 | import org.junit.experimental.categories.Category; |
48 | 46 | import org.junit.runner.RunWith; |
|
52 | 50 | import java.nio.charset.StandardCharsets; |
53 | 51 | import java.sql.Connection; |
54 | 52 | import java.sql.ResultSet; |
55 | | -import java.sql.ResultSetMetaData; |
56 | 53 | import java.sql.SQLException; |
57 | 54 | import java.sql.Statement; |
58 | 55 | import java.util.ArrayList; |
|
62 | 59 | import java.util.concurrent.TimeUnit; |
63 | 60 |
|
64 | 61 | 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; |
67 | 62 | import static org.junit.Assert.assertEquals; |
68 | 63 | import static org.junit.Assert.assertTrue; |
69 | 64 | import static org.junit.Assert.fail; |
@@ -253,98 +248,66 @@ public void errorInsertRecords(CloseableHttpClient httpClient, String json, Http |
253 | 248 | } |
254 | 249 | } |
255 | 250 |
|
256 | | - @Ignore // Flaky test |
257 | 251 | @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 { |
270 | 253 | CloseableHttpResponse response = null; |
271 | 254 | 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++) { |
291 | 271 | 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 | + } |
295 | 283 | } |
296 | 284 | } |
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())); |
311 | 289 | } catch (IOException e) { |
312 | 290 | e.printStackTrace(); |
313 | 291 | 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(); |
336 | 296 | } |
337 | | - assertEquals(3, count); |
| 297 | + } catch (IOException e) { |
| 298 | + e.printStackTrace(); |
| 299 | + fail(e.getMessage()); |
338 | 300 | } |
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; |
345 | 301 | } |
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)")); |
348 | 311 | } |
349 | 312 | } |
350 | 313 |
|
|
0 commit comments