Package org.drools.core.impl

Examples of org.drools.core.impl.StatefulKnowledgeSessionImpl$GlobalsAdapter


                   ((DefaultFactHandle) results[0]).getObject());
    }

    @Test
    public void testAssertObjectWithNoMatchingObjectTypeNode() {
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        final Rete rete = kBase.getRete();
        assertEquals(1,
                     rete.getObjectTypeNodes().size());

        List list = new ArrayList();

        ksession.insert(list);

        assertEquals(2,
                     rete.getObjectTypeNodes().size());
    }
View Full Code Here


    }

    @Test
    @Ignore
    public void testHierarchy() {
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        final Rete rete = kBase.getRete();
        final IdGenerator idGenerator = kBase.getReteooBuilder().getIdGenerator();

        // Attach a List ObjectTypeNode
        final ObjectTypeNode listOtn = new ObjectTypeNode(idGenerator.getNextId(),
                                                          this.entryPoint,
                                                          new ClassObjectType(List.class),
                                                          buildContext);
        listOtn.attach(buildContext);

        // Will automatically create an ArrayList ObjectTypeNode
        FactHandle handle = ksession.insert(new ArrayList());

        // Check we have three ObjectTypeNodes, List, ArrayList and InitialFactImpl
        assertEquals(3,
                     rete.getObjectTypeNodes().size());

        // double check that the List reference is the same as the one we created, i.e. engine should try and recreate it
        assertSame(listOtn,
                   rete.getObjectTypeNodes(EntryPointId.DEFAULT).get(new ClassObjectType(List.class)));

        // ArrayConf should match two ObjectTypenodes for List and ArrayList
        ClassObjectTypeConf arrayConf = (ClassObjectTypeConf) ksession.getObjectTypeConfigurationRegistry().getObjectTypeConf(this.entryPoint.getEntryPoint(), new ArrayList());
        final ObjectTypeNode arrayOtn = arrayConf.getConcreteObjectTypeNode();
        assertEquals(2,
                     arrayConf.getObjectTypeNodes().length);

        // Check it contains List and ArrayList
        List nodes = Arrays.asList(arrayConf.getObjectTypeNodes());
        assertEquals(2,
                     nodes.size());
        assertTrue(nodes.contains(arrayOtn));
        assertTrue(nodes.contains(listOtn));

        // Nodes are there, retract the fact so we can check both nodes are populated
        ksession.retract(handle);

        // Add MockSinks so we can track assertions
        final MockObjectSink listSink = new MockObjectSink();
        listOtn.addObjectSink(listSink);

        final MockObjectSink arraySink = new MockObjectSink();
        listOtn.addObjectSink(arraySink);

        ksession.insert(new ArrayList());
        assertEquals(1,
                     listSink.getAsserted().size());
        assertEquals(1,
                     arraySink.getAsserted().size());
View Full Code Here

     * All objects deleted from a RootNode must be propagated to all children
     * ObjectTypeNodes.
     */
    @Test
    public void testRetractObject() throws Exception {
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
        final Rete rete = kBase.getRete();
        final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1,
                                                                 this.entryPoint,
View Full Code Here

                   ((DefaultFactHandle) results[0]).getObject());
    }

    @Test
    public void testIsShadowed() {
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
        final Rete rete = kBase.getRete();
        final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1,
                                                                 this.entryPoint,
View Full Code Here

                               "org.drools.core.test.model.Cheese");
        RuleBaseConfiguration conf = new RuleBaseConfiguration(properties);
        InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(conf);
        buildContext = new BuildContext(kBase,
                                        kBase.getReteooBuilder().getIdGenerator());
        final StatefulKnowledgeSessionImpl workingMemory = new StatefulKnowledgeSessionImpl(1, kBase);

        // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
        final Rete rete = kBase.getRete();
        final EntryPointNode entryPoint = new EntryPointNode(0,
                                                             rete,
View Full Code Here

        // Initialise from lian
        KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
        kconf.setOption( RuleEngineOption.PHREAK );

        InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        SegmentUtilities.createSegmentMemory( liaNode, ksession );
        liaNode.assertObject((InternalFactHandle) ksession.insert("str"), context, ksession);
       

        LiaNodeMemory liaMem = (LiaNodeMemory) ksession.getNodeMemory( liaNode );
        assertEquals( 1, liaMem.getNodePosMaskBit() );
        assertEquals( 3, liaMem.getSegmentMemory().getAllLinkedMaskTest() );
       
        BetaMemory bm1 = (BetaMemory) ksession.getNodeMemory( n1 );
        assertEquals( 2, bm1.getNodePosMaskBit() );
        assertEquals( 3, bm1.getSegmentMemory().getAllLinkedMaskTest() );        
       
        // Initialise from n1    
        kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
        ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        n1.assertObject( (InternalFactHandle) ksession.insert( "str" ), context, ksession );
       

        liaMem = (LiaNodeMemory) ksession.getNodeMemory( liaNode );
        assertEquals( 1, liaMem.getNodePosMaskBit() );
        assertEquals( 3, liaMem.getSegmentMemory().getAllLinkedMaskTest() );
       
        bm1 = (BetaMemory) ksession.getNodeMemory( n1 );
        assertEquals( 2, bm1.getNodePosMaskBit() );
        assertEquals( 3, bm1.getSegmentMemory().getAllLinkedMaskTest() );          
    }
View Full Code Here

        setUp( JOIN_NODE );
        // Initialise from lian
        KieBaseConfiguration kconf = org.kie.internal.KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
        kconf.setOption( RuleEngineOption.PHREAK );
        InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        SegmentUtilities.createSegmentMemory( liaNode, ksession );
       
        InternalFactHandle fh1 = (InternalFactHandle) ksession.insert( "str1" );
        n1.assertObject( fh1, context, ksession );
       
        LiaNodeMemory liaMem = (LiaNodeMemory) ksession.getNodeMemory( liaNode );
        assertEquals( 1, liaMem.getNodePosMaskBit() );
        assertEquals( 3, liaMem.getSegmentMemory().getAllLinkedMaskTest() );
       
        BetaMemory bm1 = (BetaMemory) ksession.getNodeMemory( n1 );
        assertEquals( 2, bm1.getNodePosMaskBit() );
        assertEquals( 3, bm1.getSegmentMemory().getAllLinkedMaskTest() );    
       
        // still unlinked
        assertFalse( liaMem.getSegmentMemory().isSegmentLinked() );
       
        // now linked
        InternalFactHandle fh2 = (InternalFactHandle) ksession.insert( "str2" );
        liaNode.assertObject( fh2, context, ksession );
        assertTrue( liaMem.getSegmentMemory().isSegmentLinked() );
       
        // test unlink after one retract
        liaNode.retractLeftTuple( fh2.getFirstLeftTuple(), context, ksession );
        assertFalse( liaMem.getSegmentMemory().isSegmentLinked() );
       
        // check counter, after multiple asserts
        InternalFactHandle fh3 = (InternalFactHandle) ksession.insert( "str3" );
        InternalFactHandle fh4 = (InternalFactHandle) ksession.insert( "str4" );
        liaNode.assertObject( fh3, context, ksession );
        liaNode.assertObject( fh4, context, ksession );
       
        assertTrue( liaMem.getSegmentMemory().isSegmentLinked() );
       
View Full Code Here

        setUp( JOIN_NODE );
        // Initialise from n3
        KieBaseConfiguration kconf = org.kie.internal.KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
        kconf.setOption( RuleEngineOption.PHREAK );
        InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        createSegmentMemory(n3, ksession);

        BetaMemory bm = (BetaMemory) ksession.getNodeMemory( n1 );
        assertNull(bm.getSegmentMemory());

        bm = (BetaMemory) ksession.getNodeMemory( n3 );
        assertEquals( 1, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n4 );
        assertEquals( 2, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n5 );
        assertEquals( 4, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n6 );
        assertEquals( 8, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        // Initialise from n4      
        kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
        ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        bm = createSegmentMemory( n4, ksession );

        bm = (BetaMemory) ksession.getNodeMemory( n1 );
        assertNull( bm.getSegmentMemory() );

        bm = (BetaMemory) ksession.getNodeMemory( n3 );
        assertEquals( 1, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n4 );
        assertEquals( 2, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n5 );
        assertEquals( 4, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n6 );
        assertEquals(8, bm.getNodePosMaskBit());
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        // Initialise from n5
        kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
        ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        createSegmentMemory( n5, ksession );

        bm = (BetaMemory) ksession.getNodeMemory( n1 );
        assertNull(bm.getSegmentMemory());

        bm = (BetaMemory) ksession.getNodeMemory( n3 );
        assertEquals( 1, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n4 );
        assertEquals( 2, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n5 );
        assertEquals( 4, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n6 );
        assertEquals( 8, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        // Initialise from n6
        kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
        ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        createSegmentMemory( n6, ksession );

        bm = (BetaMemory) ksession.getNodeMemory( n1 );
        assertNull( bm.getSegmentMemory() );

        bm = (BetaMemory) ksession.getNodeMemory( n3 );
        assertEquals( 1, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n4 );
        assertEquals( 2, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n5 );
        assertEquals( 4, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );

        bm = (BetaMemory) ksession.getNodeMemory( n6 );
        assertEquals( 8, bm.getNodePosMaskBit() );
        assertEquals( 15, bm.getSegmentMemory().getAllLinkedMaskTest() );
    }
View Full Code Here

        assertEquals( JoinNode.class, n3.getClass() ); // make sure it created JoinNodes

        KieBaseConfiguration kconf = org.kie.internal.KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
        kconf.setOption( RuleEngineOption.PHREAK );
        InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        DefaultFactHandle f1 = (DefaultFactHandle) ksession.insert( "test1" );
        n3.assertObject( f1, context, ksession );

        BetaMemory bm = (BetaMemory) ksession.getNodeMemory( n3 );
        assertFalse( bm.getSegmentMemory().isSegmentLinked() );

        n4.assertObject( f1, context, ksession );
        assertFalse( bm.getSegmentMemory().isSegmentLinked() );
View Full Code Here

        assertEquals( ExistsNode.class, n3.getClass() ); // make sure it created ExistsNodes

        KieBaseConfiguration kconf = org.kie.internal.KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
        kconf.setOption( RuleEngineOption.PHREAK );
        InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
        StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl)kBase.newStatefulKnowledgeSession();

        DefaultFactHandle f1 = (DefaultFactHandle) ksession.insert( "test1" );
        n3.assertObject( f1, context, ksession );

        BetaMemory bm = (BetaMemory) ksession.getNodeMemory( n3 );
        assertFalse( bm.getSegmentMemory().isSegmentLinked() );

        n4.assertObject( f1, context, ksession );
        assertFalse( bm.getSegmentMemory().isSegmentLinked() );
View Full Code Here

TOP

Related Classes of org.drools.core.impl.StatefulKnowledgeSessionImpl$GlobalsAdapter

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.