Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

341: Fix Validation Rule Engine concurrency issues #997

Merged
merged 8 commits into from
Apr 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void unloadRules() {
rules.clear();
}

public void ensureRulesLoaded() {
public synchronized void ensureRulesLoaded() {
luis-pabon-tf marked this conversation as resolved.
Show resolved Hide resolved
if (rules.isEmpty()) {
loadRules();
}
Expand Down
2 changes: 1 addition & 1 deletion etor/src/main/resources/rule_definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"violationMessage": "Message doesn't have required receiver id",
"conditions": [ ],
"validations": [
"Bundle.entry.resource.ofType(MessageHeader).destination.receiver.resolve().identifier.value.exists()"
"Bundle.entry.resource.ofType(MessageHeader).destination.receiver.resolve().identifier.where(system = 'urn:ietf:rfc:3986').value.exists()"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,27 @@ class RuleEngineTest extends Specification {
1 * mockRuleLoader.loadRules(_ as String) >> [Mock(Rule)]
}

def "ensureRulesLoaded loads rules only once on multiple threads"() {
given:
def threadsNum = 2
basiliskus marked this conversation as resolved.
Show resolved Hide resolved
def iterations = 4

when:
List<Thread> threads = []
(1..threadsNum).each { threadId ->
threads.add(new Thread({
for (int i = 0; i < iterations; i++) {
ruleEngine.ensureRulesLoaded()
}
}))
}
threads*.start()
threads*.join()

then:
1 * mockRuleLoader.loadRules(_ as String) >> [Mock(Rule)]
}

def "ensureRulesLoaded logs an error if there is an exception loading the rules"() {
given:
def exception = new RuleLoaderException("Error loading rules", new Exception())
Expand Down
Loading