Commit 58d9c313a89d3929ad7c3d0e46ed287b91132355

Authored by Andrii Shvaika
1 parent 341f0d14

Fixed tests

... ... @@ -47,6 +47,7 @@ import java.util.stream.Collectors;
47 47 @Slf4j
48 48 public class DefaultRuleEngineStatisticsService implements RuleEngineStatisticsService {
49 49
  50 + public static final String TB_SERVICE_QUEUE = "TbServiceQueue";
50 51 public static final FutureCallback<Void> CALLBACK = new FutureCallback<Void>() {
51 52 @Override
52 53 public void onSuccess(@Nullable Void result) {
... ... @@ -95,7 +96,13 @@ public class DefaultRuleEngineStatisticsService implements RuleEngineStatisticsS
95 96 });
96 97 ruleEngineStats.getTenantExceptions().forEach((tenantId, e) -> {
97 98 TsKvEntry tsKv = new BasicTsKvEntry(ts, new JsonDataEntry("ruleEngineException", e.toJsonString()));
98   - tsService.saveAndNotify(tenantId, getServiceAssetId(tenantId, queueName), Collections.singletonList(tsKv), CALLBACK);
  99 + try {
  100 + tsService.saveAndNotify(tenantId, getServiceAssetId(tenantId, queueName), Collections.singletonList(tsKv), CALLBACK);
  101 + } catch (DataValidationException e2) {
  102 + if (!e2.getMessage().equalsIgnoreCase("Asset is referencing to non-existent tenant!")) {
  103 + throw e2;
  104 + }
  105 + }
99 106 });
100 107 ruleEngineStats.reset();
101 108 }
... ... @@ -113,7 +120,7 @@ public class DefaultRuleEngineStatisticsService implements RuleEngineStatisticsS
113 120 asset = new Asset();
114 121 asset.setTenantId(tenantId);
115 122 asset.setName(queueName + "_" + serviceInfoProvider.getServiceId());
116   - asset.setType("TbServiceQueue");
  123 + asset.setType(TB_SERVICE_QUEUE);
117 124 asset = assetService.saveAsset(asset);
118 125 }
119 126 assetId = asset.getId();
... ...
... ... @@ -32,6 +32,7 @@ import org.thingsboard.server.common.data.page.TextPageData;
32 32 import org.thingsboard.server.common.data.page.TextPageLink;
33 33 import org.thingsboard.server.common.data.security.Authority;
34 34 import org.thingsboard.server.dao.model.ModelConstants;
  35 +import org.thingsboard.server.service.stats.DefaultRuleEngineStatisticsService;
35 36
36 37 import java.util.ArrayList;
37 38 import java.util.Collections;
... ... @@ -71,7 +72,7 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
71 72 public void afterTest() throws Exception {
72 73 loginSysAdmin();
73 74
74   - doDelete("/api/tenant/"+savedTenant.getId().getId().toString())
  75 + doDelete("/api/tenant/" + savedTenant.getId().getId().toString())
75 76 .andExpect(status().isOk());
76 77 }
77 78
... ... @@ -111,26 +112,27 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
111 112 @Test
112 113 public void testFindAssetTypesByTenantId() throws Exception {
113 114 List<Asset> assets = new ArrayList<>();
114   - for (int i=0;i<3;i++) {
  115 + for (int i = 0; i < 3; i++) {
115 116 Asset asset = new Asset();
116   - asset.setName("My asset B"+i);
  117 + asset.setName("My asset B" + i);
117 118 asset.setType("typeB");
118 119 assets.add(doPost("/api/asset", asset, Asset.class));
119 120 }
120   - for (int i=0;i<7;i++) {
  121 + for (int i = 0; i < 7; i++) {
121 122 Asset asset = new Asset();
122   - asset.setName("My asset C"+i);
  123 + asset.setName("My asset C" + i);
123 124 asset.setType("typeC");
124 125 assets.add(doPost("/api/asset", asset, Asset.class));
125 126 }
126   - for (int i=0;i<9;i++) {
  127 + for (int i = 0; i < 9; i++) {
127 128 Asset asset = new Asset();
128   - asset.setName("My asset A"+i);
  129 + asset.setName("My asset A" + i);
129 130 asset.setType("typeA");
130 131 assets.add(doPost("/api/asset", asset, Asset.class));
131 132 }
132 133 List<EntitySubtype> assetTypes = doGetTyped("/api/asset/types",
133   - new TypeReference<List<EntitySubtype>>(){});
  134 + new TypeReference<List<EntitySubtype>>() {
  135 + });
134 136
135 137 Assert.assertNotNull(assetTypes);
136 138 Assert.assertEquals(3, assetTypes.size());
... ... @@ -146,10 +148,10 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
146 148 asset.setType("default");
147 149 Asset savedAsset = doPost("/api/asset", asset, Asset.class);
148 150
149   - doDelete("/api/asset/"+savedAsset.getId().getId().toString())
  151 + doDelete("/api/asset/" + savedAsset.getId().getId().toString())
150 152 .andExpect(status().isOk());
151 153
152   - doGet("/api/asset/"+savedAsset.getId().getId().toString())
  154 + doGet("/api/asset/" + savedAsset.getId().getId().toString())
153 155 .andExpect(status().isNotFound());
154 156 }
155 157
... ... @@ -244,16 +246,16 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
244 246
245 247 loginSysAdmin();
246 248
247   - doDelete("/api/tenant/"+savedTenant2.getId().getId().toString())
  249 + doDelete("/api/tenant/" + savedTenant2.getId().getId().toString())
248 250 .andExpect(status().isOk());
249 251 }
250 252
251 253 @Test
252 254 public void testFindTenantAssets() throws Exception {
253 255 List<Asset> assets = new ArrayList<>();
254   - for (int i=0;i<178;i++) {
  256 + for (int i = 0; i < 178; i++) {
255 257 Asset asset = new Asset();
256   - asset.setName("Asset"+i);
  258 + asset.setName("Asset" + i);
257 259 asset.setType("default");
258 260 assets.add(doPost("/api/asset", asset, Asset.class));
259 261 }
... ... @@ -262,13 +264,16 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
262 264 TextPageData<Asset> pageData = null;
263 265 do {
264 266 pageData = doGetTypedWithPageLink("/api/tenant/assets?",
265   - new TypeReference<TextPageData<Asset>>(){}, pageLink);
  267 + new TypeReference<TextPageData<Asset>>() {
  268 + }, pageLink);
266 269 loadedAssets.addAll(pageData.getData());
267 270 if (pageData.hasNext()) {
268 271 pageLink = pageData.getNextPageLink();
269 272 }
270 273 } while (pageData.hasNext());
271 274
  275 + loadedAssets.removeIf(asset -> asset.getType().equals(DefaultRuleEngineStatisticsService.TB_SERVICE_QUEUE));
  276 +
272 277 Collections.sort(assets, idComparator);
273 278 Collections.sort(loadedAssets, idComparator);
274 279
... ... @@ -279,10 +284,10 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
279 284 public void testFindTenantAssetsByName() throws Exception {
280 285 String title1 = "Asset title 1";
281 286 List<Asset> assetsTitle1 = new ArrayList<>();
282   - for (int i=0;i<143;i++) {
  287 + for (int i = 0; i < 143; i++) {
283 288 Asset asset = new Asset();
284 289 String suffix = RandomStringUtils.randomAlphanumeric(15);
285   - String name = title1+suffix;
  290 + String name = title1 + suffix;
286 291 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
287 292 asset.setName(name);
288 293 asset.setType("default");
... ... @@ -290,10 +295,10 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
290 295 }
291 296 String title2 = "Asset title 2";
292 297 List<Asset> assetsTitle2 = new ArrayList<>();
293   - for (int i=0;i<75;i++) {
  298 + for (int i = 0; i < 75; i++) {
294 299 Asset asset = new Asset();
295 300 String suffix = RandomStringUtils.randomAlphanumeric(15);
296   - String name = title2+suffix;
  301 + String name = title2 + suffix;
297 302 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
298 303 asset.setName(name);
299 304 asset.setType("default");
... ... @@ -305,7 +310,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
305 310 TextPageData<Asset> pageData = null;
306 311 do {
307 312 pageData = doGetTypedWithPageLink("/api/tenant/assets?",
308   - new TypeReference<TextPageData<Asset>>(){}, pageLink);
  313 + new TypeReference<TextPageData<Asset>>() {
  314 + }, pageLink);
309 315 loadedAssetsTitle1.addAll(pageData.getData());
310 316 if (pageData.hasNext()) {
311 317 pageLink = pageData.getNextPageLink();
... ... @@ -321,7 +327,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
321 327 pageLink = new TextPageLink(4, title2);
322 328 do {
323 329 pageData = doGetTypedWithPageLink("/api/tenant/assets?",
324   - new TypeReference<TextPageData<Asset>>(){}, pageLink);
  330 + new TypeReference<TextPageData<Asset>>() {
  331 + }, pageLink);
325 332 loadedAssetsTitle2.addAll(pageData.getData());
326 333 if (pageData.hasNext()) {
327 334 pageLink = pageData.getNextPageLink();
... ... @@ -334,24 +341,26 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
334 341 Assert.assertEquals(assetsTitle2, loadedAssetsTitle2);
335 342
336 343 for (Asset asset : loadedAssetsTitle1) {
337   - doDelete("/api/asset/"+asset.getId().getId().toString())
  344 + doDelete("/api/asset/" + asset.getId().getId().toString())
338 345 .andExpect(status().isOk());
339 346 }
340 347
341 348 pageLink = new TextPageLink(4, title1);
342 349 pageData = doGetTypedWithPageLink("/api/tenant/assets?",
343   - new TypeReference<TextPageData<Asset>>(){}, pageLink);
  350 + new TypeReference<TextPageData<Asset>>() {
  351 + }, pageLink);
344 352 Assert.assertFalse(pageData.hasNext());
345 353 Assert.assertEquals(0, pageData.getData().size());
346 354
347 355 for (Asset asset : loadedAssetsTitle2) {
348   - doDelete("/api/asset/"+asset.getId().getId().toString())
  356 + doDelete("/api/asset/" + asset.getId().getId().toString())
349 357 .andExpect(status().isOk());
350 358 }
351 359
352 360 pageLink = new TextPageLink(4, title2);
353 361 pageData = doGetTypedWithPageLink("/api/tenant/assets?",
354   - new TypeReference<TextPageData<Asset>>(){}, pageLink);
  362 + new TypeReference<TextPageData<Asset>>() {
  363 + }, pageLink);
355 364 Assert.assertFalse(pageData.hasNext());
356 365 Assert.assertEquals(0, pageData.getData().size());
357 366 }
... ... @@ -361,10 +370,10 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
361 370 String title1 = "Asset title 1";
362 371 String type1 = "typeA";
363 372 List<Asset> assetsType1 = new ArrayList<>();
364   - for (int i=0;i<143;i++) {
  373 + for (int i = 0; i < 143; i++) {
365 374 Asset asset = new Asset();
366 375 String suffix = RandomStringUtils.randomAlphanumeric(15);
367   - String name = title1+suffix;
  376 + String name = title1 + suffix;
368 377 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
369 378 asset.setName(name);
370 379 asset.setType(type1);
... ... @@ -373,10 +382,10 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
373 382 String title2 = "Asset title 2";
374 383 String type2 = "typeB";
375 384 List<Asset> assetsType2 = new ArrayList<>();
376   - for (int i=0;i<75;i++) {
  385 + for (int i = 0; i < 75; i++) {
377 386 Asset asset = new Asset();
378 387 String suffix = RandomStringUtils.randomAlphanumeric(15);
379   - String name = title2+suffix;
  388 + String name = title2 + suffix;
380 389 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
381 390 asset.setName(name);
382 391 asset.setType(type2);
... ... @@ -388,7 +397,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
388 397 TextPageData<Asset> pageData = null;
389 398 do {
390 399 pageData = doGetTypedWithPageLink("/api/tenant/assets?type={type}&",
391   - new TypeReference<TextPageData<Asset>>(){}, pageLink, type1);
  400 + new TypeReference<TextPageData<Asset>>() {
  401 + }, pageLink, type1);
392 402 loadedAssetsType1.addAll(pageData.getData());
393 403 if (pageData.hasNext()) {
394 404 pageLink = pageData.getNextPageLink();
... ... @@ -404,7 +414,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
404 414 pageLink = new TextPageLink(4);
405 415 do {
406 416 pageData = doGetTypedWithPageLink("/api/tenant/assets?type={type}&",
407   - new TypeReference<TextPageData<Asset>>(){}, pageLink, type2);
  417 + new TypeReference<TextPageData<Asset>>() {
  418 + }, pageLink, type2);
408 419 loadedAssetsType2.addAll(pageData.getData());
409 420 if (pageData.hasNext()) {
410 421 pageLink = pageData.getNextPageLink();
... ... @@ -417,24 +428,26 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
417 428 Assert.assertEquals(assetsType2, loadedAssetsType2);
418 429
419 430 for (Asset asset : loadedAssetsType1) {
420   - doDelete("/api/asset/"+asset.getId().getId().toString())
  431 + doDelete("/api/asset/" + asset.getId().getId().toString())
421 432 .andExpect(status().isOk());
422 433 }
423 434
424 435 pageLink = new TextPageLink(4);
425 436 pageData = doGetTypedWithPageLink("/api/tenant/assets?type={type}&",
426   - new TypeReference<TextPageData<Asset>>(){}, pageLink, type1);
  437 + new TypeReference<TextPageData<Asset>>() {
  438 + }, pageLink, type1);
427 439 Assert.assertFalse(pageData.hasNext());
428 440 Assert.assertEquals(0, pageData.getData().size());
429 441
430 442 for (Asset asset : loadedAssetsType2) {
431   - doDelete("/api/asset/"+asset.getId().getId().toString())
  443 + doDelete("/api/asset/" + asset.getId().getId().toString())
432 444 .andExpect(status().isOk());
433 445 }
434 446
435 447 pageLink = new TextPageLink(4);
436 448 pageData = doGetTypedWithPageLink("/api/tenant/assets?type={type}&",
437   - new TypeReference<TextPageData<Asset>>(){}, pageLink, type2);
  449 + new TypeReference<TextPageData<Asset>>() {
  450 + }, pageLink, type2);
438 451 Assert.assertFalse(pageData.hasNext());
439 452 Assert.assertEquals(0, pageData.getData().size());
440 453 }
... ... @@ -447,9 +460,9 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
447 460 CustomerId customerId = customer.getId();
448 461
449 462 List<Asset> assets = new ArrayList<>();
450   - for (int i=0;i<128;i++) {
  463 + for (int i = 0; i < 128; i++) {
451 464 Asset asset = new Asset();
452   - asset.setName("Asset"+i);
  465 + asset.setName("Asset" + i);
453 466 asset.setType("default");
454 467 asset = doPost("/api/asset", asset, Asset.class);
455 468 assets.add(doPost("/api/customer/" + customerId.getId().toString()
... ... @@ -461,7 +474,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
461 474 TextPageData<Asset> pageData = null;
462 475 do {
463 476 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?",
464   - new TypeReference<TextPageData<Asset>>(){}, pageLink);
  477 + new TypeReference<TextPageData<Asset>>() {
  478 + }, pageLink);
465 479 loadedAssets.addAll(pageData.getData());
466 480 if (pageData.hasNext()) {
467 481 pageLink = pageData.getNextPageLink();
... ... @@ -483,10 +497,10 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
483 497
484 498 String title1 = "Asset title 1";
485 499 List<Asset> assetsTitle1 = new ArrayList<>();
486   - for (int i=0;i<125;i++) {
  500 + for (int i = 0; i < 125; i++) {
487 501 Asset asset = new Asset();
488 502 String suffix = RandomStringUtils.randomAlphanumeric(15);
489   - String name = title1+suffix;
  503 + String name = title1 + suffix;
490 504 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
491 505 asset.setName(name);
492 506 asset.setType("default");
... ... @@ -496,10 +510,10 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
496 510 }
497 511 String title2 = "Asset title 2";
498 512 List<Asset> assetsTitle2 = new ArrayList<>();
499   - for (int i=0;i<143;i++) {
  513 + for (int i = 0; i < 143; i++) {
500 514 Asset asset = new Asset();
501 515 String suffix = RandomStringUtils.randomAlphanumeric(15);
502   - String name = title2+suffix;
  516 + String name = title2 + suffix;
503 517 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
504 518 asset.setName(name);
505 519 asset.setType("default");
... ... @@ -513,7 +527,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
513 527 TextPageData<Asset> pageData = null;
514 528 do {
515 529 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?",
516   - new TypeReference<TextPageData<Asset>>(){}, pageLink);
  530 + new TypeReference<TextPageData<Asset>>() {
  531 + }, pageLink);
517 532 loadedAssetsTitle1.addAll(pageData.getData());
518 533 if (pageData.hasNext()) {
519 534 pageLink = pageData.getNextPageLink();
... ... @@ -529,7 +544,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
529 544 pageLink = new TextPageLink(4, title2);
530 545 do {
531 546 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?",
532   - new TypeReference<TextPageData<Asset>>(){}, pageLink);
  547 + new TypeReference<TextPageData<Asset>>() {
  548 + }, pageLink);
533 549 loadedAssetsTitle2.addAll(pageData.getData());
534 550 if (pageData.hasNext()) {
535 551 pageLink = pageData.getNextPageLink();
... ... @@ -548,7 +564,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
548 564
549 565 pageLink = new TextPageLink(4, title1);
550 566 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?",
551   - new TypeReference<TextPageData<Asset>>(){}, pageLink);
  567 + new TypeReference<TextPageData<Asset>>() {
  568 + }, pageLink);
552 569 Assert.assertFalse(pageData.hasNext());
553 570 Assert.assertEquals(0, pageData.getData().size());
554 571
... ... @@ -559,7 +576,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
559 576
560 577 pageLink = new TextPageLink(4, title2);
561 578 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?",
562   - new TypeReference<TextPageData<Asset>>(){}, pageLink);
  579 + new TypeReference<TextPageData<Asset>>() {
  580 + }, pageLink);
563 581 Assert.assertFalse(pageData.hasNext());
564 582 Assert.assertEquals(0, pageData.getData().size());
565 583 }
... ... @@ -574,10 +592,10 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
574 592 String title1 = "Asset title 1";
575 593 String type1 = "typeC";
576 594 List<Asset> assetsType1 = new ArrayList<>();
577   - for (int i=0;i<125;i++) {
  595 + for (int i = 0; i < 125; i++) {
578 596 Asset asset = new Asset();
579 597 String suffix = RandomStringUtils.randomAlphanumeric(15);
580   - String name = title1+suffix;
  598 + String name = title1 + suffix;
581 599 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
582 600 asset.setName(name);
583 601 asset.setType(type1);
... ... @@ -588,10 +606,10 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
588 606 String title2 = "Asset title 2";
589 607 String type2 = "typeD";
590 608 List<Asset> assetsType2 = new ArrayList<>();
591   - for (int i=0;i<143;i++) {
  609 + for (int i = 0; i < 143; i++) {
592 610 Asset asset = new Asset();
593 611 String suffix = RandomStringUtils.randomAlphanumeric(15);
594   - String name = title2+suffix;
  612 + String name = title2 + suffix;
595 613 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
596 614 asset.setName(name);
597 615 asset.setType(type2);
... ... @@ -605,7 +623,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
605 623 TextPageData<Asset> pageData = null;
606 624 do {
607 625 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&",
608   - new TypeReference<TextPageData<Asset>>(){}, pageLink, type1);
  626 + new TypeReference<TextPageData<Asset>>() {
  627 + }, pageLink, type1);
609 628 loadedAssetsType1.addAll(pageData.getData());
610 629 if (pageData.hasNext()) {
611 630 pageLink = pageData.getNextPageLink();
... ... @@ -621,7 +640,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
621 640 pageLink = new TextPageLink(4);
622 641 do {
623 642 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&",
624   - new TypeReference<TextPageData<Asset>>(){}, pageLink, type2);
  643 + new TypeReference<TextPageData<Asset>>() {
  644 + }, pageLink, type2);
625 645 loadedAssetsType2.addAll(pageData.getData());
626 646 if (pageData.hasNext()) {
627 647 pageLink = pageData.getNextPageLink();
... ... @@ -640,7 +660,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
640 660
641 661 pageLink = new TextPageLink(4);
642 662 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&",
643   - new TypeReference<TextPageData<Asset>>(){}, pageLink, type1);
  663 + new TypeReference<TextPageData<Asset>>() {
  664 + }, pageLink, type1);
644 665 Assert.assertFalse(pageData.hasNext());
645 666 Assert.assertEquals(0, pageData.getData().size());
646 667
... ... @@ -651,7 +672,8 @@ public abstract class BaseAssetControllerTest extends AbstractControllerTest {
651 672
652 673 pageLink = new TextPageLink(4);
653 674 pageData = doGetTypedWithPageLink("/api/customer/" + customerId.getId().toString() + "/assets?type={type}&",
654   - new TypeReference<TextPageData<Asset>>(){}, pageLink, type2);
  675 + new TypeReference<TextPageData<Asset>>() {
  676 + }, pageLink, type2);
655 677 Assert.assertFalse(pageData.hasNext());
656 678 Assert.assertEquals(0, pageData.getData().size());
657 679 }
... ...
... ... @@ -426,7 +426,7 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
426 426 message.setPayload(strKvs.getBytes());
427 427 client.publish("v1/devices/me/telemetry", message);
428 428 Thread.sleep(1000);
429   -// client.disconnect();
  429 + client.disconnect();
430 430 }
431 431
432 432 private void awaitConnected(MqttAsyncClient client, long ms) throws InterruptedException {
... ... @@ -463,13 +463,13 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
463 463 MqttConnectOptions options = new MqttConnectOptions();
464 464 options.setUserName(accessToken);
465 465 client.connect(options);
466   - Thread.sleep(3000);
  466 + awaitConnected(client, TimeUnit.SECONDS.toMillis(30));
467 467
468 468 MqttMessage message = new MqttMessage();
469 469 message.setPayload((stringKV).getBytes());
470 470 client.publish("v1/devices/me/attributes", message);
471 471 Thread.sleep(1000);
472   -
  472 + client.disconnect();
473 473 return new HashSet<>(doGetAsync("/api/plugins/telemetry/DEVICE/" + viewDeviceId + "/keys/attributes", List.class));
474 474 }
475 475
... ...
... ... @@ -16,10 +16,12 @@
16 16 package org.thingsboard.server.controller;
17 17
18 18 import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;
  19 +import org.junit.BeforeClass;
19 20 import org.junit.ClassRule;
20 21 import org.junit.extensions.cpsuite.ClasspathSuite;
21 22 import org.junit.runner.RunWith;
22 23 import org.thingsboard.server.dao.CustomCassandraCQLUnit;
  24 +import org.thingsboard.server.queue.memory.InMemoryStorage;
23 25
24 26 import java.util.Arrays;
25 27
... ... @@ -37,4 +39,9 @@ public class ControllerNoSqlTestSuite {
37 39 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false),
38 40 new ClassPathCQLDataSet("cassandra/system-test.cql", false, false)),
39 41 "cassandra-test.yaml", 30000l);
  42 +
  43 + @BeforeClass
  44 + public static void cleanupInMemStorage(){
  45 + InMemoryStorage.getInstance().cleanup();
  46 + }
40 47 }
... ...
... ... @@ -15,10 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.controller;
17 17
  18 +import org.junit.BeforeClass;
18 19 import org.junit.ClassRule;
19 20 import org.junit.extensions.cpsuite.ClasspathSuite;
20 21 import org.junit.runner.RunWith;
21 22 import org.thingsboard.server.dao.CustomSqlUnit;
  23 +import org.thingsboard.server.queue.memory.InMemoryStorage;
22 24
23 25 import java.util.Arrays;
24 26
... ... @@ -33,4 +35,9 @@ public class ControllerSqlTestSuite {
33 35 Arrays.asList("sql/schema-ts-hsql.sql", "sql/schema-entities-hsql.sql", "sql/schema-entities-idx.sql", "sql/system-data.sql"),
34 36 "sql/drop-all-tables.sql",
35 37 "sql-test.properties");
  38 +
  39 + @BeforeClass
  40 + public static void cleanupInMemStorage(){
  41 + InMemoryStorage.getInstance().cleanup();
  42 + }
36 43 }
... ...
... ... @@ -16,10 +16,12 @@
16 16 package org.thingsboard.server.mqtt;
17 17
18 18 import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;
  19 +import org.junit.BeforeClass;
19 20 import org.junit.ClassRule;
20 21 import org.junit.extensions.cpsuite.ClasspathSuite;
21 22 import org.junit.runner.RunWith;
22 23 import org.thingsboard.server.dao.CustomCassandraCQLUnit;
  24 +import org.thingsboard.server.queue.memory.InMemoryStorage;
23 25
24 26 import java.util.Arrays;
25 27
... ... @@ -36,4 +38,9 @@ public class MqttNoSqlTestSuite {
36 38 new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
37 39 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
38 40 "cassandra-test.yaml", 30000l);
  41 +
  42 + @BeforeClass
  43 + public static void cleanupInMemStorage(){
  44 + InMemoryStorage.getInstance().cleanup();
  45 + }
39 46 }
... ...
... ... @@ -15,10 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.mqtt;
17 17
  18 +import org.junit.BeforeClass;
18 19 import org.junit.ClassRule;
19 20 import org.junit.extensions.cpsuite.ClasspathSuite;
20 21 import org.junit.runner.RunWith;
21 22 import org.thingsboard.server.dao.CustomSqlUnit;
  23 +import org.thingsboard.server.queue.memory.InMemoryStorage;
22 24
23 25 import java.util.Arrays;
24 26
... ... @@ -32,4 +34,9 @@ public class MqttSqlTestSuite {
32 34 Arrays.asList("sql/schema-ts-hsql.sql", "sql/schema-entities-hsql.sql", "sql/system-data.sql"),
33 35 "sql/drop-all-tables.sql",
34 36 "sql-test.properties");
  37 +
  38 + @BeforeClass
  39 + public static void cleanupInMemStorage(){
  40 + InMemoryStorage.getInstance().cleanup();
  41 + }
35 42 }
... ...
... ... @@ -16,11 +16,13 @@
16 16 package org.thingsboard.server.rules;
17 17
18 18 import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;
  19 +import org.junit.BeforeClass;
19 20 import org.junit.ClassRule;
20 21 import org.junit.extensions.cpsuite.ClasspathSuite;
21 22 import org.junit.runner.RunWith;
22 23 import org.thingsboard.server.dao.CustomCassandraCQLUnit;
23 24 import org.thingsboard.server.dao.CustomSqlUnit;
  25 +import org.thingsboard.server.queue.memory.InMemoryStorage;
24 26
25 27 import java.util.Arrays;
26 28
... ... @@ -40,4 +42,9 @@ public class RuleEngineNoSqlTestSuite {
40 42 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
41 43 "cassandra-test.yaml", 30000l);
42 44
  45 + @BeforeClass
  46 + public static void cleanupInMemStorage(){
  47 + InMemoryStorage.getInstance().cleanup();
  48 + }
  49 +
43 50 }
... ...
... ... @@ -15,10 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.rules;
17 17
  18 +import org.junit.BeforeClass;
18 19 import org.junit.ClassRule;
19 20 import org.junit.extensions.cpsuite.ClasspathSuite;
20 21 import org.junit.runner.RunWith;
21 22 import org.thingsboard.server.dao.CustomSqlUnit;
  23 +import org.thingsboard.server.queue.memory.InMemoryStorage;
22 24
23 25 import java.util.Arrays;
24 26
... ... @@ -33,4 +35,9 @@ public class RuleEngineSqlTestSuite {
33 35 Arrays.asList("sql/schema-ts-hsql.sql", "sql/schema-entities-hsql.sql", "sql/system-data.sql"),
34 36 "sql/drop-all-tables.sql",
35 37 "sql-test.properties");
  38 +
  39 + @BeforeClass
  40 + public static void cleanupInMemStorage(){
  41 + InMemoryStorage.getInstance().cleanup();
  42 + }
36 43 }
... ...
... ... @@ -16,10 +16,12 @@
16 16 package org.thingsboard.server.system;
17 17
18 18 import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;
  19 +import org.junit.BeforeClass;
19 20 import org.junit.ClassRule;
20 21 import org.junit.extensions.cpsuite.ClasspathSuite;
21 22 import org.junit.runner.RunWith;
22 23 import org.thingsboard.server.dao.CustomCassandraCQLUnit;
  24 +import org.thingsboard.server.queue.memory.InMemoryStorage;
23 25
24 26 import java.util.Arrays;
25 27
... ... @@ -38,4 +40,9 @@ public class SystemNoSqlTestSuite {
38 40 new ClassPathCQLDataSet("cassandra/schema-entities.cql", false, false),
39 41 new ClassPathCQLDataSet("cassandra/system-data.cql", false, false)),
40 42 "cassandra-test.yaml", 30000l);
  43 +
  44 + @BeforeClass
  45 + public static void cleanupInMemStorage(){
  46 + InMemoryStorage.getInstance().cleanup();
  47 + }
41 48 }
... ...
... ... @@ -15,10 +15,12 @@
15 15 */
16 16 package org.thingsboard.server.system;
17 17
  18 +import org.junit.BeforeClass;
18 19 import org.junit.ClassRule;
19 20 import org.junit.extensions.cpsuite.ClasspathSuite;
20 21 import org.junit.runner.RunWith;
21 22 import org.thingsboard.server.dao.CustomSqlUnit;
  23 +import org.thingsboard.server.queue.memory.InMemoryStorage;
22 24
23 25 import java.util.Arrays;
24 26
... ... @@ -35,4 +37,9 @@ public class SystemSqlTestSuite {
35 37 "sql/drop-all-tables.sql",
36 38 "sql-test.properties");
37 39
  40 + @BeforeClass
  41 + public static void cleanupInMemStorage(){
  42 + InMemoryStorage.getInstance().cleanup();
  43 + }
  44 +
38 45 }
... ...
... ... @@ -30,11 +30,9 @@ import java.util.concurrent.TimeUnit;
30 30 public final class InMemoryStorage {
31 31 private static InMemoryStorage instance;
32 32 private final ConcurrentHashMap<String, BlockingQueue<TbQueueMsg>> storage;
33   - private volatile boolean stopped;
34 33
35 34 private InMemoryStorage() {
36 35 storage = new ConcurrentHashMap<>();
37   - stopped = false;
38 36 }
39 37
40 38 public static InMemoryStorage getInstance() {
... ... @@ -52,33 +50,31 @@ public final class InMemoryStorage {
52 50 return storage.computeIfAbsent(topic, (t) -> new LinkedBlockingQueue<>()).add(msg);
53 51 }
54 52
55   - public <T extends TbQueueMsg> List<T> get(String topic, long durationInMillis) {
  53 + public <T extends TbQueueMsg> List<T> get(String topic, long durationInMillis) throws InterruptedException {
56 54 if (storage.containsKey(topic)) {
57   - try {
58   - List<T> entities;
59   - T first = (T) storage.get(topic).poll(durationInMillis, TimeUnit.MILLISECONDS);
60   - if (first != null) {
61   - entities = new ArrayList<>();
62   - entities.add(first);
63   - List<TbQueueMsg> otherList = new ArrayList<>();
64   - storage.get(topic).drainTo(otherList, 999);
65   - for (TbQueueMsg other : otherList) {
66   - entities.add((T) other);
67   - }
68   - } else {
69   - entities = Collections.emptyList();
70   - }
71   - return entities;
72   - } catch (InterruptedException e) {
73   - if (!stopped) {
74   - log.warn("Queue was interrupted", e);
  55 + List<T> entities;
  56 + T first = (T) storage.get(topic).poll(durationInMillis, TimeUnit.MILLISECONDS);
  57 + if (first != null) {
  58 + entities = new ArrayList<>();
  59 + entities.add(first);
  60 + List<TbQueueMsg> otherList = new ArrayList<>();
  61 + storage.get(topic).drainTo(otherList, 999);
  62 + for (TbQueueMsg other : otherList) {
  63 + entities.add((T) other);
75 64 }
  65 + } else {
  66 + entities = Collections.emptyList();
76 67 }
  68 + return entities;
77 69 }
78 70 return Collections.emptyList();
79 71 }
80 72
81   - public void stop() {
82   - stopped = true;
  73 + /**
  74 + * Used primarily for testing.
  75 + */
  76 + public void cleanup() {
  77 + storage.clear();
83 78 }
  79 +
84 80 }
... ...
... ... @@ -66,7 +66,16 @@ public class InMemoryTbQueueConsumer<T extends TbQueueMsg> implements TbQueueCon
66 66 if (subscribed) {
67 67 List<T> messages = partitions
68 68 .stream()
69   - .map(tpi -> storage.get(tpi.getFullTopicName(), durationInMillis))
  69 + .map(tpi -> {
  70 + try {
  71 + return storage.get(tpi.getFullTopicName(), durationInMillis);
  72 + } catch (InterruptedException e) {
  73 + if (!stopped) {
  74 + log.error("Queue was interrupted.", e);
  75 + }
  76 + return Collections.emptyList();
  77 + }
  78 + })
70 79 .flatMap(List::stream)
71 80 .map(msg -> (T) msg).collect(Collectors.toList());
72 81 if (messages.size() > 0) {
... ...
... ... @@ -54,7 +54,7 @@
54 54 <dependency>
55 55 <groupId>org.apache.cassandra</groupId>
56 56 <artifactId>cassandra-all</artifactId>
57   - <version>3.11.4</version>
  57 + <version>3.11.6</version>
58 58 </dependency>
59 59 <dependency>
60 60 <groupId>com.datastax.cassandra</groupId>
... ...