use of org.drools.compiler.integrationtests.facts.BeanA in project drools by kiegroup.
the class SharedSessionParallelTest method testCountdownBean2.
@Test(timeout = 20000)
public void testCountdownBean2() throws InterruptedException {
final int threadCount = 100;
final int seed = 1000;
final String drl = "import " + BeanA.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule countdown " + "when " + " $bean : BeanA($n : seed, seed > 0 ) " + "then " + " modify($bean) { setSeed($n-1) };" + " list.add(\"\" + $bean.getSeed());" + "end";
final KieSession kieSession = getKieBase(drl).newKieSession();
final List<String> list = Collections.synchronizedList(new ArrayList<>());
final BeanA[] beans = new BeanA[threadCount];
final TestExecutor exec = counter -> {
final BeanA bean = new BeanA(seed);
beans[counter] = bean;
try {
kieSession.setGlobal("list", list);
kieSession.insert(bean);
kieSession.fireAllRules();
return true;
} catch (final Exception ex) {
throw new RuntimeException(ex);
}
};
parallelTest(threadCount, exec);
kieSession.dispose();
checkList(0, seed, list, seed * threadCount);
for (final BeanA bean : beans) {
Assertions.assertThat(bean).hasFieldOrPropertyWithValue("seed", 0);
}
}
Aggregations