40 ) );
InternalFactHandle bob3 = (InternalFactHandle) session.insert( new Person( "bob",
40 ) );
InternalFactHandle bob4 = (InternalFactHandle) session.insert( new Person( "bob",
40 ) );
InternalFactHandle addr1 = (InternalFactHandle) session.insert( new Address( "bangalore" ) );
InternalFactHandle addr2 = (InternalFactHandle) session.insert( new Address( "India" ) );
session.fireAllRules();
assertEquals( 9,
results.size() );
assertEquals( stilton3.getObject(),
results.get( 4 ) );
assertEquals( bob4.getObject(),
results.get( 5 ) );
assertEquals( bob3.getObject(),
results.get( 6 ) );
assertEquals( addr2.getObject(),
results.get( 7 ) );
assertEquals( addr1.getObject(),
results.get( 8 ) );
serializedRulebase = null;
resolver = session.getGlobalResolver();
baos = new ByteArrayOutputStream();
ksession = new StatefulKnowledgeSessionImpl( (ReteooStatefulSession) session );
marshaller = MarshallerFactory.newMarshaller( ksession.getKnowledgeBase() );
marshaller.marshall( baos,
ksession );
baos.close();
serializedRulebase = DroolsStreamUtils.streamOut( ruleBase );
session.dispose();
// now recreate the rulebase, deserialize the session and test it
ruleBase = (RuleBase) DroolsStreamUtils.streamIn( serializedRulebase );
marshaller = MarshallerFactory.newMarshaller( new KnowledgeBaseImpl( ruleBase ) );
ksession = (StatefulKnowledgeSessionImpl) marshaller.unmarshall( new ByteArrayInputStream( baos.toByteArray() ),
KnowledgeBaseFactory.newKnowledgeSessionConfiguration(),
EnvironmentFactory.newEnvironment() );
session = (ReteooStatefulSession) ksession.session;
session.setGlobalResolver( resolver );
results = (List) session.getGlobal( "results" );
InternalFactHandle stilton4 = (InternalFactHandle) session.insert( new Cheese( "stilton",
50 ) );
InternalFactHandle brie4 = (InternalFactHandle) session.insert( new Cheese( "brie",
50 ) );
InternalFactHandle bob5 = (InternalFactHandle) session.insert( new Person( "bob",
50 ) );
InternalFactHandle bob6 = (InternalFactHandle) session.insert( new Person( "bob",
50 ) );
InternalFactHandle addr3 = (InternalFactHandle) session.insert( new Address( "Tripura" ) );
InternalFactHandle addr4 = (InternalFactHandle) session.insert( new Address( "Agartala" ) );
session.fireAllRules();
assertEquals( 14,
results.size() );