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

[DROOLS-7571] SessionStats eventsMatched isn't correctly calculated i… #87

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RegisterOnlyAgendaFilter implements AgendaFilter {

private final Set<Match> matchedRules = new LinkedHashSet<>();

private final Set<FactHandle> eventsToBeDeleted = Collections.newSetFromMap(new IdentityHashMap<>());
private final Set<FactHandle> matchedEvents = Collections.newSetFromMap(new IdentityHashMap<>());

public RegisterOnlyAgendaFilter(RulesExecutorSession rulesExecutorSession) {
this.rulesExecutorSession = rulesExecutorSession;
Expand All @@ -55,23 +55,23 @@ public boolean accept(Match match) {
matchedRules.add( matchTransformers.getOrDefault(metadata.get(RULE_TYPE_TAG), Function.identity()).apply(match) );
}

if (!rulesExecutorSession.isMatchMultipleRules()) {
for (InternalFactHandle fh : fhs) {
if (fh.isEvent()) {
eventsToBeDeleted.add(fh);
}
for (InternalFactHandle fh : fhs) {
if (fh.isEvent()) {
matchedEvents.add(fh);
}
}

return validMatch;
}

public List<Match> finalizeAndGetResults(boolean event) {
rulesExecutorSession.registerMatchedEvents(eventsToBeDeleted);
for (FactHandle toBeDeleted : eventsToBeDeleted) {
rulesExecutorSession.delete(toBeDeleted);
rulesExecutorSession.registerMatchedEvents(matchedEvents);
if (!rulesExecutorSession.isMatchMultipleRules()) {
for (FactHandle toBeDeleted : matchedEvents) {
rulesExecutorSession.delete(toBeDeleted);
}
}
eventsToBeDeleted.clear();
matchedEvents.clear();

List<Match> matches = new ArrayList<>( matchedRules );
matchedRules.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package org.drools.ansible.rulebook.integration.api;

import org.drools.ansible.rulebook.integration.api.rulesengine.SessionStats;
import org.junit.Test;
import org.kie.api.runtime.rule.Match;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;

public class MultipleRuleMatchTest {

Expand Down Expand Up @@ -126,6 +128,12 @@ public void processEventsWithMatchMultipleRules_shouldMatchMultipleRules() {
assertThat(matchedRules).hasSize(2);
assertThat(matchedRules.stream().map(m -> m.getRule().getName())).contains("R1", "R2");

SessionStats stats = rulesExecutor.getSessionStats();
assertEquals(2, stats.getRulesTriggered());
assertEquals(1, stats.getEventsProcessed());
assertEquals(1, stats.getEventsMatched());
assertEquals(0, stats.getEventsSuppressed());

rulesExecutor.dispose();
}

Expand Down
Loading