Search in sources :

Example 1 with FbWireService

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

the class TestV10Service method testBasicAttach.

/**
 * Tests if attaching to a service works.
 * <p>
 * Includes a test of {@link FbService#getServiceInfo(ServiceParameterBuffer, ServiceRequestBuffer, int)} (which is
 * called to populate the server version after attach).
 * </p>
 */
@Test
public void testBasicAttach() throws Exception {
    try (WireServiceConnection gdsConnection = createConnection()) {
        gdsConnection.socketConnect();
        try (FbWireService service = gdsConnection.identify()) {
            assertEquals("Unexpected FbWireService implementation", getExpectedServiceType(), service.getClass());
            service.attach();
            assertTrue("Expected isAttached() to return true", service.isAttached());
            assertNotNull("Expected version string to be not null", service.getServerVersion());
            assertNotEquals("Expected version should not be invalid", GDSServerVersion.INVALID_VERSION, service.getServerVersion());
        }
    }
}
Also used : WireServiceConnection(org.firebirdsql.gds.ng.wire.WireServiceConnection) FbWireService(org.firebirdsql.gds.ng.wire.FbWireService) AbstractFbWireService(org.firebirdsql.gds.ng.wire.AbstractFbWireService) Test(org.junit.Test)

Example 2 with FbWireService

use of org.firebirdsql.gds.ng.wire.FbWireService 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)

Aggregations

AbstractFbWireService (org.firebirdsql.gds.ng.wire.AbstractFbWireService)2 FbWireService (org.firebirdsql.gds.ng.wire.FbWireService)2 WireServiceConnection (org.firebirdsql.gds.ng.wire.WireServiceConnection)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 SQLException (java.sql.SQLException)1 ServiceRequestBuffer (org.firebirdsql.gds.ServiceRequestBuffer)1 FBManager (org.firebirdsql.management.FBManager)1