use of org.kie.api.event.kiebase.DefaultKieBaseEventListener in project jbpm by kiegroup.
the class BusinessRuleTaskHandlerTest method testDrlStatefulBusinessRuleTaskWithScanner.
@Ignore("ignored as it is unstable on jenkins for unknown reason")
@Test
public void testDrlStatefulBusinessRuleTaskWithScanner() throws Exception {
TestWorkItemManager manager = new TestWorkItemManager();
BusinessRuleTaskHandler handler = new BusinessRuleTaskHandler(GROUP_ID, ARTIFACT_ID, VERSION, 2000);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setId(999);
Person person = new Person("john");
workItem.setParameter("person", person);
workItem.setParameter("KieSessionType", BusinessRuleTaskHandler.STATEFULL_TYPE);
handler.executeWorkItem(workItem, manager);
Map<String, Object> results = manager.getResults(workItem.getId());
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(35, ((Person) results.get("person")).getAge().intValue());
// build and deploy new version
createAndDeployJar(ks, ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION), ks.getResources().newClassPathResource("businessRule2.drl"));
// setup waiting mechanism to wait for scanner update
CountDownLatch latch = new CountDownLatch(1);
handler.getKieContainer().getKieBase().addEventListener(new DefaultKieBaseEventListener() {
@Override
public void afterRuleAdded(AfterRuleAddedEvent event) {
latch.countDown();
}
});
latch.await(10, TimeUnit.SECONDS);
person = new Person("john");
workItem.setParameter("person", person);
workItem.setParameter("KieSessionType", BusinessRuleTaskHandler.STATEFULL_TYPE);
handler.executeWorkItem(workItem, manager);
results = manager.getResults(workItem.getId());
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(45, ((Person) results.get("person")).getAge().intValue());
}
use of org.kie.api.event.kiebase.DefaultKieBaseEventListener in project drools by kiegroup.
the class MultipleKieBaseListenersTest method testKnowledgeBaseEventSupportLeak.
@Test
public void testKnowledgeBaseEventSupportLeak() throws Exception {
final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, "");
KieBaseEventListener listener = new DefaultKieBaseEventListener();
kieBase.addEventListener(listener);
kieBase.addEventListener(listener);
kieBase.addEventListener(listener);
Assertions.assertThat(kieBase.getKieBaseEventListeners().size()).isEqualTo(1);
kieBase.removeEventListener(listener);
Assertions.assertThat(kieBase.getKieBaseEventListeners()).isEmpty();
}
use of org.kie.api.event.kiebase.DefaultKieBaseEventListener in project drools by kiegroup.
the class Misc2Test method testKnowledgeBaseEventSupportLeak.
@Test
public void testKnowledgeBaseEventSupportLeak() throws Exception {
// JBRULES-3666
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration);
KieBaseEventListener listener = new DefaultKieBaseEventListener();
kbase.addEventListener(listener);
kbase.addEventListener(listener);
assertEquals(1, kbase.getKieBaseEventListeners().size());
kbase.removeEventListener(listener);
assertEquals(0, kbase.getKieBaseEventListeners().size());
}
use of org.kie.api.event.kiebase.DefaultKieBaseEventListener in project drools by kiegroup.
the class Misc2Test method testKnowledgeBaseEventSupportLeak.
@Test
public void testKnowledgeBaseEventSupportLeak() throws Exception {
// JBRULES-3666
KieBase kbase = getKnowledgeBase();
KieBaseEventListener listener = new DefaultKieBaseEventListener();
kbase.addEventListener(listener);
kbase.addEventListener(listener);
assertEquals(1, ((KnowledgeBaseImpl) kbase).getKieBaseEventListeners().size());
kbase.removeEventListener(listener);
assertEquals(0, ((KnowledgeBaseImpl) kbase).getKieBaseEventListeners().size());
}
Aggregations