session.halt();
ksession.halt();
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState()); assertEquals(1, ((InternalProcessRuntime) ((InternalWorkingMemory) session).getProcessRuntime()).getTimerManager().getTimers().size()); session.halt();
private void stopEngine() { ksession.halt(); executorService.shutdownNow(); }
private void waitForResultAndStopFireUntilHalt(final List<Integer> resultList, final KieSession kieSession, final Future fireUntilHaltFuture) throws InterruptedException, ExecutionException { try { while (resultList.size() < 1) { Thread.sleep(100); } } finally { kieSession.halt(); fireUntilHaltFuture.get(); } }
@After public void after() { ksession.halt(); ksession.dispose(); }
@Test public void testFireAllWhenFiringUntilHalt() throws InterruptedException { final KieBase kbase = getKnowledgeBase(); final KieSession ksession = createKnowledgeSession(kbase); final Thread t1 = new Thread(ksession::fireUntilHalt); final Thread t2 = new Thread(ksession::fireAllRules); t1.start(); Thread.sleep(500); t2.start(); // give the chance for t2 to finish Thread.sleep(1000); final boolean aliveT2 = t2.isAlive(); ksession.halt(); Thread.sleep(1000); final boolean aliveT1 = t1.isAlive(); if (t2.isAlive()) { t2.interrupt(); } if (t1.isAlive()) { t1.interrupt(); } assertFalse("T2 should have finished", aliveT2); assertFalse("T1 should have finished", aliveT1); }
/** * Events are being collected through accumulate while * separate thread inserts other events. * <p/> * The engine runs in fireUntilHalt mode started in a separate thread. * Events may expire during the evaluation of accumulate. */ @Test public void testFireUntilHaltWithAccumulateAndExpires() throws Exception { // thread for firing until halt final ExecutorService executor = Executors.newSingleThreadExecutor(); final Future sessionFuture = executor.submit((Runnable) statefulSession::fireUntilHalt); try { for (int iteration = 0; iteration < 100; iteration++) { this.populateSessionWithStocks(); } // let the engine finish its job Thread.sleep(2000); } finally { statefulSession.halt(); // not to swallow possible exception sessionFuture.get(); statefulSession.dispose(); executor.shutdownNow(); } }
ksession.halt();
list.onItemAdded = (l -> { if (l.size() == 10) { ksession.halt(); done.countDown();
@Test public void testFactLeak() throws InterruptedException { //DROOLS-131 String drl = "package org.drools.test; \n" + "global java.util.List list; \n" + "" + "" + "rule Intx when\n" + " $x : Integer() from entry-point \"x\" \n" + "then\n" + " list.add( $x ); \n" + "end"; int N = 1100; KieBase kb = loadKnowledgeBaseFromString( drl ); final KieSession ks = kb.newKieSession(); ArrayList list = new ArrayList(); ks.setGlobal( "list", list ); new Thread(ks::fireUntilHalt).start(); try { for ( int j = 0; j < N; j++ ) { ks.getEntryPoint( "x" ).insert( new Integer( j ) ); } Thread.sleep( 1000 ); } finally { ks.halt(); ks.dispose(); assertEquals( N, list.size() ); } }
@Test(timeout = 10000) public void testClassLoaderRace() throws InterruptedException { final String drl = "package org.drools.integrationtests;\n" + "" + "rule \"average temperature\"\n" + "when\n" + " $avg := Number( ) from accumulate ( " + " $x : Integer ( ); " + " average ($x) )\n" + "then\n" + " System.out.println( $avg );\n" + "end\n" + "\n"; final KieBase kbase = loadKnowledgeBaseFromString(drl); final KieSession session = kbase.newKieSession(); final Thread t = new Thread(session::fireUntilHalt); t.start(); try { session.fireAllRules(); for (int j = 0; j < 100; j++) { session.insert(j); } Thread.sleep(1000); } finally { session.halt(); session.dispose(); } }
ksession.halt(); ksession.dispose();
ep.insert(new Person("darth")); Thread.sleep(500); ksession.halt(); t1.join(5000); final boolean alive = t1.isAlive();
ksession.halt(); ksession.dispose();
ksession.halt(); ksession.dispose();
assertEquals(1, list.size()); kSession.halt(); kSession.dispose();
ksession.halt();