private KieBaseConfiguration createKnowledgeBaseConfiguration(boolean shareBetaNodes) { KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption( SequentialOption.NO ); kconf.setOption( ShareAlphaNodesOption.YES ); kconf.setOption( shareBetaNodes ? ShareBetaNodesOption.YES : ShareBetaNodesOption.NO ); return kconf; }
@Test(timeout = 10000) public void testAgendaGroupSalience() { "end\n"; KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption( DeclarativeAgendaOption.ENABLED ); ksession.setGlobal( "ruleList", ruleList ); ksession.insert( "fireRules" ); ksession.fireAllRules(); assertEquals( ruleList.get( 0 ), "first" ); assertEquals( ruleList.get( 1 ), "second" ); assertEquals( ruleList.get( 2 ), "third" );
@Test public void testSequentialConfiguration() { // setting the option using the type safe method config.setOption( SequentialOption.YES ); // checking the type safe getOption() method assertEquals( SequentialOption.YES, config.getOption( SequentialOption.class ) ); // checking the string based getProperty() method assertEquals( "true", config.getProperty( SequentialOption.PROPERTY_NAME ) ); // setting the options using the string based setProperty() method config.setProperty( SequentialOption.PROPERTY_NAME, "false" ); // checking the type safe getOption() method assertEquals( SequentialOption.NO, config.getOption( SequentialOption.class ) ); // checking the string based getProperty() method assertEquals( "false", config.getProperty( SequentialOption.PROPERTY_NAME ) ); }
@Test public void testNotInStatelessSession() throws Exception { KieBaseConfiguration kbc = org.kie.internal.KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbc.setOption( RuleEngineOption.RETEOO ); kbc.setOption( SequentialOption.YES ); KnowledgeBase kbase = SerializationHelper.serializeObject( loadKnowledgeBase( kbc, "test_NotInStatelessSession.drl" ) ); StatelessKnowledgeSession session = createStatelessKnowledgeSession( kbase ); List list = new ArrayList(); session.setGlobal( "list", list ); session.execute( "not integer" ); assertEquals( "not integer", list.get( 0 ) ); }
@Test public void testMarshallEvents() throws Exception { String str = config.setOption( EventProcessingOption.STREAM ); KieSession ksession = kBase.newStatefulKnowledgeSession( ksconf, null ); ksession.insert( new A() ); ksession.insert( new B() ); ksession.fireAllRules(); assertEquals( 2, ksession.getObjects().size() );
@Test public void testEventExpires() throws Exception { String timerRule = "package org.drools.test\n" + " then \n" + "end"; KieBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbconf.setOption( EventProcessingOption.STREAM ); InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( kbconf ); Resource resource = ResourceFactory.newByteArrayResource( timerRule.getBytes() );
@Before public void initialization() { KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem(); kfs.write("src/main/resources/kbase1/window_test.drl", drl); KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs); kbuilder.buildAll(); List<Message> res = kbuilder.getResults().getMessages(Level.ERROR); assertEquals(res.toString(), 0, res.size()); KieBaseConfiguration kbconf = KnowledgeBaseFactory .newKnowledgeBaseConfiguration(); kbconf.setOption(EventProcessingOption.STREAM); KieBase kbase = KieServices.Factory.get() .newKieContainer(kbuilder.getKieModule().getReleaseId()) .newKieBase(kbconf); KieSessionConfiguration ksconfig = KnowledgeBaseFactory .newKnowledgeSessionConfiguration(); ksconfig.setOption(ClockTypeOption.get("pseudo")); ksession = kbase.newKieSession(ksconfig, null); clock = ksession.getSessionClock(); }
public static void main(String[] args) throws InterruptedException { KieServices kieServices = KieServices.Factory.get(); KieBaseConfiguration config = kieServices.newKieBaseConfiguration(); config.setOption(EventProcessingOption.STREAM); KieContainer container = kieServices.getKieClasspathContainer(); // KieBase kieBase = container.getKieBase("test-cep"); KieBase kieBase = container.newKieBase("test-cep",config); KieSession kieSession = kieBase.newKieSession(); Person p1 = new Person(1,"Tom"); Person p2 = new Person(2,"Lucy"); kieSession.insert(p1); Thread.sleep(3000); kieSession.insert(p2); int count = kieSession.fireAllRules(); System.out.println("Fire " + count + " rules!"); } }
private int processStocks(int stockCount, AgendaEventListener agendaEventListener, String drlContentString) throws Exception { KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption(EventProcessingOption.STREAM); KieBase kbase = loadKnowledgeBaseFromString(kconf, drlContentString); 100 * stIndex, 100 * stIndex); ksession.insert(st); Thread.sleep( 100 );
@Test(timeout=10000) public void testCancelMultipleActivations() { String str = "package org.domain.test\n" + "end"; KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption( DeclarativeAgendaOption.ENABLED ); KieBase kbase = loadKnowledgeBaseFromString( kconf, str ); KieSession ksession = createKnowledgeSession(kbase); ksession.setGlobal( "list", list ); ksession.insert("fireRules"); ksession.fireAllRules(); System.out.println(list); assertEquals(0, list.size());
@Test public void testShareAlphaNodesConfiguration() { // setting the option using the type safe method config.setOption( ShareAlphaNodesOption.YES ); // checking the type safe getOption() method assertEquals( ShareAlphaNodesOption.YES, config.getOption( ShareAlphaNodesOption.class ) ); // checking the string based getProperty() method assertEquals( "true", config.getProperty( ShareAlphaNodesOption.PROPERTY_NAME ) ); // setting the options using the string based setProperty() method config.setProperty( ShareAlphaNodesOption.PROPERTY_NAME, "false" ); // checking the type safe getOption() method assertEquals( ShareAlphaNodesOption.NO, config.getOption( ShareAlphaNodesOption.class ) ); // checking the string based getProperty() method assertEquals( "false", config.getProperty( ShareAlphaNodesOption.PROPERTY_NAME ) ); }
@Test public void testMarshallWithNot() throws Exception { String str = "import " + getClass().getCanonicalName() + ".*\n" + "rule one\n" + "when\n" + " A()\n" + " not(B())\n" + "then\n" + "System.out.println(\"a\");\n" + "end\n" + "\n" + "rule two\n" + "when\n" + " A()\n" + "then\n" + "System.out.println(\"b\");\n" + "end\n"; KieBaseConfiguration config = KnowledgeBaseFactory .newKnowledgeBaseConfiguration(); config.setOption( EventProcessingOption.STREAM ); KnowledgeBase kBase = loadKnowledgeBaseFromString(config, str); StatefulKnowledgeSession ksession = kBase.newStatefulKnowledgeSession(); ksession.insert( new A() ); MarshallerFactory.newMarshaller( kBase ).marshall( new ByteArrayOutputStream(), ksession ); }
private InternalKnowledgeBase createKnowledgeBase() { KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); config.setOption( EventProcessingOption.STREAM ); return (InternalKnowledgeBase)KnowledgeBaseFactory.newKnowledgeBase( config ); }
@Test(timeout=10000) public void testStatedShadowLogicalWithSingleOccurance() { String droolsSource = KieBaseConfiguration kieConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kieConf.setOption( EqualityBehaviorOption.IDENTITY ); KieBase kbase = loadKnowledgeBaseFromString( kieConf, droolsSource ); KieSession session = kbase.newKieSession(); try { List list = new ArrayList(); session.setGlobal("list", list); InternalFactHandle fh1 = (InternalFactHandle) session.insert( "f1" ); InternalFactHandle fh2 = (InternalFactHandle) session.insert( "f2" ); session.insert( "go1" ); session.fireAllRules(); session.insert( "go2" ); session.fireAllRules(); assertEquals( 1, list.size() ); assertEquals( "f1", list.get( 0 ) ); } finally { session.dispose();
@Test public void testIndexLeftBetaMemoryConfiguration() { // setting the option using the type safe method config.setOption( IndexLeftBetaMemoryOption.YES ); // checking the type safe getOption() method assertEquals( IndexLeftBetaMemoryOption.YES, config.getOption( IndexLeftBetaMemoryOption.class ) ); // checking the string based getProperty() method assertEquals( "true", config.getProperty( IndexLeftBetaMemoryOption.PROPERTY_NAME ) ); // setting the options using the string based setProperty() method config.setProperty( IndexLeftBetaMemoryOption.PROPERTY_NAME, "false" ); // checking the type safe getOption() method assertEquals( IndexLeftBetaMemoryOption.NO, config.getOption( IndexLeftBetaMemoryOption.class ) ); // checking the string based getProperty() method assertEquals( "false", config.getProperty( IndexLeftBetaMemoryOption.PROPERTY_NAME ) ); }
@Test public void testAlphaNodeSharing() throws Exception { KieBaseConfiguration kbc = org.kie.internal.KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbc.setOption( ShareAlphaNodesOption.YES ); final KnowledgeBase kbase = SerializationHelper.serializeObject( loadKnowledgeBase( kbc, "test_alphaNodeSharing.drl" ) ); final StatefulKnowledgeSession ksession = createKnowledgeSession( kbase ); final List results = new ArrayList(); ksession.setGlobal( "results", results ); Person p1 = new Person( "bob", 5 ); ksession.insert( p1 ); ksession.fireAllRules(); assertEquals( 2, results.size() ); assertEquals( "1", results.get( 0 ) ); assertEquals( "2", results.get( 1 ) ); }
@Before public void setup() { kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kconf.setOption( SequentialOption.YES ); }
@Test public void testNotInStatelessSession() throws Exception { final KieBaseConfiguration kbc = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); kbc.setOption(SequentialOption.YES); final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase(kbc, "test_NotInStatelessSession.drl")); final StatelessKieSession session = kbase.newStatelessKieSession(); final List list = new ArrayList(); session.setGlobal("list", list); session.execute("not integer"); assertEquals("not integer", list.get(0)); }
@Test public void testIndexRightBetaMemoryConfiguration() { // setting the option using the type safe method config.setOption( IndexRightBetaMemoryOption.YES ); // checking the type safe getOption() method assertEquals( IndexRightBetaMemoryOption.YES, config.getOption( IndexRightBetaMemoryOption.class ) ); // checking the string based getProperty() method assertEquals( "true", config.getProperty( IndexRightBetaMemoryOption.PROPERTY_NAME ) ); // setting the options using the string based setProperty() method config.setProperty( IndexRightBetaMemoryOption.PROPERTY_NAME, "false" ); // checking the type safe getOption() method assertEquals( IndexRightBetaMemoryOption.NO, config.getOption( IndexRightBetaMemoryOption.class ) ); // checking the string based getProperty() method assertEquals( "false", config.getProperty( IndexRightBetaMemoryOption.PROPERTY_NAME ) ); }