Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection closed issue #90

Open
lindholm opened this issue Jun 16, 2017 · 7 comments
Open

Connection closed issue #90

lindholm opened this issue Jun 16, 2017 · 7 comments

Comments

@lindholm
Copy link

I've put together a small utility library to help our local code base unit test
our beans and such.
But for some reason when I'm using derby and hibernate, I get these errors:

checkBeanEm(ca.ubc.sis.test.arquillian.TestArquillianDerbyTest)  Time elapsed: 0.014 sec  <<< ERROR!
org.jboss.arquillian.persistence.dbunit.exception.DBUnitDataSetHandlingException: Failed while seeding database.
Caused by: org.dbunit.dataset.DataSetException: Exception while searching the dependent tables.
Caused by: org.dbunit.util.search.SearchException: java.sql.SQLException: Connection jdbc:derby:memory:testDB, UserName=SA, Apache Derby Embedded JDBC Driver is closed.
Caused by: java.sql.SQLException: Connection jdbc:derby:memory:testDB, UserName=SA, Apache Derby Embedded JDBC Driver is closed.

After a lot of poking around I came up with this fix:

diff --git a/dbunit/src/main/java/org/jboss/arquillian/persistence/dbunit/DBUnitPersistenceTestLifecycleHandler.java b/dbunit/src/main/java/org/jboss/arquillian/persistence/dbunit/DBUnitPersistenceTestLifecycleHandler.java
index 28bc80e..0223461 100644
--- a/dbunit/src/main/java/org/jboss/arquillian/persistence/dbunit/DBUnitPersistenceTestLifecycleHandler.java
+++ b/dbunit/src/main/java/org/jboss/arquillian/persistence/dbunit/DBUnitPersistenceTestLifecycleHandler.java
@@ -115,8 +117,12 @@
 
     private void createDatabaseConnection() {
 
-        if (databaseConnectionProducer.get() == null) {
-            configureDatabaseConnection();
+        try {
+            if (databaseConnectionProducer.get() == null || databaseConnectionProducer.get().getConnection().isClosed()) {
+                configureDatabaseConnection();
+            }
+        } catch (SQLException e) {
+            throw new DBUnitInitializationException("Unable to createDatabaseConnection database connection for DBUnit module.", e);
         }
     }
 
@bartoszmajsak
Copy link
Member

bartoszmajsak commented Jun 16, 2017

Please make it as a PR and I will make sure it will make sure we roll out the fix soon. Thank you for spending time tracing this problem!

@lindholm
Copy link
Author

How do I do that?

@bartoszmajsak
Copy link
Member

It's fairly simple - clone the repository, apply the changes and open Pull Request. It's not that I don't want to do this myself, it's more that it's your contribution so attribution is important and you leave the footprint :)

Here's fairly simple overview of the "process" https://help.github.com/articles/about-pull-requests/

If you have more questions just give me a shout.

@bartoszmajsak
Copy link
Member

bartoszmajsak commented Jun 17, 2017

Would be awesome if you could do the same for #89

@lindholm
Copy link
Author

I keep getting (with egit):

Can't connect to any repository: ssh://George.Lindholm%[email protected]/arquillian/arquillian-extension-persistence.git (ssh://George.Lindholm%[email protected]/arquillian/arquillian-extension-persistence.git: Auth fail)

I have SSH set up

@bartoszmajsak
Copy link
Member

Oh, my mistake. I meant "fork" instead of just "clone". You have to have forked repository first and from there you clone to work locally. Then just push to your branch and on GitHub you will be able to create a Pull Request. Thank you very much for spending time on this issues.

@lindholm
Copy link
Author

OK, I think got it right. Let me know if I missed any steps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants