Search in sources :

Example 1 with AsyncResponseHandler

use of org.kie.server.client.jms.AsyncResponseHandler in project droolsjbpm-integration by kiegroup.

the class DroolsJmsResponseHandlerIntegrationTest method testExecuteSimpleRuleFlowProcessWithAsyncResponseHandler.

@Test
public void testExecuteSimpleRuleFlowProcessWithAsyncResponseHandler() {
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<Class<?>>(extraClasses.values()), configuration.getMarshallingFormat(), client.getClassLoader());
    ResponseCallback responseCallback = new BlockingResponseCallback(marshaller);
    ResponseHandler asyncResponseHandler = new AsyncResponseHandler(responseCallback);
    ruleClient.setResponseHandler(asyncResponseHandler);
    List<Command<?>> commands = new ArrayList<Command<?>>();
    commands.add(commandsFactory.newSetGlobal(LIST_NAME, new ArrayList<String>(), LIST_OUTPUT_NAME));
    commands.add(commandsFactory.newStartProcess(PROCESS_ID));
    commands.add(commandsFactory.newGetGlobal(LIST_NAME, LIST_OUTPUT_NAME));
    BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, KIE_SESSION);
    ServiceResponse<?> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
    assertThat(response).isNull();
    ExecutionResults result = responseCallback.get(ExecutionResultImpl.class);
    List<String> outcome = (List<String>) result.getValue(LIST_OUTPUT_NAME);
    assertThat(outcome).isNotNull();
    assertThat(outcome).containsExactly("Rule from first ruleflow group executed", "Rule from second ruleflow group executed");
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) ResponseHandler(org.kie.server.client.jms.ResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) BeforeClass(org.junit.BeforeClass) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test) DroolsKieServerBaseIntegrationTest(org.kie.server.integrationtests.drools.DroolsKieServerBaseIntegrationTest)

Example 2 with AsyncResponseHandler

use of org.kie.server.client.jms.AsyncResponseHandler in project droolsjbpm-integration by kiegroup.

the class JmsResponseHandlerIntegrationTest method testGetTasksUseOfAsyncResponseHandlerWithMarshaller.

@Test
public void testGetTasksUseOfAsyncResponseHandlerWithMarshaller() throws Exception {
    ResponseCallback callback = new BlockingResponseCallback(createMarshaller());
    testGetTaskResponseHandler(new AsyncResponseHandler(callback));
    // now let's check if response has arrived
    TaskSummaryList taskSummaryList = callback.get(TaskSummaryList.class);
    assertThat(taskSummaryList).isNotNull();
    assertThat(taskSummaryList.getItems()).isNotNull().hasSize(1);
}
Also used : AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) TaskSummaryList(org.kie.server.api.model.instance.TaskSummaryList) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 3 with AsyncResponseHandler

use of org.kie.server.client.jms.AsyncResponseHandler in project droolsjbpm-integration by kiegroup.

the class JmsResponseHandlerIntegrationTest method testStartProcessUseOfAsyncResponseHandler.

@Test
public void testStartProcessUseOfAsyncResponseHandler() throws Exception {
    ResponseCallback callback = new BlockingResponseCallback(null);
    testStartProcessResponseHandler(new AsyncResponseHandler(callback));
    // now let's check if response has arrived
    ServiceResponsesList response = callback.get();
    assertThat(response).isNotNull();
    assertThat(response.getResponses()).isNotNull().hasSize(1);
    KieServerAssert.assertSuccess(response.getResponses().get(0));
    ServiceResponse<? extends Object> serviceResponse = response.getResponses().get(0);
    Object result = serviceResponse.getResult();
    assertThat(result).isNotNull();
}
Also used : ServiceResponsesList(org.kie.server.api.model.ServiceResponsesList) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 4 with AsyncResponseHandler

use of org.kie.server.client.jms.AsyncResponseHandler in project droolsjbpm-integration by kiegroup.

the class JmsResponseHandlerIntegrationTest method testStartAndCompleteTaskUseOfAsyncResponseHandler.

@Test
public void testStartAndCompleteTaskUseOfAsyncResponseHandler() throws Exception {
    ResponseCallback callback = new BlockingResponseCallback(null);
    testStartAndCompleteTask(new AsyncResponseHandler(callback));
}
Also used : AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 5 with AsyncResponseHandler

use of org.kie.server.client.jms.AsyncResponseHandler in project droolsjbpm-integration by kiegroup.

the class OptaPlannerJmsResponseHandlerIntegrationTest method testSolverWithAsyncResponseHandler.

@Test
public void testSolverWithAsyncResponseHandler() throws Exception {
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<>(extraClasses.values()), configuration.getMarshallingFormat(), client.getClassLoader());
    ResponseCallback responseCallback = new BlockingResponseCallback(marshaller);
    ResponseHandler asyncResponseHandler = new AsyncResponseHandler(responseCallback);
    solverClient.setResponseHandler(asyncResponseHandler);
    SolverInstance response = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    assertThat(response).isNull();
    SolverInstance solver = responseCallback.get(SolverInstance.class);
    assertThat(solver).isNotNull();
    assertThat(solver.getContainerId()).isEqualTo(CONTAINER_1_ID);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    List<SolverInstance> solverInstanceList = solverClient.getSolvers(CONTAINER_1_ID);
    assertThat(solverInstanceList).isNull();
    SolverInstanceList solverList = responseCallback.get(SolverInstanceList.class);
    assertThat(solverList).isNotNull();
    assertThat(solverList.getContainers()).isNotNull().isNotEmpty().hasSize(1);
    solver = solverList.getContainers().get(0);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(5, 15));
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertThat(response).isNull();
    solver = responseCallback.get(SolverInstance.class);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isEqualTo(SolverInstance.SolverStatus.SOLVING);
    solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    response = solverClient.getSolver(CONTAINER_1_ID, SOLVER_1_ID);
    assertThat(response).isNull();
    solver = responseCallback.get(SolverInstance.class);
    assertThat(solver.getSolverId()).isEqualTo(SOLVER_1_ID);
    assertThat(solver.getStatus()).isIn(SolverInstance.SolverStatus.TERMINATING_EARLY, SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
    // Make sure the service call result is consumed
    responseCallback.get(Void.class);
    solverClient.getSolvers(CONTAINER_1_ID);
    assertThat(response).isNull();
    solverList = responseCallback.get(SolverInstanceList.class);
    assertThat(solverList).isNotNull();
    assertThat(solverList.getContainers()).isNullOrEmpty();
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) Marshaller(org.kie.server.api.marshalling.Marshaller) ResponseHandler(org.kie.server.client.jms.ResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) ResponseCallback(org.kie.server.client.jms.ResponseCallback) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) SolverInstanceList(org.kie.server.api.model.instance.SolverInstanceList) OptaplannerKieServerBaseIntegrationTest(org.kie.server.integrationtests.optaplanner.OptaplannerKieServerBaseIntegrationTest) Test(org.junit.Test)

Aggregations

AsyncResponseHandler (org.kie.server.client.jms.AsyncResponseHandler)10 BlockingResponseCallback (org.kie.server.client.jms.BlockingResponseCallback)10 Test (org.junit.Test)9 ResponseCallback (org.kie.server.client.jms.ResponseCallback)9 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)7 Marshaller (org.kie.server.api.marshalling.Marshaller)3 FireAndForgetResponseHandler (org.kie.server.client.jms.FireAndForgetResponseHandler)3 BeforeClass (org.junit.BeforeClass)2 RequestReplyResponseHandler (org.kie.server.client.jms.RequestReplyResponseHandler)2 ResponseHandler (org.kie.server.client.jms.ResponseHandler)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Before (org.junit.Before)1 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)1 Command (org.kie.api.command.Command)1 ExecutionResults (org.kie.api.runtime.ExecutionResults)1 ServiceResponsesList (org.kie.server.api.model.ServiceResponsesList)1 ProcessInstanceList (org.kie.server.api.model.instance.ProcessInstanceList)1 SolverInstance (org.kie.server.api.model.instance.SolverInstance)1 SolverInstanceList (org.kie.server.api.model.instance.SolverInstanceList)1