Problem
When creating a RuleUnitInstance from a RuleUnitDefinition (Java DSL) with a RuleConfig that sets ClockType.PSEUDO, the pseudo clock is not applied. The session still uses the default JDKTimerService (realtime clock), causing unitInstance.getClock() to fail with a ClassCastException when cast to SessionPseudoClock.
Root Cause
In RuleUnitProviderForDSL.ModelRuleUnit.internalCreateInstance(), the RuleUnitExecutorImpl is created before the RuleConfig clock type can be merged into the session configuration:
public RuleUnitInstance<T> internalCreateInstance(T data, RuleConfig ruleConfig) {
ReteEvaluator reteEvaluator = new RuleUnitExecutorImpl(ruleBase); // uses default REALTIME clock
return new DSLRuleUnitInstance<>(this, data, reteEvaluator, unitGlobalsResolver, ruleConfig);
}
The DRL-based RuleUnit path handles this via RuleConfigImpl.mergeSessionConfiguration() which is called before the executor is created. The DSL path should do the same.
Expected Behavior
RuleConfig ruleConfig = RuleUnitProvider.get().newRuleConfig();
ruleConfig.setClockType(ClockType.PSEUDO);
try (RuleUnitInstance<MyUnit> unitInstance = RuleUnitProvider.get().createRuleUnitInstance(unit, ruleConfig)) {
SessionPseudoClock clock = unitInstance.getClock(); // should work
clock.advanceTime(40L, TimeUnit.MINUTES);
unitInstance.fire(); // timer rules should fire after advancing
}
Actual Behavior
java.lang.ClassCastException: class org.drools.core.time.impl.JDKTimerService cannot be cast to class org.kie.api.time.SessionPseudoClock
Context
Discovered while implementing rule attribute support for RuleUnit DSL (incubator-kie#6235). The timer attribute is supported in the DSL, but cannot be fully tested with pseudo clock due to this issue.
Problem
When creating a
RuleUnitInstancefrom aRuleUnitDefinition(Java DSL) with aRuleConfigthat setsClockType.PSEUDO, the pseudo clock is not applied. The session still uses the defaultJDKTimerService(realtime clock), causingunitInstance.getClock()to fail with aClassCastExceptionwhen cast toSessionPseudoClock.Root Cause
In
RuleUnitProviderForDSL.ModelRuleUnit.internalCreateInstance(), theRuleUnitExecutorImplis created before theRuleConfigclock type can be merged into the session configuration:The DRL-based RuleUnit path handles this via
RuleConfigImpl.mergeSessionConfiguration()which is called before the executor is created. The DSL path should do the same.Expected Behavior
Actual Behavior
Context
Discovered while implementing rule attribute support for RuleUnit DSL (incubator-kie#6235). The
timerattribute is supported in the DSL, but cannot be fully tested with pseudo clock due to this issue.