use of org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy in project jbpm by kiegroup.
the class ProcessInstanceResolverStrategyTest method before.
@Before
public void before() {
context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
// load up the knowledge base
Environment env = PersistenceUtil.createEnvironment(context);
env.set(OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new ProcessInstanceResolverStrategy(), new JPAPlaceholderResolverStrategy(env), new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
if (useLocking) {
env.set(USE_PESSIMISTIC_LOCKING, true);
}
KieBase kbase = loadKnowledgeBase();
// create session
ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
Assert.assertTrue("Valid KnowledgeSession could not be created.", ksession != null && ksession.getIdentifier() > 0);
}
use of org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy in project jbpm by kiegroup.
the class SimpleRuntimeEnvironment method copyEnvironment.
protected Environment copyEnvironment() {
Environment copy = EnvironmentFactory.newEnvironment();
addIfPresent(EnvironmentName.ENTITY_MANAGER_FACTORY, copy);
addIfPresent(EnvironmentName.CALENDARS, copy);
addIfPresent(EnvironmentName.DATE_FORMATS, copy);
addIfPresent(EnvironmentName.GLOBALS, copy);
addIfPresent(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, copy);
addIfPresent(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, copy);
addIfPresent(EnvironmentName.TASK_PERSISTENCE_CONTEXT_MANAGER, copy);
addIfPresent(EnvironmentName.TRANSACTION_MANAGER, copy);
addIfPresent(EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY, copy);
addIfPresent(EnvironmentName.TRANSACTION, copy);
addIfPresent(EnvironmentName.USE_LOCAL_TRANSACTIONS, copy);
addIfPresent(EnvironmentName.USE_PESSIMISTIC_LOCKING, copy);
addIfPresent(EnvironmentName.EXEC_ERROR_MANAGER, copy);
addIfPresent(EnvironmentName.DEPLOYMENT_ID, copy);
if (usePersistence()) {
ObjectMarshallingStrategy[] strategies = (ObjectMarshallingStrategy[]) copy.get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES);
List<ObjectMarshallingStrategy> listStrategies = new ArrayList<ObjectMarshallingStrategy>(Arrays.asList(strategies));
listStrategies.add(0, new ProcessInstanceResolverStrategy());
strategies = new ObjectMarshallingStrategy[listStrategies.size()];
copy.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, listStrategies.toArray(strategies));
}
// copy if present in environment template which in general should not be used
// unless with some framework support to make EM thread safe - like spring
addIfPresent(EnvironmentName.APP_SCOPED_ENTITY_MANAGER, copy);
addIfPresent(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER, copy);
addIfPresent("IS_JTA_TRANSACTION", copy);
addIfPresent("IS_TIMER_CMT", copy);
addIfPresent("IS_SHARED_ENTITY_MANAGER", copy);
addIfPresent("TRANSACTION_LOCK_ENABLED", copy);
addIfPresent("IdentityProvider", copy);
addIfPresent("jbpm.business.calendar", copy);
// handle for custom environment entries that might be required by non engine use cases
if (!environmentEntries.isEmpty()) {
for (Entry<String, Object> entry : environmentEntries.entrySet()) {
// don't override
if (copy.get(entry.getKey()) != null) {
continue;
}
copy.set(entry.getKey(), entry.getValue());
}
}
return copy;
}
use of org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy in project jbpm by kiegroup.
the class ProcessInstanceResolverStrategyTest method testProcessInstanceResolverStrategy.
@Test
public void testProcessInstanceResolverStrategy() throws Exception {
// Setup
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource(PROCESS_NAME, this.getClass()), ResourceType.DRF);
KieBase kbase = kbuilder.newKieBase();
KieSession ksession = kbase.newKieSession();
ProcessInstance processInstance = ksession.createProcessInstance("process name", new HashMap<String, Object>());
ksession.insert(processInstance);
// strategy setup
ProcessInstanceResolverStrategy strategy = new ProcessInstanceResolverStrategy();
ObjectMarshallingStrategy[] strategies = { strategy, MarshallerFactory.newSerializeMarshallingStrategy() };
// Test strategy.write
org.kie.api.marshalling.MarshallingConfiguration marshallingConfig = new MarshallingConfigurationImpl(strategies, true, true);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
MarshallerWriteContext writerContext = new MarshallerWriteContext(baos, ((InternalKnowledgeBase) kbase), (InternalWorkingMemory) ((StatefulKnowledgeSessionImpl) ksession), RuleBaseNodes.getNodeMap(((InternalKnowledgeBase) kbase)), marshallingConfig.getObjectMarshallingStrategyStore(), marshallingConfig.isMarshallProcessInstances(), marshallingConfig.isMarshallWorkItems(), ksession.getEnvironment());
strategy.write(writerContext, processInstance);
baos.close();
writerContext.close();
byte[] bytes = baos.toByteArray();
int numCorrectBytes = calculateNumBytesForLong(processInstance.getId());
assertTrue("Expected " + numCorrectBytes + " bytes, not " + bytes.length, bytes.length == numCorrectBytes);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
long serializedProcessInstanceId = ois.readLong();
assertTrue("Expected " + processInstance.getId() + ", not " + serializedProcessInstanceId, processInstance.getId() == serializedProcessInstanceId);
// Test other strategy stuff
ProcessInstanceManager pim = ProcessInstanceResolverStrategy.retrieveProcessInstanceManager(writerContext);
assertNotNull(pim);
assertNotNull(ProcessInstanceResolverStrategy.retrieveKnowledgeRuntime(writerContext));
assertTrue(processInstance == pim.getProcessInstance(serializedProcessInstanceId));
// Test strategy.read
bais = new ByteArrayInputStream(bytes);
MarshallerReaderContext readerContext = new MarshallerReaderContext(bais, ((KnowledgeBaseImpl) kbase), RuleBaseNodes.getNodeMap(((KnowledgeBaseImpl) kbase)), marshallingConfig.getObjectMarshallingStrategyStore(), ProtobufMarshaller.TIMER_READERS, marshallingConfig.isMarshallProcessInstances(), marshallingConfig.isMarshallWorkItems(), EnvironmentFactory.newEnvironment());
readerContext.wm = ((StatefulKnowledgeSessionImpl) ksession).getInternalWorkingMemory();
Object procInstObject = strategy.read(readerContext);
assertTrue(procInstObject != null && procInstObject instanceof ProcessInstance);
assertTrue(processInstance == procInstObject);
}
use of org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy in project jbpm by kiegroup.
the class ProcessInstanceResolverStrategyTest method testAccept.
@Test
public void testAccept() {
KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
KieSession ksession = kbase.newKieSession();
WorkflowProcessImpl process = new WorkflowProcessImpl();
RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
processInstance.setState(ProcessInstance.STATE_ACTIVE);
processInstance.setProcess(process);
processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
ProcessInstanceResolverStrategy strategy = new ProcessInstanceResolverStrategy();
assertTrue(strategy.accept(processInstance));
Object object = new Object();
assertTrue(!strategy.accept(object));
}
use of org.jbpm.marshalling.impl.ProcessInstanceResolverStrategy in project jbpm by kiegroup.
the class JbpmBpmn2TestCase method createEnvironment.
protected Environment createEnvironment(EntityManagerFactory emf) {
Environment env = EnvironmentFactory.newEnvironment();
env.set(ENTITY_MANAGER_FACTORY, emf);
env.set(TRANSACTION_MANAGER, com.arjuna.ats.jta.TransactionManager.transactionManager());
if (sessionPersistence) {
ObjectMarshallingStrategy[] strategies = (ObjectMarshallingStrategy[]) env.get(OBJECT_MARSHALLING_STRATEGIES);
List<ObjectMarshallingStrategy> listStrategies = new ArrayList<ObjectMarshallingStrategy>(Arrays.asList(strategies));
listStrategies.add(0, new ProcessInstanceResolverStrategy());
strategies = new ObjectMarshallingStrategy[listStrategies.size()];
env.set(OBJECT_MARSHALLING_STRATEGIES, listStrategies.toArray(strategies));
}
return env;
}
Aggregations