Package org.drools.time.impl

Examples of org.drools.time.impl.PseudoClockScheduler


        KnowledgeSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
        conf.setOption( ClockTypeOption.get( "pseudo" ) );
       
        List list = new ArrayList();
        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession( conf, null );
        PseudoClockScheduler timeService = ( PseudoClockScheduler ) ksession.getSessionClock();
        DateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
        Date date = df.parse( "2009-01-01T00:00:00.000-0000" );
       
        timeService.advanceTime( date.getTime(), TimeUnit.MILLISECONDS );
       
        ksession.setGlobal( "list", list );
 
        ksession.fireAllRules();
        assertEquals( 0, list.size() );
               
        timeService.advanceTime( 10, TimeUnit.SECONDS );
        ksession.fireAllRules();
        assertEquals( 0, list.size() );
                
        timeService.advanceTime( 10, TimeUnit.SECONDS );
        ksession.fireAllRules();
        assertEquals( 1, list.size() );
       
        timeService.advanceTime( 30, TimeUnit.SECONDS );
        ksession.fireAllRules();
        assertEquals( 1, list.size() );
       
        timeService.advanceTime( 30, TimeUnit.SECONDS );
        ksession.fireAllRules();
        assertEquals( 2, list.size() );
    }
View Full Code Here


        KnowledgeSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
        conf.setOption( ClockTypeOption.get( "pseudo" ) );
       
        List list = new ArrayList();
        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession( conf, null );
        PseudoClockScheduler timeService = ( PseudoClockScheduler ) ksession.getSessionClock();
        DateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
        Date date = df.parse( "2009-01-01T00:00:00.000-0000" );
       
        ksession.getCalendars().set( "cal1", calTrue );
       
        timeService.advanceTime( date.getTime(), TimeUnit.MILLISECONDS );
        ksession.setGlobal( "list", list );
        ksession.insert( "o1" );
        ksession.fireAllRules();
        assertEquals( 1, list.size() );
               
        timeService.advanceTime( 10, TimeUnit.SECONDS );
        ksession.insert( "o2" );
        ksession.fireAllRules();
        assertEquals( 2, list.size() );
       
        ksession.getCalendars().set( "cal1", calFalse );
        timeService.advanceTime( 10, TimeUnit.SECONDS );
        ksession.insert( "o3" );
        ksession.fireAllRules();
        assertEquals( 2, list.size() );
       
        ksession.getCalendars().set( "cal1", calTrue );
        timeService.advanceTime( 30, TimeUnit.SECONDS );
        ksession.insert( "o4" );
        ksession.fireAllRules();
        assertEquals( 3, list.size() );
    }
View Full Code Here

            DefaultAgenda agenda,
            long time,
            boolean multithread,
            MarshallerReaderContext context ) throws IOException, ClassNotFoundException {
        if (session.getTimerService() instanceof PseudoClockScheduler) {
            PseudoClockScheduler clock = (PseudoClockScheduler) session.getTimerService();
            clock.advanceTime( time,
                               TimeUnit.MILLISECONDS );
        }

        // RuleFlowGroups need to reference the session
        for (RuleFlowGroup group : agenda.getRuleFlowGroupsMap().values()) {
View Full Code Here

                                                                               null );

        WorkingMemoryEventListener wml = mock( WorkingMemoryEventListener.class );
        ksession.addEventListener( wml );

        PseudoClockScheduler clock = ksession.getSessionClock();

        final StockTickInterface st1 = new StockTick( 1,
                                             "RHT",
                                             100,
                                             1000 );
        final StockTickInterface st2 = new StockTick( 2,
                                             "RHT",
                                             100,
                                             1000 );

        ksession.insert( st1 );
        ksession.insert( st2 );

        verify( wml,
                times( 2 ) ).objectInserted( any( org.drools.event.rule.ObjectInsertedEvent.class ) );
        assertThat( ksession.getObjects().size(),
                    equalTo( 2 ) );
        assertThat( ksession.getObjects(),
                    hasItems( (Object) st1,
                              st2 ) );

        ksession.fireAllRules();

        clock.advanceTime( 3,
                           TimeUnit.SECONDS );
        ksession.fireAllRules();

        assertThat( ksession.getObjects().size(),
                    equalTo( 0 ) );
View Full Code Here

        WorkingMemoryEventListener wml = mock( WorkingMemoryEventListener.class );
        ksession.addEventListener( wml );
        AgendaEventListener ael = mock( AgendaEventListener.class );
        ksession.addEventListener( ael );

        PseudoClockScheduler clock = ksession.getSessionClock();

        final StockTickInterface st1 = new StockTick( 1,
                                             "RHT",
                                             100,
                                             1000 );
        final StockTickInterface st2 = new StockTick( 2,
                                             "RHT",
                                             100,
                                             1000 );

        ksession.insert( st1 );
        ksession.insert( st2 );

        verify( wml,
                times( 2 ) ).objectInserted( any( org.drools.event.rule.ObjectInsertedEvent.class ) );
        verify( ael,
                times( 2 ) ).activationCreated( any( ActivationCreatedEvent.class ) );
        assertThat( ksession.getObjects().size(),
                    equalTo( 2 ) );
        assertThat( ksession.getObjects(),
                    hasItems( (Object) st1,
                              st2 ) );

        int fired = ksession.fireAllRules();

        assertThat( fired,
                    equalTo( 2 ) );

        clock.advanceTime( 3,
                           TimeUnit.SECONDS );
        ksession.fireAllRules();

        assertThat( ksession.getObjects().size(),
                    equalTo( 0 ) );
View Full Code Here

        if( globalResolver != null ) {
            session.setGlobalResolver( globalResolver );
        }

        if ( session.getTimerService() instanceof PseudoClockScheduler ) {
            PseudoClockScheduler clock = (PseudoClockScheduler) session.getTimerService();
            clock.advanceTime( _session.getTime(),
                               TimeUnit.MILLISECONDS );
        }

        // RuleFlowGroups need to reference the session
        for ( RuleFlowGroup group : agenda.getRuleFlowGroupsMap().values() ) {
View Full Code Here

       
        knowledgeBase.addKnowledgePackages(Collections.singleton((KnowledgePackage) impl));
        SessionConfiguration config = new SessionConfiguration();
        config.setClockType(ClockType.PSEUDO_CLOCK);
        StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession(config, KnowledgeBaseFactory.newEnvironment());
        PseudoClockScheduler scheduler = ksession.getSessionClock();
        Marshaller marshaller = MarshallerFactory.newMarshaller(knowledgeBase);
       


        ksession.insert("cheese");
        assertTrue(fired.isEmpty());
        //marshall, then unmarshall session
        readWrite(knowledgeBase, ksession, config);
        //the activations should fire after 10 seconds
        assertTrue(fired.isEmpty());
        scheduler.advanceTime(12, TimeUnit.SECONDS);
        assertFalse(fired.isEmpty());

    }
View Full Code Here

                return it.next();
            }
        });
       
        // create the scheduler used by drools and the feeder to be tested
        PseudoClockScheduler clock = new PseudoClockScheduler();
        EventFeeder feeder = new EventFeeder( clock,
                                              source,
                                              receiver );

        feeder.feed();
        // advancing time step by step, so that we can test state between advances
        for( Event<?> event : events ) {
            clock.advanceTime( event.getTimestamp() - clock.getCurrentTime(),
                               TimeUnit.MILLISECONDS );
        }

        verify( source, times(7) ).hasNext();
        verify( source, times(6) ).getNext();
View Full Code Here

            DefaultAgenda agenda,
            long time,
            boolean multithread,
            MarshallerReaderContext context ) throws IOException, ClassNotFoundException {
        if (session.getTimerService() instanceof PseudoClockScheduler) {
            PseudoClockScheduler clock = (PseudoClockScheduler) session.getTimerService();
            clock.advanceTime( time,
                               TimeUnit.MILLISECONDS );
        }

        // RuleFlowGroups need to reference the session
        for (RuleFlowGroup group : agenda.getRuleFlowGroupsMap().values()) {
View Full Code Here

        if( globalResolver != null ) {
            session.setGlobalResolver( globalResolver );
        }

        if ( session.getTimerService() instanceof PseudoClockScheduler ) {
            PseudoClockScheduler clock = (PseudoClockScheduler) session.getTimerService();
            clock.advanceTime( _session.getTime(),
                               TimeUnit.MILLISECONDS );
        }

        // RuleFlowGroups need to reference the session
        for ( RuleFlowGroup group : agenda.getRuleFlowGroupsMap().values() ) {
View Full Code Here

TOP

Related Classes of org.drools.time.impl.PseudoClockScheduler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.