oracle - Spring / DbUnit closes connection after one test -


so, need write integration tests our java-configurated spring application (3.2.3) oracle data base. there's separate schema gets populated spring-test-dbunit , first test runs without problems. other following tests, no matter if they're in same class or not, fail due closed connection:

java.sql.sqlrecoverableexception: closed connection     @ oracle.jdbc.driver.physicalconnection.createstatement(physicalconnection.java:3423)     @ oracle.jdbc.driver.physicalconnection.createstatement(physicalconnection.java:3398)     @ org.dbunit.database.statement.abstractbatchstatement.<init>(abstractbatchstatement.java:50)     @ org.dbunit.database.statement.simplestatement.<init>(simplestatement.java:49)     @ org.dbunit.database.statement.preparedstatementfactory.createbatchstatement(preparedstatementfactory.java:57)     @ org.dbunit.operation.deletealloperation.execute(deletealloperation.java:85)     @ org.dbunit.operation.compositeoperation.execute(compositeoperation.java:79)     @ com.github.springtestdbunit.dbunitrunner.setuporteardown(dbunitrunner.java:194)     @ com.github.springtestdbunit.dbunitrunner.beforetestmethod(dbunitrunner.java:66)     @ com.github.springtestdbunit.dbunittestexecutionlistener.beforetestmethod(dbunittestexecutionlistener.java:186)     @ org.springframework.test.context.testcontextmanager.beforetestmethod(testcontextmanager.java:348)     @ org.springframework.test.context.junit4.statements.runbeforetestmethodcallbacks.evaluate(runbeforetestmethodcallbacks.java:73)     @ org.springframework.test.context.junit4.statements.runaftertestmethodcallbacks.evaluate(runaftertestmethodcallbacks.java:83)     @ org.springframework.test.context.junit4.statements.springrepeat.evaluate(springrepeat.java:72)     @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:231)     @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:88)     @ org.junit.runners.parentrunner$3.run(parentrunner.java:290)     @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71)     @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288)     @ org.junit.runners.parentrunner.access$000(parentrunner.java:58)     @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268)     @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61)     @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:71)     @ org.junit.runners.parentrunner.run(parentrunner.java:363)     @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:174)     @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:86)     @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:459)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:675)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:382)     @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:192) 

here's our data source:

@override @bean public datasource datasource() {     string constring = "jdbc:oracle:thin:@localhost:1521:xe";     string username = "john";     string password = "doe";      driver driver = new oracledriver();     simpledriverdatasource datasource = new simpledriverdatasource(driver, constring, username, password);      return datasource; } 

and sample integration test class:

@contextconfiguration(classes = { integrationtestconfiguration.class }) @activeprofiles(constants.profile_integration) @runwith(springjunit4classrunner.class) @testexecutionlisteners({ dependencyinjectiontestexecutionlistener.class, dirtiescontexttestexecutionlistener.class,         transactionaltestexecutionlistener.class, dbunittestexecutionlistener.class, foreignkeydisabler.class }) @dbunitconfiguration(databaseconnection = "oracleconnection") @databasesetup("/database/snapshot/snapshot1.xml") public class integrationtest extends abstracttransactionaljunit4springcontexttests {     @autowired     private newsservice newsservice;       @test     @transactional(propagation = propagation.requires_new)     public void testspringconfiguration()     {         this.assertnewssize(1);          news news1 = new news();         news1.settitle("test news 1");         news savednews1 = this.newsservice.save(news1);         assert.asserttrue(savednews1.getid() > 0);          news news2 = new news();         news2.settitle("test news 2");         news savednews2 = this.newsservice.save(news2);         assert.asserttrue(savednews2.getid() > 0);          news news3 = new news();         news3.settitle("test news 3");         news savednews3 = this.newsservice.save(news3);         assert.asserttrue(savednews3.getid() > 0);          this.assertnewssize(4);     }       @test     @transactional(propagation = propagation.requires_new)     public void testspringconfigurationagain()     {         this.assertnewssize(1);          news news1 = new news();         news1.settitle("test news 1");         news savednews1 = this.newsservice.save(news1);         assert.asserttrue(savednews1.getid() > 0);          news news2 = new news();         news2.settitle("test news 2");         news savednews2 = this.newsservice.save(news2);         assert.asserttrue(savednews2.getid() > 0);          news news3 = new news();         news3.settitle("test news 3");         news savednews3 = this.newsservice.save(news3);         assert.asserttrue(savednews3.getid() > 0);          this.assertnewssize(4);     }       private void assertnewssize(int newssize)     {         list<news> allnews = this.newsservice.getnews();         assert.assertequals(newssize, allnews.size());     } } 

might problem of spring's database connection behavior close connection after committing/rolling transaction? if yes, how can solve this? last try create transaction on class/method base without success.

thank in advance.

i believe connected dirtiescontexttestexecutionlistener.class kind of equivalent of http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/annotation/dirtiescontext.html .

test annotation indicates applicationcontext associated test dirty , should closed: ...

after each test method in current test class, when declared @ class level class mode set after_each_test_method

so spring closing beans after 1st test method. maybe easier clean database in @aftermethod method? run after each test.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -