Search in sources :

Example 41 with XdrOutputStream

use of org.firebirdsql.gds.impl.wire.XdrOutputStream in project jaybird by FirebirdSQL.

the class TestV10EventHandling method testAsynchronousDelivery_partialEvent.

@Test
public void testAsynchronousDelivery_partialEvent() throws Exception {
    final SimpleChannelListener listener = new SimpleChannelListener();
    try (SimpleServer simpleServer = new SimpleServer()) {
        final FbWireAsynchronousChannel channel = new V10AsynchronousChannel(createDummyDatabase());
        channel.addChannelListener(listener);
        Thread establishChannel = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    channel.connect("localhost", simpleServer.getPort(), 1);
                } catch (SQLException e) {
                // suppress
                }
            }
        });
        establishChannel.start();
        simpleServer.acceptConnection();
        AsynchronousProcessor.getInstance().registerAsynchronousChannel(channel);
        establishChannel.join(500);
        assertTrue("Expected connected channel", channel.isConnected());
        final XdrOutputStream out = new XdrOutputStream(simpleServer.getOutputStream());
        out.writeInt(op_dummy);
        out.writeInt(op_event);
        out.writeInt(513);
        out.writeBuffer(new byte[] { 1, 3, 69, 86, 84, 3, 0, 0, 0 });
        // Flushing partial event to test if processing works as expected
        out.flush();
        Thread.sleep(500);
        List<AsynchronousChannelListener.Event> receivedEvents = listener.getReceivedEvents();
        assertEquals("Unexpected number of events", 0, receivedEvents.size());
        out.writeLong(0);
        out.writeInt(7);
        out.flush();
        Thread.sleep(500);
        receivedEvents = listener.getReceivedEvents();
        assertEquals("Unexpected number of events", 1, receivedEvents.size());
        AsynchronousChannelListener.Event event = receivedEvents.get(0);
        assertEquals("Unexpected eventId", 7, event.getEventId());
        assertEquals("Unexpected event count", 3, event.getEventCount());
    }
}
Also used : SimpleServer(org.firebirdsql.common.SimpleServer) SQLException(java.sql.SQLException) XdrOutputStream(org.firebirdsql.gds.impl.wire.XdrOutputStream) Test(org.junit.Test)

Aggregations

XdrOutputStream (org.firebirdsql.gds.impl.wire.XdrOutputStream)41 SQLException (java.sql.SQLException)25 IOException (java.io.IOException)24 FbExceptionBuilder (org.firebirdsql.gds.ng.FbExceptionBuilder)22 SimpleServer (org.firebirdsql.common.SimpleServer)4 Encoding (org.firebirdsql.encodings.Encoding)3 XdrInputStream (org.firebirdsql.gds.impl.wire.XdrInputStream)3 Test (org.junit.Test)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 SQLNonTransientConnectionException (java.sql.SQLNonTransientConnectionException)2 SQLNonTransientException (java.sql.SQLNonTransientException)2 BlobParameterBuffer (org.firebirdsql.gds.BlobParameterBuffer)2 GenericResponse (org.firebirdsql.gds.ng.wire.GenericResponse)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 SQLTimeoutException (java.sql.SQLTimeoutException)1 BitSet (java.util.BitSet)1 WireCrypt (org.firebirdsql.gds.ng.WireCrypt)1 ClientAuthBlock (org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock)1 EncryptionIdentifier (org.firebirdsql.gds.ng.wire.crypt.EncryptionIdentifier)1