100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Backend test robustness improvement (#2356)
Rich Turnerf56825ff3f52
diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.javaindex b2d176d13..3e4f51ed1 100644--- a/model/src/main/java/org/openremote/model/asset/Asset.java+++ b/model/src/main/java/org/openremote/model/asset/Asset.java@@ -426,10 +426,8 @@ public abstract class Asset<T extends Asset<?>> implements IdentifiableEntity<T>}/**- * NOTE: This is a transient and optional property, set only in database query results.- * <p>- * The identifiers of all parents representing the path in the tree. The first element is the identifier of this- * instance, the last is the root asset without a parent.+ * The identifiers of all parents representing the path in the tree. The first element is the+ * root asset without a parent, the last is the identifier of this instance.*/public String[] getPath() {return path;diff --git a/test/src/main/groovy/org/openremote/test/ContainerTrait.groovy b/test/src/main/groovy/org/openremote/test/ContainerTrait.groovyindex 5559e1193..2a751619a 100644--- a/test/src/main/groovy/org/openremote/test/ContainerTrait.groovy+++ b/test/src/main/groovy/org/openremote/test/ContainerTrait.groovy@@ -219,8 +219,41 @@ trait ContainerTrait {}if (!TestFixture.assets.isEmpty()) {- LOG.info("Re-inserting ${TestFixture.assets.size()} asset(s)")- TestFixture.assets.forEach { a ->+ // Redeploy agents first except for agents under an asset parent then merge those first+ def agents = TestFixture.assets.stream().filter { it instanceof Agent }.toList()+ def assets = new ArrayList<>(TestFixture.assets.stream().filter { !(it instanceof Agent) }.toList())+ LOG.info("Re-inserting ${agents.size()} agent(s)")+ agents.forEach { a ->+ a.version = 0++ if (a.path.size() > 1) {+ for (final def assetId in a.path) {+ if (assetId == a.id) {+ continue+ }+ def ancestorIndex = assets.findIndexOf { it.id == assetId }+ def ancestor = ancestorIndex >= 0 ? assets.remove(ancestorIndex) : null+ if (ancestor != null) {+ assetStorageService.merge(ancestor, true)+ }+ }+ }++ assetStorageService.merge(a, true)+ }++ counter = 0+ def agentsDeployed = false+ while (!agentsDeployed) {+ if (counter++ > 100) {+ throw new IllegalStateException("Failed to deploy agents")+ }+ agentsDeployed = container.getService(AgentService.class).agents.size() == agents.size()+ Thread.sleep(100)+ }++ LOG.info("Re-inserting ${assets.size()} asset(s)")+ assets.forEach { a ->a.version = 0assetStorageService.merge(a, true)}