cancel
Showing results for 
Search instead for 
Did you mean: 

Why h2 db is not cleaned between tests

albertorugnone1
Champ in-the-making
Champ in-the-making
Hello everybody. Smiley Very Happy
It is the first time I post here, I hope you could help me. :mrgreen:
Working on tests of my project built on engine API, as usual practice I built a big amount of unit test to take control of development. Each test works fine alone but not in a suite. :?

I tried with some test form Activiti in Action book and the result is the same.
Looking in deep seems that h2 db is not cleaned between tests. I am not expert of h2 use in the test but honestly I expected  it would create a new instance or at least be cleaned between tests.
Debugging the code, I see that  ActivitiRule, in the finished method calls  TestHelper.annotationDeploymentTearDownIn, which calls  deleteDeployment. This means that IdentityService, HistoricService in my understanding.

This is in my understanding.
Then the question how I can take h2 db cleaned between tests (or also how I can have test not depending by each others)??
Please help me, I really don't know how solve this issues.

Best
Alberto  :ugeek:
5 REPLIES 5

jbarrez
Star Contributor
Star Contributor
If you remove a deployment, it cascades all related data.

What data isn't removed?

Eg. users and groups need manual removal in the teardown, because typically those are shared accross tests.

albertorugnone1
Champ in-the-making
Champ in-the-making
They seems data related to IdentityService and HistoricService

jbarrez
Star Contributor
Star Contributor
History data should be removed when the deployment is removed. What data do you see?

Identity is normal: that is not related to processes and is not cleaned?

albertorugnone1
Champ in-the-making
Champ in-the-making
I am not really sure what happened, maybe my poor expertise with db in mem. In any case I am preparing few maven projects too isolate all issue related to data in db.
The first issue is about h2 db creation.  You can find the project at https://www.dropbox.com/s/4fv3qefob1r7dnb/InitFailsTableAlreadyExist.zip

in this example the test initEngineStandaloneConfigurationInMemDbTest fails throwing
org.activiti.engine.ActivitiException: couldn't create db schema: create table ACT_HI_PROCINST (
ID_ varchar(64) not null,
PROC_INST_ID_ varchar(64) not null,
BUSINESS_KEY_ varchar(255),
PROC_DEF_ID_ varchar(64) not null,
START_TIME_ timestamp not null,
END_TIME_ timestamp,
DURATION_ bigint,
START_USER_ID_ varchar(255),
START_ACT_ID_ varchar(255),
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
DELETE_REASON_ varchar(4000),
primary key (ID_),
unique (PROC_INST_ID_)
)
at org.activiti.engine.impl.db.DbSqlSession.executeSchemaResource(DbSqlSession.java:828)
at org.activiti.engine.impl.db.DbSqlSession.executeSchemaResource(DbSqlSession.java:755)
at org.activiti.engine.impl.db.DbSqlSession.executeMandatorySchemaResource(DbSqlSession.java:618)
at org.activiti.engine.impl.db.DbSqlSession.dbSchemaCreateHistory(DbSqlSession.java:587)
at org.activiti.engine.impl.db.DbSqlSession.dbSchemaCreate(DbSqlSession.java:574)
at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:881)
at org.activiti.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:25)
at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:77)
at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:283)
at it.ipiu.orch.ProcessManagementTest.testInitEngineConfigurationInMem(ProcessManagementTest.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48)
at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.h2.jdbc.JdbcSQLException: Table "ACT_HI_PROCINST" already exists; SQL statement:
create table ACT_HI_PROCINST (
ID_ varchar(64) not null,
PROC_INST_ID_ varchar(64) not null,
BUSINESS_KEY_ varchar(255),
PROC_DEF_ID_ varchar(64) not null,
START_TIME_ timestamp not null,
END_TIME_ timestamp,
DURATION_ bigint,
START_USER_ID_ varchar(255),
START_ACT_ID_ varchar(255),
END_ACT_ID_ varchar(255),
SUPER_PROCESS_INSTANCE_ID_ varchar(64),
DELETE_REASON_ varchar(4000),
primary key (ID_),
unique (PROC_INST_ID_)
) [42101-132]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:316)
at org.h2.message.DbException.get(DbException.java:167)
at org.h2.message.DbException.get(DbException.java:144)
at org.h2.command.ddl.CreateTable.update(CreateTable.java:106)
at org.h2.command.CommandContainer.update(CommandContainer.java:70)
at org.h2.command.Command.executeUpdate(Command.java:198)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:176)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:151)
at org.activiti.engine.impl.db.DbSqlSession.executeSchemaResource(DbSqlSession.java:802)
… 38 more


Honestly I am looking for this project in the forum and in the documentation but without success. Maybe you can help me.
Please forgive me if this issue is for real newbe  :mrgreen: and if I don't follow the best practice for activiti unit test.

Thank you and kind regards  :ugeek:

frederikherema1
Star Contributor
Star Contributor
The in-memory database keeps it's data as long as the jvm is running… So if you get errors stating the table is already there, this means you're not asking activiti to drop the tables between tests