Commit 714b7bd7798bde87e15da2aeb8ae985363d58353

Authored by Andrii Shvaika
1 parent 9942231d

Tests Fix

... ... @@ -102,6 +102,7 @@ public abstract class BaseEntityQueryControllerTest extends AbstractControllerTe
102 102 device.setType("default");
103 103 device.setLabel("testLabel" + (int) (Math.random() * 1000));
104 104 devices.add(doPost("/api/device", device, Device.class));
  105 + Thread.sleep(1);
105 106 }
106 107 DeviceTypeFilter filter = new DeviceTypeFilter();
107 108 filter.setDeviceType("default");
... ... @@ -141,6 +142,7 @@ public abstract class BaseEntityQueryControllerTest extends AbstractControllerTe
141 142 device.setType("default");
142 143 device.setLabel("testLabel" + (int) (Math.random() * 1000));
143 144 devices.add(doPost("/api/device", device, Device.class));
  145 + Thread.sleep(1);
144 146 }
145 147
146 148 DeviceTypeFilter filter = new DeviceTypeFilter();
... ... @@ -210,6 +212,7 @@ public abstract class BaseEntityQueryControllerTest extends AbstractControllerTe
210 212 device.setType("default");
211 213 device.setLabel("testLabel" + (int) (Math.random() * 1000));
212 214 devices.add(doPost("/api/device?accessToken=" + name, device, Device.class));
  215 + Thread.sleep(1);
213 216 long temperature = (long) (Math.random() * 100);
214 217 temperatures.add(temperature);
215 218 if (temperature > 45) {
... ...
... ... @@ -88,7 +88,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
88 88 }
89 89
90 90 @Test
91   - public void testCountEntitiesByQuery() {
  91 + public void testCountEntitiesByQuery() throws InterruptedException {
92 92 List<Device> devices = new ArrayList<>();
93 93 for (int i = 0; i < 97; i++) {
94 94 Device device = new Device();
... ... @@ -131,7 +131,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
131 131 }
132 132
133 133 @Test
134   - public void testCountHierarchicalEntitiesByQuery() {
  134 + public void testCountHierarchicalEntitiesByQuery() throws InterruptedException {
135 135 List<Asset> assets = new ArrayList<>();
136 136 List<Device> devices = new ArrayList<>();
137 137 createTestHierarchy(assets, devices, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
... ... @@ -408,7 +408,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
408 408 deviceService.deleteDevicesByTenantId(tenantId);
409 409 }
410 410
411   - private void createTestHierarchy(List<Asset> assets, List<Device> devices, List<Long> consumptions, List<Long> highConsumptions, List<Long> temperatures, List<Long> highTemperatures) {
  411 + private void createTestHierarchy(List<Asset> assets, List<Device> devices, List<Long> consumptions, List<Long> highConsumptions, List<Long> temperatures, List<Long> highTemperatures) throws InterruptedException {
412 412 for (int i = 0; i < 5; i++) {
413 413 Asset asset = new Asset();
414 414 asset.setTenantId(tenantId);
... ... @@ -416,6 +416,8 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
416 416 asset.setType("type" + i);
417 417 asset.setLabel("AssetLabel" + i);
418 418 asset = assetService.saveAsset(asset);
  419 + //TO make sure devices have different created time
  420 + Thread.sleep(1);
419 421 assets.add(asset);
420 422 EntityRelation er = new EntityRelation();
421 423 er.setFrom(tenantId);
... ... @@ -435,6 +437,8 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
435 437 device.setType("default" + j);
436 438 device.setLabel("testLabel" + (int) (Math.random() * 1000));
437 439 device = deviceService.saveDevice(device);
  440 + //TO make sure devices have different created time
  441 + Thread.sleep(1);
438 442 devices.add(device);
439 443 er = new EntityRelation();
440 444 er.setFrom(asset.getId());
... ... @@ -452,7 +456,7 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
452 456 }
453 457
454 458 @Test
455   - public void testSimpleFindEntityDataByQuery() {
  459 + public void testSimpleFindEntityDataByQuery() throws InterruptedException {
456 460 List<Device> devices = new ArrayList<>();
457 461 for (int i = 0; i < 97; i++) {
458 462 Device device = new Device();
... ... @@ -460,6 +464,8 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
460 464 device.setName("Device" + i);
461 465 device.setType("default");
462 466 device.setLabel("testLabel" + (int) (Math.random() * 1000));
  467 + //TO make sure devices have different created time
  468 + Thread.sleep(1);
463 469 devices.add(deviceService.saveDevice(device));
464 470 }
465 471
... ... @@ -529,6 +535,8 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
529 535 device.setType("default");
530 536 device.setLabel("testLabel" + (int) (Math.random() * 1000));
531 537 devices.add(deviceService.saveDevice(device));
  538 + //TO make sure devices have different created time
  539 + Thread.sleep(1);
532 540 long temperature = (long) (Math.random() * 100);
533 541 temperatures.add(temperature);
534 542 if (temperature > 45) {
... ...