tkobayas opened a new issue, #6911:
URL: https://github.com/apache/incubator-kie/issues/6911

   ## 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:
   
   ```java
   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
   
   ```java
   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](https://github.com/apache/incubator-kie/issues/6235)). 
The `timer` attribute is supported in the DSL, but cannot be fully tested with 
pseudo clock due to this issue.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to