Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Test
- public void testFireUntilHalt() throws InterruptedException, IOException {
- String drl = "package org.jboss.qa.jbpm.functional\n" +
- "\n" +
- "import org.jboss.qa.brms.domain.Person;\n" +
- "\n" +
- "rule \"person detector\"\n" +
- " when\n" +
- " Person( )\n" +
- " then\n" +
- " System.out.println(\"There is a person.\");\n" +
- "end";
- RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get()
- .newEmptyBuilder()
- .addAsset(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DRL)
- .get();
- RuntimeManager runtimeManager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
- // ksession for process instance #1
- // since there is no process instance yet we need to get new session
- RuntimeEngine runtime = runtimeManager.getRuntimeEngine(EmptyContext.get());
- final KieSession ksessionLocal = runtime.getKieSession();
- TrackingAgendaEventListener listener = new TrackingAgendaEventListener();
- ksessionLocal.addEventListener(listener);
- // thread for firing until halt
- ExecutorService thread = Executors.newSingleThreadExecutor();
- thread.submit(new Runnable() {
- @Override
- public void run() {
- ksessionLocal.fireUntilHalt();
- }
- });
- int wantedPersonsNum = 3;
- int unwantedPersonsNum = 2;
- Person p;
- // insert 3 wanted persons
- for (int i = 0; i < wantedPersonsNum; i++) {
- p = new Person("wanted person");
- p.setId(i);
- ksessionLocal.insert(p);
- }
- // insert 2 unwanted persons
- for (int i = 0; i < unwantedPersonsNum; i++) {
- p = new Person("unwanted person");
- p.setId(i + 50);
- ksessionLocal.insert(p);
- }
- // wait for rule to fire
- Thread.sleep(1000);
- // 8 persons should be acknowledged - person detector rule fired
- assertEquals(wantedPersonsNum + unwantedPersonsNum, listener.ruleFiredCount("person detector"));
- ksessionLocal.halt();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement