Package org.drools.core

Examples of org.drools.core.WorkingMemory


        str += "    'good bye', new java.util.ArrayList();\n";

        NodeTestResult result = executeTest( str );
        Map<String, Object> map = result.context;

        WorkingMemory wm = (WorkingMemory) map.get( "WorkingMemory" );
        List<InternalFactHandle> handles = (List<InternalFactHandle>) map.get( "Handles" );

        assertNotNull( wm );
        assertNotNull( handles );
View Full Code Here


        str += "    h4, add( 2 );\n";

        NodeTestResult result = executeTest( str );
        Map<String, Object> map = result.context;

        WorkingMemory wm = (WorkingMemory) map.get( "WorkingMemory" );
        List<InternalFactHandle> handles = (List<InternalFactHandle>) map.get( "Handles" );

        assertNotNull( wm );
        assertNotNull( handles );
View Full Code Here

public class RuleTest {

    @Test
    public void testDateEffective() {
        WorkingMemory wm = new ReteooRuleBase("x", null).newStatefulSession();

        final Rule rule = new Rule( "myrule" );

        assertTrue( rule.isEffective(null, new RuleTerminalNode(), wm ) );
View Full Code Here

    }

    @Test
    public void testDateExpires() throws Exception {
        WorkingMemory wm = new ReteooRuleBase("x", null).newStatefulSession();
       
        final Rule rule = new Rule( "myrule" );

        assertTrue( rule.isEffective(null, new RuleTerminalNode(), wm ) );
View Full Code Here

    }

    @Test
    public void testDateEffectiveExpires() {
        WorkingMemory wm = new ReteooRuleBase("x",null).newStatefulSession();
       
        final Rule rule = new Rule( "myrule" );

        final Calendar past = Calendar.getInstance();
        past.setTimeInMillis( 10 );
View Full Code Here

    }

    @Test
    public void testRuleEnabled() {
        WorkingMemory wm = new ReteooRuleBase("x", null).newStatefulSession();
       
        final Rule rule = new Rule( "myrule" );
        rule.setEnabled( EnabledBoolean.ENABLED_FALSE );
        assertFalse( rule.isEffective( null, new RuleTerminalNode(), wm ) );
View Full Code Here

    @Test
    public void testTimeMachine() {
        SessionConfiguration conf = new SessionConfiguration();
        conf.setClockType( ClockType.PSEUDO_CLOCK );
        WorkingMemory wm = new ReteooRuleBase("x", null).newStatefulSession(conf, null);
       
        final Calendar future = Calendar.getInstance();
        ((PseudoClockScheduler)wm.getSessionClock()).setStartupTime( future.getTimeInMillis() );
       
        final Rule rule = new Rule( "myrule" );
        rule.setEnabled( EnabledBoolean.ENABLED_TRUE );
        assertTrue( rule.isEffective(null, new RuleTerminalNode(), wm ) );

       
        future.setTimeInMillis( future.getTimeInMillis() + 100000000 );
        rule.setDateEffective(future);
        assertFalse( rule.isEffective(null, new RuleTerminalNode(), wm ) );

        ((PseudoClockScheduler)wm.getSessionClock()).advanceTime( 1000000000000L, TimeUnit.MILLISECONDS );
       
        assertTrue(rule.isEffective(null, new RuleTerminalNode(), wm ));
    }
View Full Code Here

    @Test
    public void testManners() throws Exception {

        final RuleBase ruleBase = RuleBaseFactory.newRuleBase( RuleBase.RETEOO );
        ruleBase.addPackage( this.pkg );
        final WorkingMemory workingMemory = ruleBase.newStatefulSession();

        final DefaultAgendaEventListener listener = new DefaultAgendaEventListener() {
            private int counter = 0;

            //           public void matchCreated(ActivationCreatedEvent event) {
            //                super.matchCreated( event );
            //                System.out.println( event );
            //            }
            //          
            //           public void matchCancelled(ActivationCancelledEvent event) {
            //               super.matchCancelled( event );
            //               System.out.println( event );
            //           }
            //          
            //           public void beforeMatchFired(BeforeActivationFiredEvent event) {
            //               super.beforeMatchFired( event );
            //               System.out.println( event );
            //           }

            public void afterActivationFired(AfterActivationFiredEvent event) {
                this.counter++;
                //super.afterMatchFired( event );
                //System.out.println( event );
            }

            public String toString() {
                return "fired :  " + this.counter;
            }

        };

        //workingMemory.addEventListener(listener );
        final InputStream is = getClass().getResourceAsStream( "/manners5.dat" );
        final List list = getInputObjects( is );
        for ( final Iterator it = list.iterator(); it.hasNext(); ) {
            final Object object = it.next();
            workingMemory.insert( object );
        }

        workingMemory.insert( new Count( 1 ) );

        final long start = System.currentTimeMillis();
        workingMemory.fireAllRules();
//        System.err.println( System.currentTimeMillis() - start );

        //System.out.println( listener );

        //        while  (1==1){
View Full Code Here

        final Package pkg = builder.getPackage();

        RuleBase ruleBase = getRuleBase();
        ruleBase.addPackage( pkg );
        ruleBase = SerializationHelper.serializeObject(ruleBase);
        final WorkingMemory workingMemory = ruleBase.newStatefulSession();

        workingMemory.insert( new Cheese( "stilton",
                                          1 ) );

        workingMemory.fireAllRules( 3000000 );

        // just for profiling
        //Thread.currentThread().wait();
    }
View Full Code Here

    @Test
    public void testEventGenerationMaxItems() throws DroolsParserException, IOException, Exception{
        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( TEST_RULE_FILE ) );
        final RuleBase ruleBase = loadRuleBase( reader );
        final WorkingMemory wm = ruleBase.newStatefulSession();
        final SimpleEventGenerator myGenerator;

        // create unrestricted event generator
        myGenerator = new SimpleEventGenerator(wm , new SimpleEventListener(wm));
        // generate 10 events, starting from the session clock
        myGenerator.addEventSource("Conveyor1", new Event(EventType.CUSTOM, null), PseudoSessionClock.timeInSeconds(4), PseudoSessionClock.timeInSeconds(6), 0, 10);
        myGenerator.generate();
        assertEquals(wm.getQueryResults("all inserted events").size(), 10);
    }
View Full Code Here

TOP

Related Classes of org.drools.core.WorkingMemory

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.