use of org.kie.api.runtime.RequestContext in project drools by kiegroup.
the class BatchRunFluentTest method testSetAndGetWithCommandRegisterWithEnds.
@Test
public void testSetAndGetWithCommandRegisterWithEnds() {
ExecutableBuilder f = ExecutableBuilder.create();
f.newApplicationContext("app1").getKieContainer(releaseId).newSession().set("s1").end().getKieContainer(releaseId).newSession().set("s2").end().get("s1", KieSessionFluent.class).insert("h1").fireAllRules().end().get("s2", KieSessionFluent.class).insert("h2").fireAllRules().end().get("s1", KieSessionFluent.class).getGlobal("outS").out("outS1").dispose().get("s2", KieSessionFluent.class).getGlobal("outS").out("outS2").dispose();
RequestContext requestContext = ExecutableRunner.create().execute(f.getExecutable());
// Check that nothing went to the 'out'
assertEquals("h1", requestContext.get("outS1"));
assertEquals("h2", requestContext.get("outS2"));
}
use of org.kie.api.runtime.RequestContext in project drools by kiegroup.
the class ExecuteCommandDisconnectedTest method executeDisconnected.
@Test
public void executeDisconnected() {
KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
ExecutionResultImpl localKresults = new ExecutionResultImpl();
RequestContext context = RequestContext.create().with(ksession);
ExecutableRunner runner = ExecutableRunner.create();
List cmds = new ArrayList();
cmds.add(new InsertObjectCommand(new String("Hi!"), "handle"));
BatchExecutionCommand batchCmd = CommandFactory.newBatchExecution(cmds, "kresults");
ExecuteCommand execCmd = new ExecuteCommand(batchCmd, true);
ExecutionResults results = execCmd.execute(context);
assertNotNull(results);
assertNotNull(results.getFactHandle("handle"));
assertTrue(((DefaultFactHandle) results.getFactHandle("handle")).isDisconnected());
cmds = new ArrayList();
cmds.add(new InsertObjectCommand(new String("Hi!"), "handle"));
batchCmd = CommandFactory.newBatchExecution(cmds, "kresults");
execCmd = new ExecuteCommand(batchCmd);
results = execCmd.execute(context);
assertNotNull(results);
assertNotNull(results.getFactHandle("handle"));
assertFalse(((DefaultFactHandle) results.getFactHandle("handle")).isDisconnected());
}
use of org.kie.api.runtime.RequestContext in project drools by kiegroup.
the class PersistableRunner method createContext.
public RequestContext createContext() {
RequestContext context = RequestContext.create(ksession.getClass().getClassLoader()).with(this.ksession);
context.set(EntryPointCreator.class.getName(), new CommandBasedEntryPointCreator(runner));
return context;
}
use of org.kie.api.runtime.RequestContext in project drools by kiegroup.
the class StatefulKnowledgeSessionImpl method execute.
public <T> T execute(Command<T> command) {
ExecutableRunner<RequestContext> runner = ExecutableRunner.create();
RequestContext context = runner.createContext().with(this.kBase).with(this);
if (!(command instanceof BatchExecutionCommand)) {
return runner.execute(command, context);
}
try {
startBatchExecution();
return runner.execute(command, context);
} finally {
endBatchExecution();
if (kBase.flushModifications()) {
fireAllRules();
}
}
}
use of org.kie.api.runtime.RequestContext in project drools by kiegroup.
the class BatchRunFluentTest method testConversationScope.
@Test
public void testConversationScope() {
ExecutableRunner<RequestContext> runner = ExecutableRunner.create();
ExecutableBuilder f = ExecutableBuilder.create();
f.newApplicationContext("app1").startConversation().getKieContainer(releaseId).newSession().insert("h1").fireAllRules().getGlobal("outS").set("outS1", Scope.CONVERSATION).dispose();
RequestContextImpl requestContext = (RequestContextImpl) runner.execute(f.getExecutable());
// check that nothing went to the 'out'
assertEquals(null, requestContext.get("outS"));
String conversationId = requestContext.getConversationContext().getName();
assertEquals("h1", requestContext.getConversationContext().get("outS1"));
// Make another request, add to conversation context, assert old and new values are there.
f = new ExecutableBuilderImpl();
f.getApplicationContext("app1").joinConversation(conversationId).getKieContainer(releaseId).newSession().insert("h2").fireAllRules().getGlobal("outS").set("outS2", Scope.CONVERSATION).dispose();
requestContext = (RequestContextImpl) runner.execute(f.getExecutable());
assertEquals("h1", requestContext.getConversationContext().get("outS1"));
assertEquals("h2", requestContext.getConversationContext().get("outS2"));
// End the conversation, check it's now null
f = new ExecutableBuilderImpl();
f.endConversation(conversationId);
requestContext = (RequestContextImpl) runner.execute(f.getExecutable());
assertNull(requestContext.getConversationContext());
}
Aggregations