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
Fixed client event test with new condition that waits for message queues to be empty
Christian Bauer8ebef756b547
diff --git a/manager/src/main/java/org/openremote/manager/event/ClientEventService.java b/manager/src/main/java/org/openremote/manager/event/ClientEventService.javaindex b9ddb1556..d716f846a 100644--- a/manager/src/main/java/org/openremote/manager/event/ClientEventService.java+++ b/manager/src/main/java/org/openremote/manager/event/ClientEventService.java@@ -20,6 +20,7 @@package org.openremote.manager.event;import org.apache.camel.Exchange;+import org.apache.camel.LoggingLevel;import org.apache.camel.builder.RouteBuilder;import org.openremote.container.Container;import org.openremote.container.ContainerService;@@ -184,6 +185,7 @@ public class ClientEventService implements ContainerService {from(ClientEventService.CLIENT_EVENT_QUEUE).routeId("ToClientWebsocketEvents")+ .log(LoggingLevel.INFO, "EVENT_DEBUG", "TO PUBLISH ${body}").choice().when(body().isInstanceOf(SharedEvent.class)).split(method(eventSubscriptions, "splitForSubscribers"))diff --git a/manager/src/main/java/org/openremote/manager/simulator/SimulatorService.java b/manager/src/main/java/org/openremote/manager/simulator/SimulatorService.javaindex 9ec148412..e4c4445cc 100644--- a/manager/src/main/java/org/openremote/manager/simulator/SimulatorService.java+++ b/manager/src/main/java/org/openremote/manager/simulator/SimulatorService.java@@ -150,4 +150,9 @@ public class SimulatorService extends RouteBuilder implements ContainerService {}});}++ @Override+ public String toString() {+ return getClass().getSimpleName() + "{}";+ }}diff --git a/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy b/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovyindex 4654c09fd..65d25c01d 100644--- a/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy+++ b/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy@@ -1,6 +1,7 @@package org.openremote.testimport com.google.common.collect.Lists+import org.apache.camel.spi.BrowsableEndpointimport org.drools.core.time.impl.PseudoClockSchedulerimport org.openremote.agent.protocol.Protocolimport org.openremote.container.Container@@ -28,6 +29,7 @@ import org.openremote.manager.security.ManagerIdentityServiceimport org.openremote.manager.setup.SetupServiceimport org.openremote.manager.simulator.SimulatorServiceimport org.openremote.manager.web.ManagerWebService+import spock.util.concurrent.PollingConditionsimport java.util.concurrent.TimeUnit@@ -36,6 +38,7 @@ import static org.openremote.container.security.IdentityService.IDENTITY_NETWORKimport static org.openremote.container.timer.TimerService.Clock.PSEUDOimport static org.openremote.container.timer.TimerService.TIMER_CLOCK_TYPEimport static org.openremote.container.web.WebService.WEBSERVER_LISTEN_PORT+import static org.openremote.manager.event.ClientEventService.CLIENT_EVENT_QUEUEimport static org.openremote.manager.setup.SetupTasks.*trait ManagerContainerTrait extends ContainerTrait {@@ -163,4 +166,16 @@ trait ManagerContainerTrait extends ContainerTrait {}}+ static void noPendingExchangesOnMessageEndpoint(Container container, String... endpointName) {+ for (String name : endpointName) {+ def endpoint = container.getService(MessageBrokerSetupService.class).context.getEndpoint(name)+ if (!endpoint) {+ throw new IllegalArgumentException("Messaging endpoint not found: " + name)+ }+ new PollingConditions(initialDelay: 0.1, delay: 0.05).eventually {+ assert ((BrowsableEndpoint)endpoint).exchanges.size() == 0+ }+ }+ }+}diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovyindex 64721e464..4559e2fe9 100644--- a/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy+++ b/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy@@ -111,7 +111,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTraitupdatesPassedDatapointService.add(assetState)}- when: "the container is started with the mock protocol and consumers"+ and: "the container is started with the mock protocol and consumers"def serverPort = findEphemeralPort()def container = startContainer(defaultConfig(serverPort), defaultServices(mockProtocol))def assetStorageService = container.getService(AssetStorageService.class)@@ -119,12 +119,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTraitdef managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)- then: "the container should be running and initialised"- conditions.eventually {- assert noEventProcessedIn(assetProcessingService, 500)- }-- then: "register mock asset processors"+ and: "register mock asset processors"assetProcessingService.processors.add(mockDatapointServiceConsumer)assetProcessingService.processors.add(3, mockAssetStorageConsumer)assetProcessingService.processors.add(2, mockRulesServiceConsumer)diff --git a/test/src/test/groovy/org/openremote/test/event/ClientEventTest.groovy b/test/src/test/groovy/org/openremote/test/event/ClientEventTest.groovyindex dab30536f..b39ec7ef0 100644--- a/test/src/test/groovy/org/openremote/test/event/ClientEventTest.groovy+++ b/test/src/test/groovy/org/openremote/test/event/ClientEventTest.groovy@@ -21,7 +21,6 @@ package org.openremote.test.eventimport com.vividsolutions.jts.geom.Coordinateimport com.vividsolutions.jts.geom.GeometryFactory-import org.openremote.agent.protocol.simulator.SimulatorProtocolimport org.openremote.manager.agent.AgentServiceimport org.openremote.manager.asset.AssetProcessingServiceimport org.openremote.manager.asset.AssetStorageService@@ -43,8 +42,8 @@ import org.openremote.test.ManagerContainerTraitimport spock.lang.Specificationimport spock.util.concurrent.PollingConditions-import static org.openremote.container.util.MapAccess.getBooleanimport static org.openremote.container.util.MapAccess.getString+import static org.openremote.manager.event.ClientEventService.CLIENT_EVENT_QUEUEimport static org.openremote.manager.event.ClientEventService.WEBSOCKET_EVENTSimport static org.openremote.manager.setup.AbstractKeycloakSetup.SETUP_ADMIN_PASSWORDimport static org.openremote.manager.setup.AbstractKeycloakSetup.SETUP_ADMIN_PASSWORD_DEFAULT@@ -62,7 +61,7 @@ class ClientEventTest extends Specification implements ManagerContainerTrait, Gwgiven: "expected conditions"def conditions = new PollingConditions(timeout: 10, delay: 1)- when: "the container is started"+ and: "the container is started"def serverPort = findEphemeralPort()def container = startContainer(defaultConfig(serverPort), defaultServices())def assetStorageService = container.getService(AssetStorageService.class)@@ -70,13 +69,9 @@ class ClientEventTest extends Specification implements ManagerContainerTrait, Gwdef agentService = container.getService(AgentService.class)def internalClientEventService = container.getService(org.openremote.manager.event.ClientEventService.class)def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)- def simulatorProtocol = container.getService(SimulatorProtocol.class)- then: "the system should settle down"- conditions.eventually {- assert noEventProcessedIn(assetProcessingService, 500)- assert simulatorProtocol.elements.size() == 10- }+ expect: "all client events happening during startup to be consumed"+ noPendingExchangesOnMessageEndpoint(container, CLIENT_EVENT_QUEUE)when: "a client websocket connection and attached event bus and service"def accessToken = {diff --git a/test/src/test/groovy/org/openremote/test/event/FailRunner.groovy b/test/src/test/groovy/org/openremote/test/event/FailRunner.groovydeleted file mode 100644index 54b433815..000000000--- a/test/src/test/groovy/org/openremote/test/event/FailRunner.groovy+++ /dev/null@@ -1,30 +0,0 @@-package org.openremote.test.event--import org.junit.runner.RunWith-import org.junit.runners.Suite-import org.openremote.test.assets.AssetBrowserPresenterTest--/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */--@RunWith(Suite.class)[email protected]([AssetBrowserPresenterTest.class, ClientEventTest.class])-class FailRunner {-}diff --git a/test/src/test/groovy/org/openremote/test/event/PassRunner.groovy b/test/src/test/groovy/org/openremote/test/event/PassRunner.groovydeleted file mode 100644index 0079693d9..000000000--- a/test/src/test/groovy/org/openremote/test/event/PassRunner.groovy+++ /dev/null@@ -1,30 +0,0 @@-package org.openremote.test.event--import org.junit.runner.RunWith-import org.junit.runners.Suite-import org.openremote.test.assets.AssetBrowserPresenterTest--/*- * Copyright 2017, OpenRemote Inc.- *- * See the CONTRIBUTORS.txt file in the distribution for a- * full listing of individual contributors.- *- * This program is free software: you can redistribute it and/or modify- * it under the terms of the GNU Affero General Public License as- * published by the Free Software Foundation, either version 3 of the- * License, or (at your option) any later version.- *- * This program is distributed in the hope that it will be useful,- * but WITHOUT ANY WARRANTY; without even the implied warranty of- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- * GNU Affero General Public License for more details.- *- * You should have received a copy of the GNU Affero General Public License- * along with this program. If not, see <http://www.gnu.org/licenses/>.- */--@RunWith(Suite.class)[email protected]([ClientEventTest.class, AssetBrowserPresenterTest.class])-class PassRunner {-}