提交 c419e7da 编写于 作者: F Frederik Heremans

Fixed intermittent failing test + added ProcessEngine lifecycle listener

+ altere JTA-oracle configuration
上级 33c851b4
......@@ -129,6 +129,14 @@
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<!-- Required for testing JTA -->
<dependency>
<groupId>org.codehaus.btm</groupId>
<artifactId>btm</artifactId>
<version>2.1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
......@@ -472,12 +480,6 @@
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.btm</groupId>
<artifactId>btm</artifactId>
<version>2.1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
......
......@@ -128,6 +128,7 @@ public abstract class ProcessEngineConfiguration implements EngineServices {
protected String activityFontName = "Arial";
protected ClassLoader classLoader;
protected ProcessEngineLifecycleListener processEngineLifecycleListener;
/** use one of the static createXxxx methods instead */
protected ProcessEngineConfiguration() {
......@@ -510,6 +511,12 @@ public abstract class ProcessEngineConfiguration implements EngineServices {
public void setActivityFontName(String activityFontName) {
this.activityFontName = activityFontName;
}
public void setProcessEngineLifecycleListener(ProcessEngineLifecycleListener processEngineLifecycleListener) {
this.processEngineLifecycleListener = processEngineLifecycleListener;
}
public ProcessEngineLifecycleListener getProcessEngineLifecycleListener() {
return processEngineLifecycleListener;
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.engine;
/**
* Interface describing a listener that get's notified when certain event occurs,
* related to the process-engine lifecycle it is attached to.
*
* @author Frederik Heremans
*/
public interface ProcessEngineLifecycleListener {
/**
* Called right after the process-engine has been built.
*
* @param processEngine engine that was built
*/
void onProcessEngineBuilt(ProcessEngine processEngine);
/**
* Called right after the process-engine has been closed.
*
* @param processEngine engine that was closed
*/
void onProcessEngineClosed(ProcessEngine processEngine);
}
......@@ -86,6 +86,11 @@ public class ProcessEngineImpl implements ProcessEngine {
if ((jobExecutor != null) && (jobExecutor.isAutoActivate())) {
jobExecutor.start();
}
if(processEngineConfiguration.getProcessEngineLifecycleListener() != null)
{
processEngineConfiguration.getProcessEngineLifecycleListener().onProcessEngineBuilt(this);
}
}
public void close() {
......@@ -95,6 +100,11 @@ public class ProcessEngineImpl implements ProcessEngine {
}
commandExecutor.execute(new SchemaOperationProcessEngineClose());
if(processEngineConfiguration.getProcessEngineLifecycleListener() != null)
{
processEngineConfiguration.getProcessEngineLifecycleListener().onProcessEngineClosed(this);
}
}
public DbSqlSessionFactory getDbSqlSessionFactory() {
......
......@@ -741,7 +741,10 @@ public class ExecutionQueryTest extends PluggableActivitiTestCase {
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Date date2 = Calendar.getInstance().getTime();
Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.SECOND, 1);
Date date2 = cal2.getTime();
vars = new HashMap<String, Object>();
vars.put("dateVar", date1);
vars.put("dateVar2", date2);
......
......@@ -723,7 +723,10 @@ public class ProcessInstanceQueryTest extends PluggableActivitiTestCase {
ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);
Date date2 = Calendar.getInstance().getTime();
Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.SECOND, 1);
Date date2 = cal2.getTime();
vars = new HashMap<String, Object>();
vars.put("dateVar", date1);
vars.put("dateVar2", date2);
......
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.standalone.jta;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineLifecycleListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import bitronix.tm.resource.jdbc.PoolingDataSource;
/**
* Used in JPA-tests to close the XA-datasource after engine is closed, due to internal caching
* of datasource, independant of process-enging/spring-context.
*
* @author Frederik Heremans
*/
public class CloseXADataSourceLifecycleListener implements ProcessEngineLifecycleListener {
private PoolingDataSource dataSource;
private static final Logger LOG = LoggerFactory.getLogger(CloseXADataSourceLifecycleListener.class);
@Override
public void onProcessEngineBuilt(ProcessEngine processEngine) {
LOG.info("--------------------- Callback for engine start");
}
@Override
public void onProcessEngineClosed(ProcessEngine processEngine) {
LOG.info("--------------------- Callback for engine end");
if(dataSource != null) {
LOG.info("--------------------- Closing datasource");
dataSource.close();
}
}
public void setDataSource(PoolingDataSource dataSource) {
this.dataSource = dataSource;
}
}
......@@ -5,7 +5,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource" init-method="init" destroy-method="close">
<bean id="dataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource" destroy-method="close">
<property name="className" value="oracle.jdbc.xa.client.OracleXADataSource" />
<property name="uniqueName" value="xaOracle" />
<property name="maxPoolSize" value="20" />
......@@ -13,8 +13,6 @@
<property name="driverProperties">
<!-- Oracle -->
<props>
<prop key="serverName">@jdbc.servername@</prop>
<prop key="databaseName">@jdbc.databasename@</prop>
<prop key="user">@jdbc.username@</prop>
<prop key="password">@jdbc.password@</prop>
<prop key="URL">@jdbc.url@</prop>
......@@ -29,6 +27,11 @@
<property name="logPart1Filename" value="target/btm1.log"/>
<property name="logPart2Filename" value="target/btm2.log"/>
</bean>
<!-- Listener to close datasource when engine is closed, spring's destroy-method is never called... -->
<bean id="lifecycleListener" class="org.activiti.standalone.jta.CloseXADataSourceLifecycleListener">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- create BTM transaction manager -->
<bean id="transactionManager" factory-method="getTransactionManager" class="bitronix.tm.TransactionManagerServices"
......@@ -40,6 +43,8 @@
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
<property name="mailServerPort" value="5025" />
<property name="processEngineLifecycleListener" ref="lifecycleListener" />
</bean>
</beans>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册