[jboss-jira] [JBoss JIRA] (DROOLS-795) Timers are reset during the serialization process

David Weir (JIRA) issues at jboss.org
Wed Nov 11 15:25:00 EST 2015


    [ https://issues.jboss.org/browse/DROOLS-795?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13127960#comment-13127960 ] 

David Weir commented on DROOLS-795:
-----------------------------------

This is still broken on 6.3.0 Final if you use a realtime clock, not pseudo clock

> 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
>             Fix For: 6.3.0.CR1
>
>
> 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.4.11#64026)


More information about the jboss-jira mailing list