Hi,
Could someone please explain whats wrong with this little unit test that I
mocked up? I'm using derby version 10.10.1.1
Basically I create an in-memory derby database, shut it down and then
expected it to not exist anymore. But if the unit test is right, I can
actually reconnect to it.
Best regards
/Pelle
Code is below!
package com.klarna.derby;
import org.apache.derby.jdbc.EmbeddedDriver;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.UUID;
public class DerbyUtilsTest {
private static final Logger LOGGER =
LoggerFactory.getLogger(DerbyUtilsTest.class);
@Test(expected = SQLException.class)
public void verifyDerbyShutdown() throws SQLException {
String url = "jdbc:derby:memory:" + UUID.randomUUID().toString();
Connection connection = DriverManager.getConnection(url +
";create=true");
// Ping derby just to make sure we got it up and running
connection.prepareCall("select * from
SYS.SYSTABLES").executeQuery();
try {
DriverManager.getConnection("jdbc:derby:;shutdown=true");
} catch (SQLException e) {
// This exception is expected:
http://db.apache.org/derby/docs/10.3/devguide/tdevdvlp20349.html
Assert.assertEquals("Derby system shutdown.", e.getMessage());
} finally {
// Make sure old driver is collected
System.gc();
try {
// Re-rgeister driver so that new derby jdbc instances may
be spawned.
DriverManager.registerDriver(new EmbeddedDriver());
} catch (SQLException e) {
LOGGER.error("Failed to re-register Derby embedded driver: "
+ e.getMessage(), e);
}
}
// Expected this to throw something like 'java.sql.SQLException:
Database 'memory:d77d6863-7624-4990-86fb-2e40a5a1e04d' not found'
DriverManager.getConnection(url);
}
}
--
View this message in context:
http://apache-database.10148.n7.nabble.com/Able-to-reconnect-previously-shutdown-in-memory-derby-database-tp134573.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.