我有一个测试来解组 kiesession,数据在全球,但解组不会返回全球。
代码是:
Java 测试
KieServices kieServices = KieServices.Factory.get();
KieContainer kContainer = kieServices.getKieClasspathContainer();
KieBase kBase1 = kContainer.getKieBase("KBase1");
KieSession kieSession1 = kContainer.newKieSession("KSession2_1");
Map<String, Object> map = new ConcurrentHashMap<String, Object>();
int tam = 10000;
for (int i = 0; i < tam; i++) {
map.put("map" + i, i);
}
kieSession1.setGlobal("map", map);
for (int i = 0; i < tam; i++) {
Client client = new Client();
client.setName("test");
client.setEdad(10);
kieSession1.insert(client);
}
kieSession1.fireAllRules();
Marshaller marshaller = MarshallerFactory.newMarshaller(kBase1);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
marshaller.marshall(baos, kieSession1);
} catch (IOException e) {
fail("error");
}
byte[] data = baos.toByteArray();
try {
baos.close();
} catch (IOException e) {
fail("error");
}
//
kieSession1.dispose();
InputStream is = new ByteArrayInputStream(data);
try {
kieSession1 = marshaller.unmarshall(is);
} catch (ClassNotFoundException e) {
fail("error");
} catch (IOException e) {
fail("error : " + e);
} finally {
try {
is.close();
} catch (IOException e) {
}
}
assertEquals(tam, kieSession1.getFactCount());
assertNotNull("No existe Global !!", kieSession1.getGlobal("map"));
流口水规则
global java.util.Map map
rule "test"
when
then
System.out.println("test !!" + map.size());
end
版本是:
- org.drools:drools-compiler:jar:6.1.0.Final
- org.drools:drools-core:jar:6.1.0.Final
- org.kie:kie-api:jar:6.1.0.Final.1.2
- org.kie:kie-internal:jar:6.1.0.Final