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
Switch to main repo production branch, updated staging.yml
Christian Bauer1668fefd9481
diff --git a/manager/server/src/main/resources/logging.properties b/manager/server/src/main/resources/logging.propertiesindex 778f6e53b..27b468b4d 100644--- a/manager/server/src/main/resources/logging.properties+++ b/manager/server/src/main/resources/logging.properties@@ -1,5 +1,7 @@# This is the default configuration file for logging, used when no other option-# is specified. Consider this the "default developer" configuration.+# is specified. Consider this the "default developer" configuration. If the+# file /deployment/logging.properties exists on the host, or the environment+# variable LOGGING_CONFIG_FILE is set, this file will not be used.handlers=java.util.logging.ConsoleHandler, org.openremote.manager.server.syslog.SyslogServicejava.util.logging.ConsoleHandler.formatter=org.openremote.container.util.LogFormatterdiff --git a/manager/test/src/test/groovy/org/openremote/test/rules/PseudoClockTimerTest.java b/manager/test/src/test/groovy/org/openremote/test/rules/PseudoClockTimerTest.javanew file mode 100644index 000000000..fa3eb208b--- /dev/null+++ b/manager/test/src/test/groovy/org/openremote/test/rules/PseudoClockTimerTest.java@@ -0,0 +1,134 @@+/*+ * Copyright 2015 Red Hat, Inc. and/or its affiliates.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+*/++package org.openremote.test.rules;++import org.drools.core.time.SessionPseudoClock;+import org.junit.Test;+import org.kie.api.KieServices;+import org.kie.api.builder.KieFileSystem;+import org.kie.api.builder.model.KieBaseModel;+import org.kie.api.builder.model.KieModuleModel;+import org.kie.api.runtime.KieSession;+import org.kie.api.runtime.conf.ClockTypeOption;+import org.kie.api.runtime.rule.FactHandle;++import java.util.concurrent.ExecutorService;+import java.util.concurrent.Executors;+import java.util.concurrent.Future;+import java.util.concurrent.TimeUnit;++import static org.junit.Assert.assertEquals;++/**+ * Based on:+ * https://github.com/kiegroup/drools/blob/master/drools-compiler/src/test/java/org/drools/compiler/integrationtests/CepFireUntilHaltTimerTest.java+ */+public class PseudoClockTimerTest {++ private KieSession ksession;+ private SessionPseudoClock clock;++ public void init(String clockType) {+ String drl = "package test.rules\n" ++ "\n" ++ "rule \"Do something triggered by timer\"\n" ++ "timer (int: 1s 1s)\n" ++ "then\n" ++ " System.out.println(\"### DO SOMETHING\");\n" ++ " insert(\"### TIME IS \" + drools.getWorkingMemory().getSessionClock().getCurrentTime());\n" ++ "end\n";++ KieServices ks = KieServices.Factory.get();++ KieModuleModel module = ks.newKieModuleModel();++ KieBaseModel defaultBase = module.newKieBaseModel("defaultKBase")+ .setDefault(true)+ .addPackage("*");+ defaultBase.newKieSessionModel("defaultKSession")+ .setDefault(true)+ .setClockType(ClockTypeOption.get(clockType));++ KieFileSystem kfs = ks.newKieFileSystem()+ .write("src/main/resources/r1.drl", drl);+ kfs.writeKModuleXML(module.toXML());+ ks.newKieBuilder(kfs).buildAll();++ ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId())+ .newKieSession();++ if (clockType.equals("pseudo"))+ clock = ksession.getSessionClock();+ }++ public void cleanup() {+ ksession.dispose();+ }++ @Test+ public void testTimerExecution() throws Exception {+/*+ init("realtime");+ performRealtimeClockTest();+ cleanup();+*/++/*+ init("pseudo");+ performPseudoClockTest();+ cleanup();+*/+ }++ private void performRealtimeClockTest() throws Exception {+ ExecutorService thread = Executors.newSingleThreadExecutor();+ final Future fireUntilHaltResult = thread.submit(() -> ksession.fireUntilHalt());++ try {+ Thread.sleep(10500);+ for (FactHandle factHandle : ksession.getFactHandles()) {+ System.err.println("GOT: " + ksession.getObject(factHandle));+ }+ assertEquals(10, ksession.getFactCount());+ } finally {+ ksession.halt();+ fireUntilHaltResult.get(60000, TimeUnit.SECONDS);+ thread.shutdown();+ }+ }++ private void performPseudoClockTest() throws Exception {+ ExecutorService thread = Executors.newSingleThreadExecutor();+ final Future fireUntilHaltResult = thread.submit(() -> ksession.fireUntilHalt());++ try {+ Thread.sleep(1000);+ for (int i = 0; i < 10; i++) {+ clock.advanceTime(1, TimeUnit.SECONDS);+ ksession.insert("foo" + i);+ }+ Thread.sleep(1000);+ for (FactHandle factHandle : ksession.getFactHandles()) {+ System.err.println("GOT: " + ksession.getObject(factHandle));+ }+ assertEquals(10, ksession.getFactCount());+ } finally {+ ksession.halt();+ fireUntilHaltResult.get(60000, TimeUnit.SECONDS);+ thread.shutdown();+ }+ }+}\ No newline at end of file