db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Trejkaz (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (DERBY-6919) Exception from stream being inserted renders PooledConnection unusable from that point onwards
Date Wed, 11 Jan 2017 01:36:58 GMT

     [ https://issues.apache.org/jira/browse/DERBY-6919?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Trejkaz updated DERBY-6919:
---------------------------
    Description: 
The following test:
* Creates a pooled connection
* Gets a connection from it, tries to performs an insert which fails not due to the database
at all, but due to the broken InputStream passed in
* Tries to get a new connection object to do new operations on.

The second call to get a new connection fails, but we don't think it should as it makes it
difficult to reuse pooled connections.

Additionally, the connectionErrorOccurred event is never called to inform us that the connection
cannot be reused.

{code}
    @Test
    public void testExceptionInsertingPoisonsPooledConnection() throws Exception
    {
        EmbeddedConnectionPoolDataSource dataSource = new EmbeddedConnectionPoolDataSource();
        dataSource.setDatabaseName(temp.getRootPath().resolve("db").toString());
        dataSource.setCreateDatabase("create");

        PooledConnection pooledConnection = dataSource.getPooledConnection();
        try {
            // Someone initialising the db
            try (Connection connection = pooledConnection.getConnection()) {
                try (Statement statement = connection.createStatement()) {
                    statement.execute("CREATE TABLE blobs ( data BLOB(1G) )");
                }
            }

            // Someone failing to insert something
            try (Connection connection = pooledConnection.getConnection();
                 PreparedStatement statement = connection.prepareStatement("INSERT INTO blobs
(data) VALUES (?)")) {
                statement.setBinaryStream(1, new BrokenInputStream());

                assertThat(statement::executeUpdate,
                           throwsException(SQLException.class));
            }

            // The next guy trying to do it right
            try (Connection connection = pooledConnection.getConnection();
                 PreparedStatement statement = connection.prepareStatement("INSERT INTO blobs
(data) VALUES (?)")) {
                statement.setBinaryStream(1, new ByteArrayInputStream("data".getBytes(StandardCharsets.UTF_8)));
                assertThat(statement.executeUpdate(), is(1));
            }
        } finally {
            pooledConnection.close();
        }
    }

    private static class BrokenInputStream extends InputStream {
        @Override
        public int read() throws IOException {
            throw new NullPointerException("I forgot to check for null");
        }
    }
{code}


  was:
The following test:
* Creates a pooled connection
* Gets a connection from it, tries to performs an insert which fails not due to the database
at all, but due to the broken InputStream passed in
* Tries to get a new connection object to do new operations on.

The second call to get a new connection fails, but we don't think it should as it makes it
difficult to reuse pooled connections.

{code}
    @Test
    public void testExceptionInsertingPoisonsPooledConnection() throws Exception
    {
        EmbeddedConnectionPoolDataSource dataSource = new EmbeddedConnectionPoolDataSource();
        dataSource.setDatabaseName(temp.getRootPath().resolve("db").toString());
        dataSource.setCreateDatabase("create");

        PooledConnection pooledConnection = dataSource.getPooledConnection();
        try {
            // Someone initialising the db
            try (Connection connection = pooledConnection.getConnection()) {
                try (Statement statement = connection.createStatement()) {
                    statement.execute("CREATE TABLE blobs ( data BLOB(1G) )");
                }
            }

            // Someone failing to insert something
            try (Connection connection = pooledConnection.getConnection();
                 PreparedStatement statement = connection.prepareStatement("INSERT INTO blobs
(data) VALUES (?)")) {
                statement.setBinaryStream(1, new BrokenInputStream());

                assertThat(statement::executeUpdate,
                           throwsException(SQLException.class));
            }

            // The next guy trying to do it right
            try (Connection connection = pooledConnection.getConnection();
                 PreparedStatement statement = connection.prepareStatement("INSERT INTO blobs
(data) VALUES (?)")) {
                statement.setBinaryStream(1, new ByteArrayInputStream("data".getBytes(StandardCharsets.UTF_8)));
                assertThat(statement.executeUpdate(), is(1));
            }
        } finally {
            pooledConnection.close();
        }
    }

    private static class BrokenInputStream extends InputStream {
        @Override
        public int read() throws IOException {
            throw new NullPointerException("I forgot to check for null");
        }
    }
{code}



> Exception from stream being inserted renders PooledConnection unusable from that point
onwards
> ----------------------------------------------------------------------------------------------
>
>                 Key: DERBY-6919
>                 URL: https://issues.apache.org/jira/browse/DERBY-6919
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions: 10.12.1.1, 10.13.1.1
>            Reporter: Trejkaz
>
> The following test:
> * Creates a pooled connection
> * Gets a connection from it, tries to performs an insert which fails not due to the database
at all, but due to the broken InputStream passed in
> * Tries to get a new connection object to do new operations on.
> The second call to get a new connection fails, but we don't think it should as it makes
it difficult to reuse pooled connections.
> Additionally, the connectionErrorOccurred event is never called to inform us that the
connection cannot be reused.
> {code}
>     @Test
>     public void testExceptionInsertingPoisonsPooledConnection() throws Exception
>     {
>         EmbeddedConnectionPoolDataSource dataSource = new EmbeddedConnectionPoolDataSource();
>         dataSource.setDatabaseName(temp.getRootPath().resolve("db").toString());
>         dataSource.setCreateDatabase("create");
>         PooledConnection pooledConnection = dataSource.getPooledConnection();
>         try {
>             // Someone initialising the db
>             try (Connection connection = pooledConnection.getConnection()) {
>                 try (Statement statement = connection.createStatement()) {
>                     statement.execute("CREATE TABLE blobs ( data BLOB(1G) )");
>                 }
>             }
>             // Someone failing to insert something
>             try (Connection connection = pooledConnection.getConnection();
>                  PreparedStatement statement = connection.prepareStatement("INSERT INTO
blobs (data) VALUES (?)")) {
>                 statement.setBinaryStream(1, new BrokenInputStream());
>                 assertThat(statement::executeUpdate,
>                            throwsException(SQLException.class));
>             }
>             // The next guy trying to do it right
>             try (Connection connection = pooledConnection.getConnection();
>                  PreparedStatement statement = connection.prepareStatement("INSERT INTO
blobs (data) VALUES (?)")) {
>                 statement.setBinaryStream(1, new ByteArrayInputStream("data".getBytes(StandardCharsets.UTF_8)));
>                 assertThat(statement.executeUpdate(), is(1));
>             }
>         } finally {
>             pooledConnection.close();
>         }
>     }
>     private static class BrokenInputStream extends InputStream {
>         @Override
>         public int read() throws IOException {
>             throw new NullPointerException("I forgot to check for null");
>         }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message