Skip to content

Commit

Permalink
BZ-1153664 - Cannot use pessimistic locking with kie-spring (fixed fa…
Browse files Browse the repository at this point in the history
…iling test)

(cherry picked from commit c151ff2)
  • Loading branch information
Marco Rietveld committed Oct 29, 2014
1 parent d1a9652 commit c56194f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 139 deletions.
Expand Up @@ -3,36 +3,47 @@
import java.io.File;
import java.io.FilenameFilter;

import bitronix.tm.resource.jdbc.PoolingDataSource;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import bitronix.tm.resource.jdbc.PoolingDataSource;

public abstract class AbstractJbpmSpringTest {

protected PoolingDataSource pds;
protected static PoolingDataSource pds;
protected ClassPathXmlApplicationContext context;

@BeforeClass
public static void generalSetup() {
pds = setupPoolingDataSource();
}

@Before
public void setup() {
cleanupSingletonSessionId();
System.setProperty("java.naming.factory.initial", "bitronix.tm.jndi.BitronixInitialContextFactory");
pds = setupPoolingDataSource();
}

@After
public void cleanup() {
if (pds != null) {
pds.close();
}
if (context != null) {
context.close();
context = null;
}
System.clearProperty("java.naming.factory.initial");
}

@AfterClass
public static void generalCleanup() {
if (pds != null) {
pds.close();
}
}

protected PoolingDataSource setupPoolingDataSource() {
protected static PoolingDataSource setupPoolingDataSource() {
PoolingDataSource pds = new PoolingDataSource();
pds.setUniqueName("jdbc/jbpm-ds");
pds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
Expand Down
@@ -1,10 +1,15 @@
package org.kie.spring.jbpm;

import java.lang.reflect.Field;
import java.util.List;

import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession;
import org.drools.persistence.SingleSessionCommandService;
import org.jbpm.process.audit.AuditLogService;
import org.jbpm.process.audit.ProcessInstanceLog;
import org.junit.Test;
import org.kie.api.runtime.Environment;
import org.kie.api.runtime.EnvironmentName;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.manager.RuntimeEngine;
import org.kie.api.runtime.manager.RuntimeManager;
Expand All @@ -19,7 +24,6 @@ public class EntityManagerFactorySpringJpaTxManagerTest extends AbstractJbpmSpri

@Test
public void testSpringWithJpa() throws Exception{

context = new ClassPathXmlApplicationContext("jbpm/jpa/jpa-spring.xml");

RuntimeManager manager = (RuntimeManager) context.getBean("runtimeManager");
Expand All @@ -28,6 +32,8 @@ public void testSpringWithJpa() throws Exception{
KieSession ksession = engine.getKieSession();
TaskService taskService = engine.getTaskService();

validatePessimisticLockingUse(ksession);

ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");

System.out.println("Process started");
Expand Down Expand Up @@ -57,4 +63,19 @@ public void testSpringWithJpa() throws Exception{
System.out.println("Process instance completed");
}

private void validatePessimisticLockingUse(KieSession ksession) throws Exception {
// do an ugly hack to get the info
CommandBasedStatefulKnowledgeSession cmdBasedKsession = (CommandBasedStatefulKnowledgeSession) ksession;
SingleSessionCommandService sscs = (SingleSessionCommandService) cmdBasedKsession.getCommandService();
// yes, this will break some day, and when it does, just delete this entire test, which isn't that good anyways.. :/
Field envField = SingleSessionCommandService.class.getDeclaredField("env");
envField.setAccessible(true);
Environment env = (Environment) envField.get(sscs);

// verify pessimistic lockings
Boolean pessLocking = (Boolean) env.get(EnvironmentName.USE_PESSIMISTIC_LOCKING);
assertNotNull( "Pessimistic locking not set in the environment: null object", pessLocking );
assertTrue( "Pessimistic locking not set in the environment: null object", pessLocking );
}

}

This file was deleted.

50 changes: 0 additions & 50 deletions kie-spring/src/test/resources/jbpm/jpa/jpa-locking-spring.xml

This file was deleted.

1 change: 1 addition & 0 deletions kie-spring/src/test/resources/jbpm/jpa/jpa-spring.xml
Expand Up @@ -25,6 +25,7 @@
<!-- <property name="entityManager" ref="sharedEntityManagerBean"/>-->
<property name="entityManagerFactory" ref="entityManagerFactoryBpmn"/>
<property name="transactionManager" ref="txManager"/>
<property name="pessimisticLocking" value="true"/>
<property name="assets">
<map>
<entry key-ref="process"><util:constant static-field="org.kie.api.io.ResourceType.BPMN2"/></entry>
Expand Down

0 comments on commit c56194f

Please sign in to comment.