db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Ondruška <peter.ondru...@yahoo.com>
Subject Re: Able to reconnect previously shutdown in-memory derby database
Date Wed, 09 Oct 2013 15:13:31 GMT
My guess is that similar to filesystem if you only shutdown Derby without JVM exit database
is still there. Similar to filesystem where you need to remove database from filesystem.

Peter

> On 9 Oct 2013, at 14:26, "pelle.ullberg" <pelle.ullberg@gmail.com> wrote:
> 
> 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.

Mime
View raw message