Search in sources :

Example 1 with RequestReplyResponseHandler

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);
}
Also used : FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) Test(org.junit.Test) DroolsKieServerBaseIntegrationTest(org.kie.server.integrationtests.drools.DroolsKieServerBaseIntegrationTest)

Example 2 with RequestReplyResponseHandler

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());
}
Also used : RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) After(org.junit.After)

Example 3 with 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);
}
Also used : RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance)

Example 4 with RequestReplyResponseHandler

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);
}
Also used : RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) TaskSummary(org.kie.server.api.model.instance.TaskSummary) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance)

Example 5 with RequestReplyResponseHandler

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);
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) TaskInstance(org.kie.server.api.model.instance.TaskInstance) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) HashMap(java.util.HashMap)

Aggregations

RequestReplyResponseHandler (org.kie.server.client.jms.RequestReplyResponseHandler)7 Test (org.junit.Test)2 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)2 FireAndForgetResponseHandler (org.kie.server.client.jms.FireAndForgetResponseHandler)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 After (org.junit.After)1 ExecutionResults (org.kie.api.runtime.ExecutionResults)1 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)1 SolverInstance (org.kie.server.api.model.instance.SolverInstance)1 TaskInstance (org.kie.server.api.model.instance.TaskInstance)1 TaskSummary (org.kie.server.api.model.instance.TaskSummary)1 ResponseHandler (org.kie.server.client.jms.ResponseHandler)1 DroolsKieServerBaseIntegrationTest (org.kie.server.integrationtests.drools.DroolsKieServerBaseIntegrationTest)1 OptaplannerKieServerBaseIntegrationTest (org.kie.server.integrationtests.optaplanner.OptaplannerKieServerBaseIntegrationTest)1