@Override protected void setUp() throws Exception { super.setUp(); server = new HornetQTaskServer(taskService, 5153); System.out.println("Waiting for the HornetQTask Server to come up"); try { startTaskServerThread(server, false); } catch (Exception e) { startTaskServerThread(server, true); } AsyncHornetQHTWorkItemHandler handler = new AsyncHornetQHTWorkItemHandler(ksession); setClient(handler.getClient()); setHandler(handler); }
@Test public void testCompleteTaskMultipleSessionsASync() throws Exception { TestStatefulKnowledgeSession ksession = new TestStatefulKnowledgeSession(); AsyncHornetQHTWorkItemHandler handler = new AsyncHornetQHTWorkItemHandler(ksession, true); clientAsync = handler.getClient(); HornetQTestWorkItemManager manager = new HornetQTestWorkItemManager(); ksession.setWorkItemManager(manager); WorkItemImpl workItem = new WorkItemImpl(); workItem.setName("Human Task"); workItem.setParameter("TaskName", "TaskName"); workItem.setParameter("Comment", "Comment"); workItem.setParameter("Priority", "10"); workItem.setParameter("ActorId", "Darth Vader"); workItem.setProcessInstanceId(10); handler.executeWorkItem(workItem, manager); TestStatefulKnowledgeSession ksession2 = new TestStatefulKnowledgeSession(10); AsyncHornetQHTWorkItemHandler handler2 = new AsyncHornetQHTWorkItemHandler("testConnector", null, ksession2, OnErrorAction.LOG); handler2.setOwningSessionOnly(true); HornetQTestWorkItemManager manager2 = new HornetQTestWorkItemManager(); ksession2.setWorkItemManager(manager2); WorkItemImpl workItem2 = new WorkItemImpl(); workItem2.setName("Human Task"); workItem2.setParameter("TaskName", "TaskName"); workItem2.setParameter("Comment", "Comment"); workItem2.setParameter("Priority", "10"); workItem2.setParameter("ActorId", "Darth Vader"); workItem2.setProcessInstanceId(10); handler2.executeWorkItem(workItem2, manager2); Thread.sleep(1000); BlockingTaskSummaryResponseHandler reshanlder = new BlockingTaskSummaryResponseHandler(); clientAsync.getTasksAssignedAsPotentialOwner("Darth Vader", "en-UK", reshanlder); List<TaskSummary> tasks = reshanlder.getResults(); assertEquals(2, tasks.size()); TaskSummary task = tasks.get(0); // ensure we get first task if (task.getProcessSessionId() == 10) { task = tasks.get(1); } assertEquals("TaskName", task.getName()); assertEquals(10, task.getPriority()); assertEquals("Comment", task.getDescription()); assertEquals(Status.Reserved, task.getStatus()); assertEquals("Darth Vader", task.getActualOwner().getId()); assertEquals(10, task.getProcessInstanceId()); BlockingTaskOperationResponseHandler resOpHandler = new BlockingTaskOperationResponseHandler(); clientAsync.start(task.getId(), "Darth Vader", resOpHandler); resOpHandler.waitTillDone(5000); resOpHandler = new BlockingTaskOperationResponseHandler(); clientAsync.complete(task.getId(), "Darth Vader", null, resOpHandler); resOpHandler.waitTillDone(5000); Thread.sleep(1000); assertEquals(1, manager.getCompleteCounter()); assertEquals(0, manager2.getCompleteCounter()); handler.dispose(); handler2.dispose(); }