-
Task
-
Resolution: Done
-
Major
-
None
-
None
When we detect score corruption as a bug in Drools, such as DROOLS-1174, we (Mario, JiriL and Geoffrey) need to end up with a Drools only unit test reproducer. For this purpose, what we do know is: first we isolate (JiriL) in OptaPlanner and the Mario trial-and-errors to reproduce in a pure drools unit test. We need to automate this more, as it happened 34 times already and will happen again.
Automating the isolation itself is non-trivial and not in the scope of this issue. Here, we want to automate the isolated OptaPlanner reproducer into a Drools unit test, which can be done this way:
public class DroolsScoreDirector ... { // class in OptaPlanner private final boolean generateDroolsUnitTest = false; // New flag protected KieSession kieSession; ... public Score calculateScore() { variableListenerSupport.assertNotificationQueuesAreEmpty(); if (generateDroolsUnitTest) { System.out.println("kieSession.fireAllRules();"); } kieSession.fireAllRules(); ... } private void update(Object entity) { if (generateDroolsUnitTest) { System.out.println("FactHandle factHandle = kieSession.getFactHandle(" + entity + ");"); System.out.println("kieSession.update(factHandle, " + entity + ");"); } FactHandle factHandle = kieSession.getFactHandle(entity); ... kieSession.update(factHandle, entity); } @Override public void afterVariableChanged(VariableDescriptor variableDescriptor, Object entity) { System.out.println(entity + ".set"+ variableDescriptor.getVariableName().makeFirstCharCapital() + "(" + variableDescriptor.getValue(entity) + ");"); update(entity); super.afterVariableChanged(variableDescriptor, entity); } }
If we then make all the domain entity's toString() return their variable name, we can use this to generate a Drools unit test.
Pitfall: during FAST/FULL_ASSERT with no assertionScoreDirectorFactory (which for example overwrites the from scratch assertions to use an EasyScorecalculator), there will be multiple DroolScoreDirector instances and we 'll need to make sure only the real one System.out's. That's possible.
- is caused by
-
DROOLS-1174 Bug of score corruption in dinner party examples uncovered by fix for DROOLS-1186
-
- Closed
-