|
51 | 51 | import java.util.concurrent.TimeUnit; |
52 | 52 |
|
53 | 53 | import static org.junit.Assert.assertEquals; |
| 54 | +import static org.junit.Assert.assertFalse; |
54 | 55 | import static org.junit.Assert.assertTrue; |
55 | 56 | import static org.junit.Assert.fail; |
56 | 57 |
|
@@ -481,4 +482,44 @@ public void testBatchJsonWithVariousValues() throws Exception { |
481 | 482 | } |
482 | 483 | } |
483 | 484 | } |
| 485 | + |
| 486 | + @Test |
| 487 | + public void testIllegalMeasurementIsRejected() throws Exception { |
| 488 | + try (final ISession session = EnvFactory.getEnv().getSessionConnection()) { |
| 489 | + String payload = |
| 490 | + "[" |
| 491 | + + "{\"device\":\"root.sg.invalid\",\"timestamp\":1,\"measurements\":[\"a.b\"],\"values\":[1]}," |
| 492 | + + "{\"device\":\"root.sg.invalid\",\"timestamp\":2,\"measurements\":[\"valid\"],\"values\":[2]}" |
| 493 | + + "]"; |
| 494 | + |
| 495 | + Awaitility.await() |
| 496 | + .atMost(3, TimeUnit.MINUTES) |
| 497 | + .pollInterval(1, TimeUnit.SECONDS) |
| 498 | + .until( |
| 499 | + () -> { |
| 500 | + connection.publish("root.sg.invalid", payload.getBytes(), QoS.AT_LEAST_ONCE, false); |
| 501 | + try (final SessionDataSet dataSet = |
| 502 | + session.executeQueryStatement( |
| 503 | + "select valid from root.sg.invalid where time = 2")) { |
| 504 | + return dataSet.hasNext(); |
| 505 | + } catch (StatementExecutionException e) { |
| 506 | + if (e.getMessage() != null && e.getMessage().contains("does not exist")) { |
| 507 | + return false; |
| 508 | + } |
| 509 | + throw e; |
| 510 | + } |
| 511 | + }); |
| 512 | + |
| 513 | + int timeseriesCount = 0; |
| 514 | + try (final SessionDataSet dataSet = |
| 515 | + session.executeQueryStatement("show timeseries root.sg.invalid.**")) { |
| 516 | + while (dataSet.hasNext()) { |
| 517 | + dataSet.next(); |
| 518 | + timeseriesCount++; |
| 519 | + } |
| 520 | + } |
| 521 | + assertEquals(1, timeseriesCount); |
| 522 | + assertFalse(session.checkTimeseriesExists("root.sg.invalid.a.b")); |
| 523 | + } |
| 524 | + } |
484 | 525 | } |
0 commit comments