Skip to content

Commit

Permalink
Added 5.11-specific tests to the upgrade job. Fixed upgrade scripts t…
Browse files Browse the repository at this point in the history
…o cope with not compiling new methods in old activiti versions.
  • Loading branch information
jbarrez committed Nov 28, 2012
1 parent 345d620 commit 99314ae
Show file tree
Hide file tree
Showing 30 changed files with 5,580 additions and 398 deletions.
Expand Up @@ -6,9 +6,7 @@

<process id="processDescription">

<documentation>
This is really good process documentation!
</documentation>
<documentation><![CDATA[This is really good process documentation!]]></documentation>

<startEvent id="start" />

Expand Down
2 changes: 1 addition & 1 deletion modules/activiti-upgrade/pom.xml
Expand Up @@ -199,7 +199,7 @@
</path>
</sql>
<echo message="generating data in ${upgradeVersion}" />
<java classname="org.activiti.upgrade.UpgradeDataGenerator" fork="true">
<java classname="org.activiti.upgrade.data.UpgradeDataGenerator" fork="true">
<arg line="${database} ${upgradeVersion}"/>
<classpath>
<path path="${test_classpath}"/>
Expand Down
Expand Up @@ -51,39 +51,43 @@ public class CleanPostgres {
"drop table ACT_ID_USER cascade;"};

public static void main(String[] args) {
if ("postgres".equals(args[0])) {
CleanPostgres cleanPostgres = new CleanPostgres();
cleanPostgres.execute();
}
}

public void execute() {
try {
if ("postgres".equals(args[0])) {
ProcessEngineConfigurationImpl processEngineConfiguration = UpgradeTestCase.createProcessEngineConfiguration("postgres");
processEngineConfiguration.buildProcessEngine();
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Object>() {
ProcessEngineConfigurationImpl processEngineConfiguration = UpgradeUtil.createProcessEngineConfiguration("postgres");
processEngineConfiguration.buildProcessEngine();
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Object>() {

public Object execute(CommandContext commandContext) {
try {
Connection connection = commandContext.getSession(DbSqlSession.class).getSqlSession().getConnection();
connection.setAutoCommit(false);
public Object execute(CommandContext commandContext) {
try {
Connection connection = commandContext.getSession(DbSqlSession.class).getSqlSession().getConnection();
connection.setAutoCommit(false);

for (String cleanStatement : cleanStatements) {
try {
PreparedStatement preparedStatement = connection.prepareStatement(cleanStatement);
preparedStatement.execute();
connection.commit();
log.info("executed ["+cleanStatement+"] successfully");
for (String cleanStatement : cleanStatements) {
try {
PreparedStatement preparedStatement = connection.prepareStatement(cleanStatement);
preparedStatement.execute();
connection.commit();
log.info("executed [" + cleanStatement + "] successfully");

} catch (Exception e) {
log.info("ERROR WHILE EXECUTING ["+cleanStatement+"]:");
e.printStackTrace();
connection.rollback();
}
} catch (Exception e) {
log.info("ERROR WHILE EXECUTING [" + cleanStatement + "]:");
e.printStackTrace();
connection.rollback();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
} catch (Exception e) {
e.printStackTrace();
}
});
}

return null;
}
});
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
@@ -0,0 +1,58 @@
/* 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.upgrade;

import java.io.FileInputStream;
import java.util.Properties;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;

/**
* @author Joram Barrez
*/
public class UpgradeUtil {

/**
* Returns the number after the 5. of the process engine version. Ie 5.11 -> 11
*/
public static int getProcessEngineVersion(ProcessEngine processEngine) {
return Integer.parseInt(processEngine.VERSION.toLowerCase()
.replace("-snapshot", "")
.replace("5.", ""));
}

public static ProcessEngineConfigurationImpl createProcessEngineConfiguration(String database) throws Exception {
ProcessEngineConfigurationImpl processEngineConfiguration;
processEngineConfiguration = (ProcessEngineConfigurationImpl) ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration()
.setDatabaseSchemaUpdate("true")
.setHistory("full")
.setJobExecutorActivate(false);

// loading properties
String propertiesFileName = System.getProperty("user.home")+System.getProperty("file.separator")+".activiti"+System.getProperty("file.separator")+"upgrade"+System.getProperty("file.separator")+"build."+database+".properties";
Properties properties = new Properties();
properties.load(new FileInputStream(propertiesFileName));

// configure the jdbc parameters in the process engine configuration
processEngineConfiguration.setJdbcDriver(properties.getProperty("jdbc.driver"));
processEngineConfiguration.setJdbcUrl(properties.getProperty("jdbc.url"));
processEngineConfiguration.setJdbcUsername(properties.getProperty("jdbc.username"));
processEngineConfiguration.setJdbcPassword(properties.getProperty("jdbc.password"));

return processEngineConfiguration;
}

}
@@ -0,0 +1,57 @@
/* 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.upgrade.data;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;

/**
* @author Joram Barrez
*/
public class Activiti_5_10_DataGenerator implements DataGenerator {

protected ProcessEngine processEngine;

public static int NR_OF_INSTANCES_FOR_SUSPENSION = 5;

public void run() {

// VerifyProcessDefinitionDescriptionTest
processEngine.getRepositoryService()
.createDeployment()
.name("verifyProcessDefinitionDescription")
.addClasspathResource("org/activiti/upgrade/test/VerifyProcessDefinitionDescriptionTest.bpmn20.xml")
.deploy();

// SuspendAndActivateFunctionalityTest
// Deploy test process, and start a few process instances
Deployment deployment = processEngine.getRepositoryService().createDeployment()
.name(Activiti_5_10_DataGenerator.class.getName())
.addClasspathResource("org/activiti/upgrade/test/SuspendAndActivateUpgradeTest.bpmn20.xml")
.deploy();

ProcessDefinition processDefinition = processEngine.getRepositoryService().createProcessDefinitionQuery()
.deploymentId(deployment.getId())
.singleResult();

for (int i=0; i<NR_OF_INSTANCES_FOR_SUSPENSION; i++) {
processEngine.getRuntimeService().startProcessInstanceById(processDefinition.getId());
}
}

public void setProcessEngine(org.activiti.engine.ProcessEngine processEngine) {
this.processEngine = processEngine;
};

}
@@ -0,0 +1,60 @@
/* 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.upgrade.data;

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;

/**
* @author Joram Barrez
*/
public class CommonDataGenerator implements DataGenerator {

protected ProcessEngine processEngine;

public void run() {

// UpgradeTaskOneTest
RuntimeService runtimeService = processEngine.getRuntimeService();
TaskService taskService = processEngine.getTaskService();

processEngine.getRepositoryService()
.createDeployment()
.name("simpleTaskProcess")
.addClasspathResource("org/activiti/upgrade/test/UserTaskBeforeTest.testSimplestTask.bpmn20.xml")
.deploy();

runtimeService.startProcessInstanceByKey("simpleTaskProcess");
String taskId = taskService.createTaskQuery().singleResult().getId();
taskService.complete(taskId);

// UpgradeTaskTwoTest
processEngine.getRepositoryService().createDeployment().name("simpleTaskProcess")
.addClasspathResource("org/activiti/upgrade/test/UserTaskBeforeTest.testTaskWithExecutionVariables.bpmn20.xml")
.deploy();

Map<String, Object> variables = new HashMap<String, Object>();
variables.put("instrument", "trumpet");
variables.put("player", "gonzo");
runtimeService.startProcessInstanceByKey("taskWithExecutionVariablesProcess", variables);
}

public void setProcessEngine(ProcessEngine processEngine) {
this.processEngine = processEngine;
}

}
@@ -0,0 +1,24 @@
/* 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.upgrade.data;

import org.activiti.engine.ProcessEngine;

/**
* @author Joram Barrez
*/
public interface DataGenerator extends Runnable {

void setProcessEngine(ProcessEngine processEngine);

}
Expand Up @@ -10,7 +10,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.upgrade;
package org.activiti.upgrade.data;

import java.io.PrintWriter;
import java.sql.DriverManager;
Expand All @@ -24,21 +24,18 @@
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.impl.util.ClassNameUtil;
import org.activiti.engine.impl.util.LogUtil;
import org.activiti.upgrade.test.UpgradeTaskOneTest;
import org.activiti.upgrade.test.UpgradeTaskTwoTest;
import org.activiti.upgrade.CleanPostgres;
import org.activiti.upgrade.ProxyDriver;
import org.activiti.upgrade.UpgradeUtil;

/**
* @author Tom Baeyens
* @author Joram Barrez
*/
public class UpgradeDataGenerator {

static Logger log = Logger.getLogger(UpgradeTestCase.class.getName());
static Logger log = Logger.getLogger(UpgradeDataGenerator.class.getName());

static UpgradeTestCase[] upgradeTestCases = new UpgradeTestCase[]{
new UpgradeTaskOneTest(),
new UpgradeTaskTwoTest()
};

public static void main(String[] args) {

ProcessEngineConfigurationImpl processEngineConfiguration = null;
Expand All @@ -56,7 +53,7 @@ public static void main(String[] args) {
log.fine("database: "+database);
log.fine("releaseVersion: "+releaseVersion);

processEngineConfiguration = UpgradeTestCase.createProcessEngineConfiguration(database);
processEngineConfiguration = UpgradeUtil.createProcessEngineConfiguration(database);

// install the jdbc proxy driver
log.fine("installing jdbc proxy driver delegating to "+processEngineConfiguration.getJdbcUrl());
Expand All @@ -67,12 +64,17 @@ public static void main(String[] args) {
log.fine("building the process engine...");
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();

log.fine("deploy processes and start process instances");
UpgradeTestCase.setProcessEngine(processEngine);

for (UpgradeTestCase upgradeTestCase: upgradeTestCases) {
log.fine("### Running test "+ClassNameUtil.getClassNameWithoutPackage(upgradeTestCase.getClass())+" in the old version");
upgradeTestCase.runInTheOldVersion();
log.fine("### Running data generator "+ClassNameUtil.getClassNameWithoutPackage(CommonDataGenerator.class)+" in the old version");
CommonDataGenerator commonDataGenerator = new CommonDataGenerator();
commonDataGenerator.setProcessEngine(processEngine);
commonDataGenerator.run();

// < 5.11 upgrade tests (ie the following data only needs to be generated when the engine is lower then or equals 5.10)
if (UpgradeUtil.getProcessEngineVersion(processEngine) < 11) {
Activiti_5_10_DataGenerator activiti_5_10_DataGenerator = new Activiti_5_10_DataGenerator();
activiti_5_10_DataGenerator.setProcessEngine(processEngine);
activiti_5_10_DataGenerator.run();
}

log.fine("### Captured SQL");
Expand All @@ -95,14 +97,23 @@ public static void main(String[] args) {
}

private static void dbSchemaDrop(ProcessEngineConfigurationImpl processEngineConfiguration) {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Object> (){
public Object execute(CommandContext commandContext) {
commandContext
.getSession(DbSqlSession.class)
.dbSchemaDrop();
return null;
}
});
if (processEngineConfiguration.getDatabaseType().equals("postgres")) {

CleanPostgres cleanPostgres = new CleanPostgres();
cleanPostgres.execute();

} else {

CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Object> (){
public Object execute(CommandContext commandContext) {
commandContext
.getSession(DbSqlSession.class)
.dbSchemaDrop();
return null;
}
});

}
}
}

0 comments on commit 99314ae

Please sign in to comment.