Permalink
Browse files

fixed failing tests

  • Loading branch information...
1 parent c3e8844 commit 71c21578da8151289a0c121261a96ae9bfbdcc19 @mswiderski mswiderski committed Dec 19, 2012
@@ -32,13 +32,16 @@
import org.drools.SessionConfiguration;
import org.drools.StatefulSession;
import org.drools.compiler.PackageBuilder;
+import org.drools.impl.EnvironmentFactory;
import org.drools.rule.Package;
import org.hibernate.service.jta.platform.internal.TransactionManagerAccess;
import org.hibernate.transaction.TransactionManagerLookup;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.kie.runtime.Environment;
+import org.kie.runtime.EnvironmentName;
import bitronix.tm.BitronixTransactionManager;
import bitronix.tm.TransactionManagerServices;
@@ -57,6 +60,9 @@
@Before
public void setUp() throws Exception {
context = setupWithPoolingDataSource(JBPM_PERSISTENCE_UNIT_NAME);
+ Environment env = EnvironmentFactory.newEnvironment();
+ env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, context.get(EnvironmentName.ENTITY_MANAGER_FACTORY));
+ JPAProcessInstanceDbLog.setEnvironment(env);
}
@After
@@ -86,7 +86,7 @@
</properties>
</persistence-unit>
- <persistence-unit name="org.jbpm.persistence.local" transaction-type="RESOURCE_LOCAL">
+ <persistence-unit name="org.jbpm.persistence.local" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/jbpm-local-ds</jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
@@ -139,7 +139,9 @@
<property name="hibernate.connection.password" value="${maven.jdbc.password}" />
<!-- BZ 841786: AS7/EAP 6/Hib 4 uses new (sequence) generators which seem to cause problems -->
- <property name="hibernate.id.new_generator_mappings" value="false" />
+ <property name="hibernate.id.new_generator_mappings" value="false" />
+ <!-- The following line is what's used in Hibernate 4 instead of a TransactionManagerLookup class -->
+ <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.BitronixJtaPlatform" />
</properties>
</persistence-unit>
@@ -15,9 +15,12 @@
import java.util.List;
import java.util.Map;
+import javax.naming.InitialContext;
+import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.transaction.TransactionManager;
+import javax.transaction.UserTransaction;
import org.drools.common.InternalKnowledgeRuntime;
import org.drools.marshalling.impl.MarshallingConfigurationImpl;
@@ -56,6 +59,7 @@
public class SerializedTimerRollbackTest {
private PoolingDataSource ds;
+ private EntityManagerFactory emf;
@Before
public void setup() {
@@ -69,10 +73,23 @@ public void setup() {
ds.getDriverProperties().put( "URL", "jdbc:h2:mem:mydb" );
ds.init();
UserGroupCallbackManager.getInstance().setCallback(null);
+
+ emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
+ try {
+ UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
+ ut.begin();
+ EntityManager em = emf.createEntityManager().getEntityManagerFactory().createEntityManager();
+ em.createQuery("delete from SessionInfo").executeUpdate();
+ em.close();
+ ut.commit();
+ } catch (Exception e) {
+
+ }
}
@After
public void tearDown() {
+ emf.close();
ds.close();
}
@@ -81,10 +98,8 @@ public void testSerizliableTestsWithExternalRollback() {
try {
Environment env = KnowledgeBaseFactory.newEnvironment();
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
- TransactionManager tm = TransactionManagerServices.getTransactionManager();
- System.out.println("Created JPA EntityManager");
+ TransactionManager tm = TransactionManagerServices.getTransactionManager();
env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager() );
TaskService taskService = new org.jbpm.task.service.TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
@@ -96,7 +111,6 @@ public void testSerizliableTestsWithExternalRollback() {
org.jbpm.task.TaskService humanTaskClient = new LocalTaskService(taskService);;
System.out.println("Task service created");
-
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("HumanTaskWithBoundaryTimer.bpmn"),ResourceType.BPMN2);
if (kbuilder.getErrors()!=null){
@@ -151,21 +165,18 @@ public void testSerizliableTestsWithExternalRollback() {
for (TimerInstance timerInstance : timers) {
assertTrue(committedProcessInstanceIds.contains(timerInstance.getProcessInstanceId()));
}
-
} catch (Exception e){
e.printStackTrace();
fail("Exception thrown");
}
+
}
@Test
public void testSerizliableTestsWithEngineRollback() {
try {
- Environment env = KnowledgeBaseFactory.newEnvironment();
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
- System.out.println("Created JPA EntityManager");
-
+ Environment env = KnowledgeBaseFactory.newEnvironment();
env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager() );
TaskService taskService = new org.jbpm.task.service.TaskService(emf, SystemEventListenerFactory.getSystemEventListener());
@@ -239,7 +250,6 @@ public void testSerizliableTestsWithEngineRollback() {
for (TimerInstance timerInstance : timers) {
assertTrue(committedProcessInstanceIds.contains(timerInstance.getProcessInstanceId()));
}
-
} catch (Exception e){
e.printStackTrace();
fail("Exception thrown");

0 comments on commit 71c2157

Please sign in to comment.