Skip to content

Commit

Permalink
Introduce fully manual pseudoclock opt (no auto advance) (#70)
Browse files Browse the repository at this point in the history
When the option is set, there is no automatic advance of the internal pseudoclock.
This option is intended for use in testing
(avoid during debug session for the pseudoclock to diverge
because of the default automatic advancements)
  • Loading branch information
tarilabs authored Aug 1, 2023
1 parent 408a112 commit e21a53d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
public enum RuleConfigurationOption {
EVENTS_PROCESSING,
USE_PSEUDO_CLOCK,
/**
* When this option is set, there is no automatic advance of the internal pseudoclock.
* This option is intended for use in testing
* (avoid during debug session for the pseudoclock to diverge
* because of the default automatic advancements)
*/
FULLY_MANUAL_PSEUDOCLOCK,
ASYNC_EVALUATION
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.KieSessionConfiguration;
import org.kie.api.runtime.conf.ClockTypeOption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

import static org.drools.ansible.rulebook.integration.api.RuleConfigurationOption.*;

public class RulesExecutorFactory {
private static final Logger LOG = LoggerFactory.getLogger(RulesExecutorFactory.class);

private static final AtomicLong ID_GENERATOR = new AtomicLong(1);

Expand Down Expand Up @@ -47,10 +50,14 @@ private static RulesExecutor create(RuleFormat format, RuleNotation notation, St

public static RulesExecutor createRulesExecutor(RulesSet rulesSet) {
RulesExecutor rulesExecutor = new RulesExecutor(createRulesExecutorSession(rulesSet), rulesSet.hasOption(ASYNC_EVALUATION));
if (rulesSet.getClockPeriod() != null) {
rulesExecutor.startAutomaticPseudoClock(rulesSet.getClockPeriod().getAmount(), rulesSet.getClockPeriod().getTimeUnit());
if (!rulesSet.hasOption(FULLY_MANUAL_PSEUDOCLOCK)) {
if (rulesSet.getClockPeriod() != null) {
rulesExecutor.startAutomaticPseudoClock(rulesSet.getClockPeriod().getAmount(), rulesSet.getClockPeriod().getTimeUnit());
} else {
rulesExecutor.startAutomaticPseudoClock(DEFAULT_AUTOMATIC_TICK_PERIOD_IN_MILLIS, TimeUnit.MILLISECONDS);
}
} else {
rulesExecutor.startAutomaticPseudoClock(DEFAULT_AUTOMATIC_TICK_PERIOD_IN_MILLIS, TimeUnit.MILLISECONDS);
LOG.info("No automatic advance of internal pseudo-clock since option {} was detected", FULLY_MANUAL_PSEUDOCLOCK);
}
return rulesExecutor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public void test57_once_after_multiple() {
"]\n" + //
"}";

RulesExecutor rulesExecutor = RulesExecutorFactory.createFromJson(RuleNotation.CoreNotation.INSTANCE.withOptions(RuleConfigurationOption.USE_PSEUDO_CLOCK), RULES);
RulesExecutor rulesExecutor = RulesExecutorFactory.createFromJson(RuleNotation.CoreNotation.INSTANCE.withOptions(RuleConfigurationOption.FULLY_MANUAL_PSEUDOCLOCK), RULES);
List<Match> matchedRules;

source_generic_loop57(rulesExecutor);
Expand Down

0 comments on commit e21a53d

Please sign in to comment.