Search in sources :

Example 1 with DefaultKieBaseEventListener

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());
}
Also used : DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) TestWorkItemManager(org.jbpm.process.workitem.core.TestWorkItemManager) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) AfterRuleAddedEvent(org.kie.api.event.kiebase.AfterRuleAddedEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Person(org.jbpm.process.workitem.bpmn2.objects.Person) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with DefaultKieBaseEventListener

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();
}
Also used : DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) KieBase(org.kie.api.KieBase) DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) KieBaseEventListener(org.kie.api.event.kiebase.KieBaseEventListener) Test(org.junit.Test)

Example 3 with DefaultKieBaseEventListener

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());
}
Also used : DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) KieBase(org.kie.api.KieBase) KieBaseEventListener(org.kie.api.event.kiebase.KieBaseEventListener) DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) Test(org.junit.Test)

Example 4 with DefaultKieBaseEventListener

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());
}
Also used : DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) KieBase(org.kie.api.KieBase) KieBaseEventListener(org.kie.api.event.kiebase.KieBaseEventListener) DefaultKieBaseEventListener(org.kie.api.event.kiebase.DefaultKieBaseEventListener) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 DefaultKieBaseEventListener (org.kie.api.event.kiebase.DefaultKieBaseEventListener)4 KieBase (org.kie.api.KieBase)3 KieBaseEventListener (org.kie.api.event.kiebase.KieBaseEventListener)3 CountDownLatch (java.util.concurrent.CountDownLatch)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)1 Person (org.jbpm.process.workitem.bpmn2.objects.Person)1 TestWorkItemManager (org.jbpm.process.workitem.core.TestWorkItemManager)1 Ignore (org.junit.Ignore)1 AfterRuleAddedEvent (org.kie.api.event.kiebase.AfterRuleAddedEvent)1