Search in sources :

Example 6 with WireDatabaseConnection

use of org.firebirdsql.gds.ng.wire.WireDatabaseConnection in project jaybird by FirebirdSQL.

the class TestV10Database method testDetach_openTransactions.

@Test
public void testDetach_openTransactions() throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        try (FbWireDatabase db = gdsConnection.identify()) {
            FbTransaction transaction = null;
            try {
                SimpleDatabaseListener callback = new SimpleDatabaseListener();
                db.addDatabaseListener(callback);
                assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
                db.attach();
                // Starting an active transaction
                transaction = getTransaction(db);
                expectedException.expect(allOf(errorCodeEquals(ISCConstants.isc_open_trans), message(startsWith(getFbMessage(ISCConstants.isc_open_trans, "1")))));
                // Triggers exception
                db.close();
            } finally {
                if (transaction != null && transaction.getState() == TransactionState.ACTIVE) {
                    transaction.commit();
                }
            }
        }
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) FBManager(org.firebirdsql.management.FBManager) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 7 with WireDatabaseConnection

use of org.firebirdsql.gds.ng.wire.WireDatabaseConnection in project jaybird by FirebirdSQL.

the class TestV10Database method testCancelOperation_abortSupported.

@Test
public void testCancelOperation_abortSupported() throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        try {
            assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
            db.attach();
            assumeTrue("expected database attached", db.isAttached());
            db.cancelOperation(ISCConstants.fb_cancel_abort);
            assertFalse("Expected database not attached after abort", db.isAttached());
            assertFalse("Expected connection closed after abort", gdsConnection.isConnected());
        } finally {
            safelyClose(db);
        }
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) FBManager(org.firebirdsql.management.FBManager) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 8 with WireDatabaseConnection

use of org.firebirdsql.gds.ng.wire.WireDatabaseConnection in project jaybird by FirebirdSQL.

the class TestV10Database method testDrop_NotAttached.

@Test
public void testDrop_NotAttached() throws Exception {
    expectedException.expect(SQLException.class);
    expectedException.expectMessage(startsWith("The connection is not attached to a database"));
    expectedException.expect(sqlStateEquals(SQLStateConstants.SQL_STATE_CONNECTION_ERROR));
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
        db.dropDatabase();
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) FBManager(org.firebirdsql.management.FBManager) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 9 with WireDatabaseConnection

use of org.firebirdsql.gds.ng.wire.WireDatabaseConnection in project jaybird by FirebirdSQL.

the class TestV10Database method testAttach_NonExistentDatabase.

/**
 * Tests if attaching to a non-existent database results in an exception
 */
@Test
public void testAttach_NonExistentDatabase() throws Exception {
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        try {
            gdsConnection.socketConnect();
            FbWireDatabase db = gdsConnection.identify();
            assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
            db.attach();
            fail("Expected the attach to fail because the database doesn't exist");
        } catch (SQLException e) {
            // NOTE: Not using expectedException because of the final assertion that isConnected is false
            // TODO Is this actually the right SQLState?
            assertThat("Expected SQLState for 'Client unable to establish connection' (08001)", e, sqlStateEquals("08001"));
            // TODO Seems to be the least specific error, deeper in there is a more specific 335544734 (isc_io_open_err)
            assertThat("Expected isc_io_error (335544344)", e, errorCodeEquals(ISCConstants.isc_io_error));
        }
        assertFalse(gdsConnection.isConnected());
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) SQLException(java.sql.SQLException) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase) Test(org.junit.Test)

Example 10 with WireDatabaseConnection

use of org.firebirdsql.gds.ng.wire.WireDatabaseConnection in project jaybird by FirebirdSQL.

the class TestV10Database method checkCancelOperationNotSupported.

private void checkCancelOperationNotSupported(int kind) throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        try (FbWireDatabase db = gdsConnection.identify()) {
            assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
            db.attach();
            assertTrue("expected database attached", db.isAttached());
            expectedException.expect(allOf(isA(SQLFeatureNotSupportedException.class), message(startsWith("Cancel Operation isn't supported in this version of the wire protocol"))));
            db.cancelOperation(kind);
        }
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : WireDatabaseConnection(org.firebirdsql.gds.ng.wire.WireDatabaseConnection) FBManager(org.firebirdsql.management.FBManager) AbstractFbWireDatabase(org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase) FbWireDatabase(org.firebirdsql.gds.ng.wire.FbWireDatabase)

Aggregations

WireDatabaseConnection (org.firebirdsql.gds.ng.wire.WireDatabaseConnection)15 FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)13 AbstractFbWireDatabase (org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase)11 Test (org.junit.Test)10 FBManager (org.firebirdsql.management.FBManager)9 File (java.io.File)2 SQLException (java.sql.SQLException)1 Ignore (org.junit.Ignore)1