Search in sources :

Example 21 with FBManager

use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.

the class TestFBConnectionTimeout method normalConnectionWithTimeoutFromProperty.

/**
 * Test if a normal connection will work when the timeout is specified in the connection properties.
 */
@Test
public void normalConnectionWithTimeoutFromProperty() throws Exception {
    // Reset DriverManager timeout
    DriverManager.setLoginTimeout(0);
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try {
        Properties properties = FBTestProperties.getDefaultPropertiesForConnection();
        properties.setProperty("connectTimeout", "1");
        Connection connection = DriverManager.getConnection(FBTestProperties.getUrl(), properties);
        connection.close();
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : FBManager(org.firebirdsql.management.FBManager) Connection(java.sql.Connection) Properties(java.util.Properties) FBTestProperties(org.firebirdsql.common.FBTestProperties) FbConnectionProperties(org.firebirdsql.gds.ng.FbConnectionProperties) Test(org.junit.Test)

Example 22 with FBManager

use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.

the class TestJnaDatabase 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 {
        JnaDatabase db = factory.connect(connectionInfo);
        db.dropDatabase();
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : FBManager(org.firebirdsql.management.FBManager) Test(org.junit.Test)

Example 23 with FBManager

use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.

the class TestV10Service method testStartServiceAction.

/**
 * Test for service action.
 * <p>
 * Replicates the behavior of {@link FBStatisticsManager#getHeaderPage()}.
 * </p>
 */
@Test
public void testStartServiceAction() throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireServiceConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        try (FbWireService service = gdsConnection.identify()) {
            assertEquals("Unexpected FbWireService implementation", getExpectedServiceType(), service.getClass());
            service.attach();
            ServiceRequestBuffer actionSrb = service.createServiceRequestBuffer();
            actionSrb.addArgument(isc_action_svc_db_stats);
            actionSrb.addArgument(isc_spb_dbname, getDatabasePath());
            actionSrb.addArgument(isc_spb_options, isc_spb_sts_hdr_pages);
            service.startServiceAction(actionSrb);
            ServiceRequestBuffer infoSrb = service.createServiceRequestBuffer();
            infoSrb.addArgument(isc_info_svc_to_eof);
            int bufferSize = 1024;
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            boolean processing = true;
            while (processing) {
                byte[] buffer = service.getServiceInfo(null, infoSrb, bufferSize);
                switch(buffer[0]) {
                    case isc_info_svc_to_eof:
                        int dataLength = iscVaxInteger2(buffer, 1);
                        if (dataLength == 0) {
                            if (buffer[3] != isc_info_end) {
                                throw new SQLException("Unexpected end of stream reached.");
                            } else {
                                processing = false;
                                break;
                            }
                        }
                        bos.write(buffer, 3, dataLength);
                        break;
                    case isc_info_truncated:
                        bufferSize = bufferSize * 2;
                        break;
                    case isc_info_end:
                        processing = false;
                        break;
                }
            }
            String headerPage = service.getEncoding().decodeFromCharset(bos.toByteArray());
            assertThat("Expected database header page content", headerPage, allOf(startsWith("\nDatabase"), containsString("Database header page information"), containsString("*END*\n")));
        }
    } finally {
        defaultDatabaseTearDown(fbManager);
    }
}
Also used : FBManager(org.firebirdsql.management.FBManager) ServiceRequestBuffer(org.firebirdsql.gds.ServiceRequestBuffer) WireServiceConnection(org.firebirdsql.gds.ng.wire.WireServiceConnection) SQLException(java.sql.SQLException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FbWireService(org.firebirdsql.gds.ng.wire.FbWireService) AbstractFbWireService(org.firebirdsql.gds.ng.wire.AbstractFbWireService) Test(org.junit.Test)

Example 24 with FBManager

use of org.firebirdsql.management.FBManager in project jaybird by FirebirdSQL.

the class TestV10Database method testDetach_NotAttached.

@Test
public void testDetach_NotAttached() throws Exception {
    FBManager fbManager = createFBManager();
    defaultDatabaseSetUp(fbManager);
    try (WireDatabaseConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        FbWireDatabase db = gdsConnection.identify();
        assertEquals("Unexpected FbWireDatabase implementation", getExpectedDatabaseType(), db.getClass());
        // Detach for connected but not attached should work
        db.close();
        assertFalse("Expected connection closed after detach", gdsConnection.isConnected());
    } 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 25 with FBManager

use of org.firebirdsql.management.FBManager 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

FBManager (org.firebirdsql.management.FBManager)26 Test (org.junit.Test)17 FbWireDatabase (org.firebirdsql.gds.ng.wire.FbWireDatabase)9 WireDatabaseConnection (org.firebirdsql.gds.ng.wire.WireDatabaseConnection)9 AbstractFbWireDatabase (org.firebirdsql.gds.ng.wire.AbstractFbWireDatabase)8 Connection (java.sql.Connection)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 FBTestProperties (org.firebirdsql.common.FBTestProperties)2 ServiceRequestBuffer (org.firebirdsql.gds.ServiceRequestBuffer)2 FbConnectionProperties (org.firebirdsql.gds.ng.FbConnectionProperties)2 FBDriver (org.firebirdsql.jdbc.FBDriver)2 GDSType (org.firebirdsql.gds.impl.GDSType)1 FbTransaction (org.firebirdsql.gds.ng.FbTransaction)1 AbstractFbWireService (org.firebirdsql.gds.ng.wire.AbstractFbWireService)1 FbWireService (org.firebirdsql.gds.ng.wire.FbWireService)1 WireServiceConnection (org.firebirdsql.gds.ng.wire.WireServiceConnection)1