Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Reduced logging for GlobalLock, more tests for RulesFacts

Christian Bauer9b5c3bd20410
diff --git a/deployment/manager/logging.properties b/deployment/manager/logging.properties
index a5ccfc39e..5d3ea8537 100644
--- a/deployment/manager/logging.properties
+++ b/deployment/manager/logging.properties
@@ -101,6 +101,7 @@ org.hibernate.type.descriptor.sql.BasicBinder.level=WARNING
#org.openremote.manager.asset.AssetProcessingService.level=FINE
# Low-level debugging overrides, most of them are to stop chatty categories
+org.openremote.container.concurrent.GlobalLock.level=INFO
org.hibernate.level=WARNING
org.hibernate.cfg.beanvalidation.TypeSafeActivator.level=SEVERE
com.zaxxer.hikari.level=WARNING
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java b/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
index 60381bf25..a54e1afe5 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
@@ -22,7 +22,6 @@ package org.openremote.manager.rules;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rule;
import org.jeasy.rules.api.RuleListener;
-import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetQuery;
import org.openremote.model.attribute.AttributeEvent;
import org.openremote.model.attribute.AttributeExecuteStatus;
@@ -324,7 +323,7 @@ public class RulesFacts extends Facts implements RuleListener {
fact = temporaryFact.getFact();
}
return Optional.ofNullable(
- factType.isAssignableFrom(fact.getClass()) && predicate.test((T) fact) ? (T) fact: null
+ factType.isAssignableFrom(fact.getClass()) && predicate.test((T) fact) ? (T) fact : null
);
}
diff --git a/manager/src/main/resources/logging.properties b/manager/src/main/resources/logging.properties
index 9ce7eb1a9..27c229784 100644
--- a/manager/src/main/resources/logging.properties
+++ b/manager/src/main/resources/logging.properties
@@ -88,11 +88,12 @@ org.hibernate.SQL.level=WARNING
org.hibernate.type.descriptor.sql.BasicBinder.level=WARNING
# Log only attribute event processing begin/end, useful to debug many events
-#org.openremote.container.web.level=INFO
-#org.openremote.manager.level=INFO
-#org.openremote.manager.asset.AssetProcessingService.level=FINE
+org.openremote.container.web.level=INFO
+org.openremote.manager.level=INFO
+org.openremote.manager.asset.AssetProcessingService.level=FINE
# Low-level debugging overrides, most of them are to stop chatty categories
+org.openremote.container.concurrent.GlobalLock.level=INFO
org.hibernate.level=WARNING
org.hibernate.cfg.beanvalidation.TypeSafeActivator.level=SEVERE
com.zaxxer.hikari.level=WARNING
diff --git a/model/src/main/java/org/openremote/model/asset/BaseAssetQuery.java b/model/src/main/java/org/openremote/model/asset/BaseAssetQuery.java
index e0c68469d..671dc0add 100644
--- a/model/src/main/java/org/openremote/model/asset/BaseAssetQuery.java
+++ b/model/src/main/java/org/openremote/model/asset/BaseAssetQuery.java
@@ -463,13 +463,13 @@ public class BaseAssetQuery<CHILD extends BaseAssetQuery<CHILD>> {
this.value = value;
}
- public DateTimePredicate(String afterValue, String beforeValue) {
+ public DateTimePredicate(String rangeStart, String rangeEnd) {
this.operator = Operator.BETWEEN;
- this.value = afterValue;
- this.rangeValue = beforeValue;
+ this.value = rangeStart;
+ this.rangeValue = rangeEnd;
}
- public DateTimePredicate dateMatch(Operator dateMatch) {
+ public DateTimePredicate operator(Operator dateMatch) {
this.operator = dateMatch;
return this;
}
@@ -484,9 +484,9 @@ public class BaseAssetQuery<CHILD extends BaseAssetQuery<CHILD>> {
return this;
}
- public DateTimePredicate rangeValue(String beforeValue) {
+ public DateTimePredicate rangeValue(String rangeEnd) {
this.operator = Operator.BETWEEN;
- this.rangeValue = beforeValue;
+ this.rangeValue = rangeEnd;
return this;
}
diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesFactsTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesFactsTest.groovy
index 67aefb0c1..4bbd424f6 100644
--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesFactsTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesFactsTest.groovy
@@ -1,5 +1,7 @@
package org.openremote.test.rules
+import groovy.transform.EqualsAndHashCode
+import groovy.transform.ToString
import org.openremote.container.Container
import org.openremote.manager.rules.RulesClock
import org.openremote.manager.rules.RulesEngine
@@ -11,6 +13,7 @@ import java.util.stream.Collectors
class BasicRulesFactsTest extends Specification {
+ @ToString(includeNames = true)
class AnonFact {
String foo
double bar
@@ -21,15 +24,17 @@ class BasicRulesFactsTest extends Specification {
this.bar = bar
this.baz = baz
}
+ }
+ @EqualsAndHashCode(includes = "id")
+ @ToString(includeNames = true)
+ class AnonFactWithId {
+ String id
+ String foo
- @Override
- String toString() {
- return getClass().getSimpleName() + "{" +
- "foo='" + foo + '\'' +
- ", bar=" + bar +
- ", baz=" + baz +
- '}'
+ AnonFactWithId(String id, String foo) {
+ this.id = id
+ this.foo = foo
}
}
@@ -155,6 +160,130 @@ class BasicRulesFactsTest extends Specification {
assert rulesFacts.anonymousFacts.size() == 2
}
+ def "Handle anonymous facts with value equality"() {
+
+ when: "some anonymous facts are added"
+ rulesFacts.put(new AnonFact("NOID1", 1, true))
+ rulesFacts.put(new AnonFact("NOID2", 2, true))
+ rulesFacts.put(new AnonFactWithId("ONE", "FOO1"))
+ rulesFacts.put(new AnonFactWithId("ONE", "FOO2"))
+ rulesFacts.put(new AnonFactWithId("ONE", "FOO3"))
+ rulesFacts.put(new AnonFactWithId("TWO", "BAR"))
+ rulesFacts.put(new AnonFactWithId("THREE", "BAZ"))
+
+ then: "facts should be present"
+ assert rulesFacts.allFacts.count() == 5
+ assert rulesFacts.assetStates.size() == 0
+ assert rulesFacts.assetEvents.size() == 0
+ assert rulesFacts.namedFacts.size() == 0
+ assert rulesFacts.anonymousFacts.size() == 5
+ assert rulesFacts.vars.size() == 0
+ assert !rulesFacts.hasTemporaryFacts()
+
+ and: "matching should succeed"
+ assert rulesFacts.match(AnonFact).count() == 2
+ assert rulesFacts.match(AnonFactWithId).count() == 3
+ assert rulesFacts.match(AnonFactWithId, { it.foo == "FOO3"}).count() == 1
+ assert rulesFacts.matchFirst(AnonFactWithId, { it.foo == "FOO3"}).isPresent()
+
+ when: "an anonymous fact is updated"
+ rulesFacts.put(new AnonFactWithId("ONE", "FOO4"))
+
+ then: "updated facts should be present"
+ assert rulesFacts.allFacts.count() == 5
+ assert rulesFacts.assetStates.size() == 0
+ assert rulesFacts.assetEvents.size() == 0
+ assert rulesFacts.namedFacts.size() == 0
+ assert rulesFacts.anonymousFacts.size() == 5
+ assert rulesFacts.vars.size() == 0
+ assert !rulesFacts.hasTemporaryFacts()
+
+ and: "matching should succeed"
+ assert rulesFacts.match(AnonFact).count() == 2
+ assert rulesFacts.match(AnonFactWithId).count() == 3
+ assert rulesFacts.match(AnonFactWithId, { it.foo == "FOO3"}).count() == 0
+ assert !rulesFacts.matchFirst(AnonFactWithId, { it.foo == "FOO3"}).isPresent()
+ assert rulesFacts.match(AnonFactWithId, { it.foo == "FOO4"}).count() == 1
+ assert rulesFacts.matchFirst(AnonFactWithId, { it.foo == "FOO4"}).isPresent()
+
+ when: "an anonymous fact is removed"
+ rulesFacts.remove(new AnonFactWithId("ONE", "whatever"))
+
+ then: "the fact should be removed"
+ assert rulesFacts.match(AnonFact).count() == 2
+ assert rulesFacts.match(AnonFactWithId).count() == 2
+ assert rulesFacts.match(AnonFactWithId, { it.foo == "FOO4"}).count() == 0
+ assert !rulesFacts.matchFirst(AnonFactWithId, { it.foo == "FOO4"}).isPresent()
+ assert rulesFacts.anonymousFacts.size() == 4
+ }
+
+ def "Handle anonymous and named facts of same type"() {
+
+ when: "some anonymous and named facts are added"
+
+ def fact1 = new AnonFactWithId("ONE", "FOO")
+ def fact2 = new AnonFactWithId("TWO", "BAR")
+ def fact3 = new AnonFactWithId("THREE", "BAZ")
+ rulesFacts.put(fact1)
+ rulesFacts.put(fact2)
+ rulesFacts.put(fact3)
+ rulesFacts.put("Anon-$fact1.foo", fact1)
+ rulesFacts.put("Anon-$fact2.foo", fact2)
+ rulesFacts.put("Anon-$fact3.foo", fact3)
+
+ then: "facts should be present"
+ assert rulesFacts.allFacts.count() == 6
+ assert rulesFacts.assetStates.size() == 0
+ assert rulesFacts.assetEvents.size() == 0
+ assert rulesFacts.namedFacts.size() == 3
+ assert rulesFacts.anonymousFacts.size() == 3
+ assert rulesFacts.vars.size() == 0
+ assert !rulesFacts.hasTemporaryFacts()
+
+ and: "matching should succeed"
+ assert rulesFacts.match(AnonFactWithId).count() == 6
+ assert rulesFacts.match(AnonFactWithId, { it.foo == "FOO"}).count() == 2
+ assert rulesFacts.matchFirst(AnonFactWithId, { it.foo == "FOO"}).isPresent()
+
+ when: "an anonymous fact is updated"
+ rulesFacts.put(new AnonFactWithId("ONE", "NEW"))
+
+ then: "updated facts should be present"
+ assert rulesFacts.allFacts.count() == 6
+ assert rulesFacts.assetStates.size() == 0
+ assert rulesFacts.assetEvents.size() == 0
+ assert rulesFacts.namedFacts.size() == 3
+ assert rulesFacts.anonymousFacts.size() == 3
+ assert rulesFacts.vars.size() == 0
+ assert !rulesFacts.hasTemporaryFacts()
+
+ and: "matching should succeed"
+ assert rulesFacts.match(AnonFactWithId).count() == 6
+ assert rulesFacts.match(AnonFactWithId, { it.foo == "FOO"}).count() == 1
+ assert rulesFacts.matchFirst(AnonFactWithId, { it.foo == "FOO"}).isPresent()
+ assert rulesFacts.match(AnonFactWithId, { it.foo == "NEW"}).count() == 1
+ assert rulesFacts.matchFirst(AnonFactWithId, { it.foo == "NEW"}).isPresent()
+
+ when: "an anonymous fact is removed"
+ rulesFacts.remove(new AnonFactWithId("ONE", "whatever"))
+
+ then: "updated facts should be present"
+ assert rulesFacts.allFacts.count() == 5
+ assert rulesFacts.assetStates.size() == 0
+ assert rulesFacts.assetEvents.size() == 0
+ assert rulesFacts.namedFacts.size() == 3
+ assert rulesFacts.anonymousFacts.size() == 2
+ assert rulesFacts.vars.size() == 0
+ assert !rulesFacts.hasTemporaryFacts()
+
+ then: "the fact should be removed"
+ assert rulesFacts.match(AnonFactWithId).count() == 5
+ assert rulesFacts.match(AnonFactWithId, { it.foo == "FOO"}).count() == 1
+ assert rulesFacts.matchFirst(AnonFactWithId, { it.foo == "FOO"}).isPresent()
+ assert rulesFacts.match(AnonFactWithId, { it.foo == "NEW"}).count() == 0
+ assert !rulesFacts.matchFirst(AnonFactWithId, { it.foo == "NEW"}).isPresent()
+ }
+
def "Handle temporary named facts"() {
when: "some temporary facts are added"