use of org.kie.server.client.jms.RequestReplyResponseHandler in project droolsjbpm-integration by kiegroup.
the class DroolsJmsResponseHandlerIntegrationTest method testExecuteSimpleRuleFlowProcessWithFireAndForgetResponseHandler.
@Test
public void testExecuteSimpleRuleFlowProcessWithFireAndForgetResponseHandler() throws Exception {
// First command in this test needs to be executed with RequestReplyResponseHandler.
// If there would be used FireAndForgetResponseHandler then following request could reach Kie server in same time
// causing stateful kie session for this container to be created concurrently.
// Concurrent creation of same stateful kie session leads to overriding one kie session with another,
// causing inconsistency and data loss.
Command<?> initializeList = commandsFactory.newSetGlobal(LIST_NAME, new ArrayList<String>(), LIST_OUTPUT_NAME);
ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, initializeList);
KieServerAssert.assertSuccess(response);
try {
ruleClient.setResponseHandler(new FireAndForgetResponseHandler());
Command<?> startProcess = commandsFactory.newStartProcess(PROCESS_ID);
response = ruleClient.executeCommandsWithResults(CONTAINER_ID, startProcess);
assertThat(response).isNull();
} finally {
ruleClient.setResponseHandler(new RequestReplyResponseHandler());
}
Command<?> getGlobalCommand = commandsFactory.newGetGlobal(LIST_NAME, LIST_OUTPUT_NAME);
List<String> value = new ArrayList<String>();
value.add("Rule from first ruleflow group executed");
value.add("Rule from second ruleflow group executed");
KieServerSynchronization.waitForCommandResult(ruleClient, CONTAINER_ID, getGlobalCommand, LIST_OUTPUT_NAME, value);
}
use of org.kie.server.client.jms.RequestReplyResponseHandler in project droolsjbpm-integration by kiegroup.
the class JmsResponseHandlerIntegrationTest method resetResponseHandler.
@After
public void resetResponseHandler() {
processClient.setResponseHandler(new RequestReplyResponseHandler());
queryClient.setResponseHandler(new RequestReplyResponseHandler());
taskClient.setResponseHandler(new RequestReplyResponseHandler());
}
use of org.kie.server.client.jms.RequestReplyResponseHandler in project droolsjbpm-integration by kiegroup.
the class JmsResponseHandlerIntegrationTest method testGetProcessInstancesResponseHandler.
private void testGetProcessInstancesResponseHandler(ResponseHandler responseHandler) throws Exception {
List<ProcessInstance> processInstances = queryClient.findProcessInstances(0, 100);
assertThat(processInstances).isEmpty();
Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK);
assertThat(processInstanceId).isNotNull();
KieServerSynchronization.waitForProcessInstanceStart(queryClient, CONTAINER_ID);
// change response handler for queryClient others are not affected
queryClient.setResponseHandler(responseHandler);
// Process should be started completely async - fire and forget.
processInstances = queryClient.findProcessInstances(0, 100);
assertThat(processInstances).isNull();
// set it back for the sake of verification
queryClient.setResponseHandler(new RequestReplyResponseHandler());
// Process should be started completely async - fire and forget.
processInstances = queryClient.findProcessInstances(0, 100);
assertThat(processInstances).isNotNull().hasSize(1);
ProcessInstance pi = processInstances.get(0);
assertThat(pi.getState()).isEqualTo(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
}
use of org.kie.server.client.jms.RequestReplyResponseHandler in project droolsjbpm-integration by kiegroup.
the class JmsResponseHandlerIntegrationTest method testStartAndCompleteTask.
private void testStartAndCompleteTask(ResponseHandler responseHandler) throws Exception {
Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK);
assertThat(processInstanceId).isNotNull();
List<ProcessInstance> processInstances = queryClient.findProcessInstances(0, 100);
assertThat(processInstances).isNotNull().hasSize(1);
assertThat(processInstances.get(0)).isNotNull();
assertThat(processInstances.get(0).getState()).isEqualTo(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
List<TaskSummary> tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertThat(tasks).hasSize(1);
Long taskId = tasks.get(0).getId();
taskClient.setResponseHandler(responseHandler);
taskClient.startTask(CONTAINER_ID, taskId, USER_YODA);
taskClient.setResponseHandler(new RequestReplyResponseHandler());
KieServerSynchronization.waitForTaskStatus(taskClient, taskId, Status.InProgress.name());
taskClient.setResponseHandler(responseHandler);
taskClient.completeTask(CONTAINER_ID, taskId, USER_YODA, new HashMap<String, Object>());
taskClient.setResponseHandler(new RequestReplyResponseHandler());
KieServerSynchronization.waitForTaskStatus(taskClient, taskId, Status.Completed.name());
tasks = taskClient.findTasksAssignedAsPotentialOwner(USER_YODA, 0, 10);
assertThat(tasks).hasSize(1);
taskId = tasks.get(0).getId();
taskClient.setResponseHandler(responseHandler);
taskClient.startTask(CONTAINER_ID, taskId, USER_YODA);
taskClient.setResponseHandler(new RequestReplyResponseHandler());
KieServerSynchronization.waitForTaskStatus(taskClient, taskId, Status.InProgress.name());
taskClient.setResponseHandler(responseHandler);
taskClient.completeTask(CONTAINER_ID, taskId, USER_YODA, new HashMap<String, Object>());
KieServerSynchronization.waitForProcessInstanceToFinish(processClient, CONTAINER_ID, processInstanceId);
}
use of org.kie.server.client.jms.RequestReplyResponseHandler in project droolsjbpm-integration by kiegroup.
the class JmsResponseHandlerIntegrationTest method testQueryRegistration.
private void testQueryRegistration(ResponseHandler responseHandler) throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("stringData", "waiting for signal");
parameters.put("personData", createPersonInstance(CONTAINER_ID));
processClient.startProcess(CONTAINER_ID, PROCESS_ID_USERTASK, parameters);
QueryDefinition query = new QueryDefinition();
query.setName("getTasksByState");
query.setSource(System.getProperty("org.kie.server.persistence.ds", "jdbc/jbpm-ds"));
query.setExpression("select * from AuditTaskImpl where status = 'Reserved'");
query.setTarget("CUSTOM");
queryClient.setResponseHandler(responseHandler);
queryClient.registerQuery(query);
try {
queryClient.setResponseHandler(new RequestReplyResponseHandler());
KieServerSynchronization.waitForQuery(queryClient, query);
List<TaskInstance> tasks = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_TASK, 0, 10, TaskInstance.class);
assertThat(tasks).isNotNull().hasSize(1);
Long taskId = tasks.get(0).getId();
query.setExpression("select * from AuditTaskImpl where status = 'InProgress'");
queryClient.setResponseHandler(responseHandler);
queryClient.replaceQuery(query);
queryClient.setResponseHandler(new RequestReplyResponseHandler());
KieServerSynchronization.waitForQuery(queryClient, query);
tasks = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_TASK, 0, 10, TaskInstance.class);
assertThat(tasks).isNotNull().isEmpty();
taskClient.startTask(CONTAINER_ID, taskId, USER_YODA);
tasks = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_TASK, 0, 10, TaskInstance.class);
assertThat(tasks).isNotNull().hasSize(1);
assertThat(tasks.get(0).getId()).isEqualTo(taskId);
} catch (Exception e) {
queryClient.setResponseHandler(new RequestReplyResponseHandler());
queryClient.unregisterQuery(query.getName());
throw e;
}
queryClient.setResponseHandler(responseHandler);
queryClient.unregisterQuery(query.getName());
queryClient.setResponseHandler(new RequestReplyResponseHandler());
KieServerSynchronization.waitForQueryRemoval(queryClient, query);
}
Aggregations