Search in sources :

Example 1 with FireAndForgetResponseHandler

use of org.kie.server.client.jms.FireAndForgetResponseHandler 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 FireAndForgetResponseHandler

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

the class OptaPlannerJmsResponseHandlerIntegrationTest method testSolverWithFireAndForgetResponseHandler.

@Test
public void testSolverWithFireAndForgetResponseHandler() throws Exception {
    solverClient.setResponseHandler(new FireAndForgetResponseHandler());
    SolverInstance solverInstance = solverClient.createSolver(CONTAINER_1_ID, SOLVER_1_ID, SOLVER_1_CONFIG);
    assertThat(solverInstance).isNull();
    solverClient.setResponseHandler(new RequestReplyResponseHandler());
    KieServerSynchronization.waitForSolver(solverClient, CONTAINER_1_ID, SOLVER_1_ID);
    solverClient.setResponseHandler(new FireAndForgetResponseHandler());
    solverClient.solvePlanningProblem(CONTAINER_1_ID, SOLVER_1_ID, loadPlanningProblem(5, 15));
    solverClient.setResponseHandler(new RequestReplyResponseHandler());
    KieServerSynchronization.waitForSolverStatus(solverClient, CONTAINER_1_ID, SOLVER_1_ID, SolverInstance.SolverStatus.SOLVING);
    solverClient.setResponseHandler(new FireAndForgetResponseHandler());
    solverClient.terminateSolverEarly(CONTAINER_1_ID, SOLVER_1_ID);
    solverClient.setResponseHandler(new RequestReplyResponseHandler());
    KieServerSynchronization.waitForSolverStatus(solverClient, CONTAINER_1_ID, SOLVER_1_ID, SolverInstance.SolverStatus.NOT_SOLVING);
    solverClient.setResponseHandler(new FireAndForgetResponseHandler());
    solverClient.disposeSolver(CONTAINER_1_ID, SOLVER_1_ID);
    solverClient.setResponseHandler(new RequestReplyResponseHandler());
    KieServerSynchronization.waitForSolverDispose(solverClient, CONTAINER_1_ID, SOLVER_1_ID);
    List<SolverInstance> solverInstanceList = solverClient.getSolvers(CONTAINER_1_ID);
    assertThat(solverInstanceList).isNullOrEmpty();
}
Also used : SolverInstance(org.kie.server.api.model.instance.SolverInstance) FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) RequestReplyResponseHandler(org.kie.server.client.jms.RequestReplyResponseHandler) OptaplannerKieServerBaseIntegrationTest(org.kie.server.integrationtests.optaplanner.OptaplannerKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 3 with FireAndForgetResponseHandler

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

the class ContainerJmsResponseHandlerIntegrationTest method setupClients.

@Before
public void setupClients() throws Exception {
    asyncClient = createDefaultClient();
    Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<Class<?>>(extraClasses.values()), configuration.getMarshallingFormat(), asyncClient.getClassLoader());
    responseCallback = new BlockingResponseCallback(marshaller);
    asyncClient.setResponseHandler(new AsyncResponseHandler(responseCallback));
    fireAndForgetClient = createDefaultClient();
    fireAndForgetClient.setResponseHandler(new FireAndForgetResponseHandler());
}
Also used : FireAndForgetResponseHandler(org.kie.server.client.jms.FireAndForgetResponseHandler) Marshaller(org.kie.server.api.marshalling.Marshaller) AsyncResponseHandler(org.kie.server.client.jms.AsyncResponseHandler) BlockingResponseCallback(org.kie.server.client.jms.BlockingResponseCallback) BeforeClass(org.junit.BeforeClass) Before(org.junit.Before)

Aggregations

FireAndForgetResponseHandler (org.kie.server.client.jms.FireAndForgetResponseHandler)3 Test (org.junit.Test)2 RequestReplyResponseHandler (org.kie.server.client.jms.RequestReplyResponseHandler)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 BeforeClass (org.junit.BeforeClass)1 ExecutionResults (org.kie.api.runtime.ExecutionResults)1 Marshaller (org.kie.server.api.marshalling.Marshaller)1 SolverInstance (org.kie.server.api.model.instance.SolverInstance)1 AsyncResponseHandler (org.kie.server.client.jms.AsyncResponseHandler)1 BlockingResponseCallback (org.kie.server.client.jms.BlockingResponseCallback)1 DroolsKieServerBaseIntegrationTest (org.kie.server.integrationtests.drools.DroolsKieServerBaseIntegrationTest)1 OptaplannerKieServerBaseIntegrationTest (org.kie.server.integrationtests.optaplanner.OptaplannerKieServerBaseIntegrationTest)1