[jboss-jira] [JBoss JIRA] (DROOLS-795) Timers are reset during the serialization process
Mario Fusco (JIRA)
issues at jboss.org
Wed May 27 10:29:02 EDT 2015
Mario Fusco created DROOLS-795:
----------------------------------
Summary: Timers are reset during the serialization process
Key: DROOLS-795
URL: https://issues.jboss.org/browse/DROOLS-795
Project: Drools
Issue Type: Bug
Reporter: Mario Fusco
Assignee: Mario Fusco
When the marshall serializes a timer it doesn't take count of how much time it is already passed, so when the timer is deserialized it restart from it start time. The following failing test case reproduces the problem.
{code}
@Test
public void testMarshallWithTimedRule() {
String drl = "rule \"Rule A Timeout\"\n" +
"when\n" +
" String( this == \"ATrigger\" )\n" +
"then\n" +
" insert (new String( \"A-Timer\") );\n" +
"System.out.println(\"+++++++Got ATrigger, started A-Timer with 5s timeout\");\n" +
"end\n" +
"\n" +
"rule \"Timer For rule A Timeout\"\n" +
" timer ( int: 5s )\n" +
"when\n" +
" String( this == \"A-Timer\")\n" +
"then\n" +
" delete ( \"A-Timer\" );\n" +
" delete ( \"ATrigger\" );\n" +
"System.out.println(\"******* reset rule A based on timer\");\n" +
"end\n";
KieBase kbase = new KieHelper().addContent( drl, ResourceType.DRL )
.build( EqualityBehaviorOption.EQUALITY,
DeclarativeAgendaOption.ENABLED,
EventProcessingOption.STREAM );
KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sessionConfig.setOption( ClockTypeOption.get( "pseudo" ) );
KieSession ksession = kbase.newKieSession(sessionConfig, null);
ksession.insert( new String( "ATrigger" ) );
assertEquals( 1, ksession.getFactCount() );
ksession.fireAllRules();
assertEquals( 2, ksession.getFactCount() );
SessionPseudoClock clock = ksession.getSessionClock();
clock.advanceTime( 4, TimeUnit.SECONDS );
assertEquals( 2, ksession.getFactCount() );
ksession.fireAllRules();
assertEquals( 2, ksession.getFactCount() );
ksession = marshallAndUnmarshall( kbase, ksession, sessionConfig);
clock = ksession.getSessionClock();
clock.advanceTime( 4, TimeUnit.SECONDS );
assertEquals( 2, ksession.getFactCount() );
ksession.fireAllRules();
assertEquals( 0, ksession.getFactCount() );
}
public static KieSession marshallAndUnmarshall(KieBase kbase, KieSession ksession, KieSessionConfiguration sessionConfig) {
// Serialize and Deserialize
try {
Marshaller marshaller = KieServices.Factory.get().getMarshallers().newMarshaller(kbase);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
marshaller.marshall(baos, ksession);
marshaller = MarshallerFactory.newMarshaller( kbase );
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
baos.close();
ksession = marshaller.unmarshall(bais, sessionConfig, null);
bais.close();
} catch (Exception e) {
e.printStackTrace();
fail("unexpected exception :" + e.getMessage());
}
return ksession;
}
{code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
More information about the jboss-jira
mailing list