@Test public void testStatelessKieSessionsPool() { KieContainerSessionsPool pool = getKieContainer().newKieSessionsPool( 1 ); StatelessKieSession session = pool.newStatelessKieSession(); List<String> list = new ArrayList<>(); session.setGlobal( "list", list ); session.execute( "test" ); assertEquals(1, list.size()); list.clear(); session.execute( "test" ); assertEquals(1, list.size()); }
@Test public void testKieSessionsPoolInMultithreadEnv() throws InterruptedException, ExecutionException { KieContainerSessionsPool pool = getKieContainer().newKieSessionsPool( 4 );
@Test public void testListenersReset() { final KieContainerSessionsPool pool = getKieContainer().newKieSessionsPool( 1 ); KieSession ksession = pool.newKieSession(); try { ksession.addEventListener(new DefaultAgendaEventListener()); ksession.addEventListener(new DefaultRuleRuntimeEventListener()); ((RuleEventManager) ksession).addEventListener(new RuleEventListener() {}); } finally { ksession.dispose(); } ksession = pool.newKieSession(); try { Assertions.assertThat(ksession.getAgendaEventListeners()).hasSize(0); Assertions.assertThat(ksession.getRuleRuntimeEventListeners()).hasSize(0); Assertions.assertThat(((EventSupport) ksession).getRuleEventSupport().getEventListeners()).hasSize(0); } finally { ksession.dispose(); } } }
@Override public KieContainerSessionsPool newKieSessionsPool( int initialSize ) { return getKieContainer().newKieSessionsPool( initialSize ); }
@Override public KieContainerSessionsPool newKieSessionsPool( int initialSize ) { return getKieContainer().newKieSessionsPool( initialSize ); }
KieSessionsPool pool = kcontainer.newKieSessionsPool( 1 );
@Test public void testKieSessionsPool() { KieContainerSessionsPool pool = getKieContainer().newKieSessionsPool( 1 ); KieSession ksession = pool.newKieSession(); try { checkKieSession( ksession ); } finally { ksession.dispose(); } try { ksession.insert( "test2" ); fail("it shouldn't be possible to operate on a disposed session even if created from a pool"); } catch (Exception e) { } KieSession ksession2 = pool.newKieSession(); // using a pool with only one session so it should return the same one as before assertSame( ksession, ksession2 ); assertNull( ksession2.getGlobal( "list" ) ); checkKieSession( ksession2 ); pool.shutdown(); try { ksession.insert( "test3" ); fail("after pool shutdown all sessions created from it should be disposed"); } catch (IllegalStateException e) { } try { pool.newKieSession(); fail("after pool shutdown it shouldn't be possible to get sessions from it"); } catch (IllegalStateException e) { } }