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());
}
}
Aggregations