db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "pelle.ullberg" <pelle.ullb...@gmail.com>
Subject Able to reconnect previously shutdown in-memory derby database
Date Wed, 09 Oct 2013 12:26:33 GMT

Could someone please explain whats wrong with this little unit test that I
mocked up? I'm using derby version

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

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 =

    @Test(expected = SQLException.class)
    public void verifyDerbyShutdown() throws SQLException {
        String url = "jdbc:derby:memory:" + UUID.randomUUID().toString();
        Connection connection = DriverManager.getConnection(url +

        // Ping derby just to make sure we got it up and running
        connection.prepareCall("select * from

        try {
        } catch (SQLException e) {
            // This exception is expected:
            Assert.assertEquals("Derby system shutdown.", e.getMessage());
        } finally {
            // Make sure old driver is collected
            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'



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.

View raw message