105106107108109110111112113114115
@Override public int evaluateInSharedSession(Message message) { final KieSession kieSession = session.get(); if (kieSession != null) { kieSession.insert(message); return kieSession.fireAllRules(); } return 0; } @Override
99100101102103104105106107108109
list ); AtomicInteger value = new AtomicInteger(4); FactHandle atomicFH = ksession.insert( value ); ksession.fireAllRules(); assertEquals( 1, list.size() ); value.addAndGet(1);
106107108109110111112113114115116
assertEquals( 1, list.size() ); value.addAndGet(1); ksession.update(atomicFH, value); ksession.fireAllRules(); assertEquals( 2, list.size() ); String externalForm = atomicFH.toExternalForm();
119120121122123124125126127128129
atomicFH = ksession.execute(CommandFactory.fromExternalFactHandleCommand(externalForm)); value.addAndGet(1); ksession.update(atomicFH, value); ksession.fireAllRules(); list = (List<?>) ksession.getGlobal("list"); assertEquals( 3, list.size() );
158159160161162163164165166167168
ksession.insert( 1 ); ksession.insert( 2 ); ksession.insert( 3 ); ksession.fireAllRules(); assertEquals( 3, list.size() ); }
199200201202203204205206207208209
ut.begin(); ksession.setGlobal( "list", list ); ksession.insert( 1 ); ksession.insert( 2 ); ksession.fireAllRules(); ut.commit(); // insert and rollback ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" ); ut.begin();
211212213214215216217218219220221
ut.rollback(); // check we rolled back the state changes from the 3rd insert ut = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" ); ut.begin(); ksession.fireAllRules(); ut.commit(); assertEquals( 2, list.size() ); // insert and commit
230231232233234235236237238239240
ut.begin(); ksession.insert( 5 ); ksession.insert( 6 ); ut.rollback(); ksession.fireAllRules(); assertEquals( 4, list.size() ); // now load the ksession
244245246247248249250251252253254
ut.begin(); ksession.insert( 7 ); ksession.insert( 8 ); ut.commit(); ksession.fireAllRules(); assertEquals( 6, list.size() ); }
317318319320321322323324325326327
ksession.insert( 1 ); ksession.insert( 2 ); ksession.insert( 3 ); ksession.getAgenda().getAgendaGroup("badfocus").setFocus(); ksession.fireAllRules(); assertEquals( 3, list.size() ); }