/** * @deprecated use {@link #outboundMessages()} */ @Deprecated public Queue<Object> lastOutboundBuffer() { return outboundMessages(); }
/** * Called for each outbound message. * * @see #doWrite(ChannelOutboundBuffer) */ protected void handleOutboundMessage(Object msg) { outboundMessages().add(msg); }
/** * @deprecated use {@link #outboundMessages()} */ @Deprecated public Queue<Object> lastOutboundBuffer() { return outboundMessages(); }
/** * Called for each outbound message. * * @see #doWrite(ChannelOutboundBuffer) */ protected void handleOutboundMessage(Object msg) { outboundMessages().add(msg); }
/** * @deprecated use {@link #outboundMessages()} */ @Deprecated public Queue<Object> lastOutboundBuffer() { return outboundMessages(); }
/** * Called for each outbound message. * * @see #doWrite(ChannelOutboundBuffer) */ protected void handleOutboundMessage(Object msg) { outboundMessages().add(msg); }
private List<ByteBuf> peekAllOutboundMessages() { return channel.outboundMessages() .stream() .map( msg -> (ByteBuf) msg ) .collect( toList() ); }
public void assertMessagesWritten(Object... msgs) { Queue<Object> outboundMessages = channel.outboundMessages(); if (null == msgs || msgs.length == 0) { assertThat("Unexpected number of messages written on the channel.", outboundMessages, is(empty())); return; } assertThat("Unexpected number of messages written on the channel.", outboundMessages, hasSize(msgs.length)); assertThat("Unexpected messages written on the channel.", outboundMessages, contains(msgs)); }
public ByteBuf readNextOutboundBuffer(int expectedWrittenMessages) { assertThat("Unexpected outbound messages size.", channel.outboundMessages(), hasSize(expectedWrittenMessages)); Object writtenMsg = channel.readOutbound(); assertThat("Unexpected message type written on the channel.", writtenMsg, is(instanceOf(ByteBuf.class))); return (ByteBuf) writtenMsg; }
@Test public void shouldFlushNothingWhenEmpty() throws Exception { out.flush(); assertEquals( 0, channel.outboundMessages().size() ); }
@Benchmark public void netty() { GET.setIndex(readerIndex, writeIndex); nettyChannel.writeInbound(GET); ByteBuf result = (ByteBuf) nettyChannel.outboundMessages().poll(); consume(result); } }
@Benchmark public void vertx() { GET.setIndex(readerIndex, writeIndex); vertxChannel.writeInbound(GET); ByteBuf result = (ByteBuf) vertxChannel.outboundMessages().poll(); consume(result); }
public Queue<Object> getWrittenMessages() { channel.runPendingTasks(); channel.flush(); return channel.outboundMessages(); }
@Test public void shouldFlushNothingWhenClosed() throws Exception { out.close(); out.flush(); assertEquals( 0, channel.outboundMessages().size() ); }
@Fork(value = 1, jvmArgsAppend = { "-Dvertx.threadChecks=false", "-Dvertx.disableContextTimings=true", "-Dvertx.disableTCCL=true", "-Dvertx.disableHttpHeadersValidation=true", }) @Benchmark public void vertxOpt() { GET.setIndex(readerIndex, writeIndex); vertxChannel.writeInbound(GET); ByteBuf result = (ByteBuf) vertxChannel.outboundMessages().poll(); consume(result); }
@Test public void shouldHandleFragmentedMessage() { // Given BoltProtocol protocol = newBoltProtocol( 1 ); BoltProtocolFactory handlerFactory = newProtocolFactory( 1, protocol ); EmbeddedChannel channel = new EmbeddedChannel( new ProtocolHandshaker( handlerFactory, boltChannel, logProvider, false, true ) ); // When channel.writeInbound( Unpooled.wrappedBuffer( new byte[]{(byte) 0x60, (byte) 0x60, (byte) 0xB0} ) ); assertEquals( 0, channel.outboundMessages().size() ); channel.writeInbound( Unpooled.wrappedBuffer( new byte[]{(byte) 0x17, 0, 0, 0} ) ); assertEquals( 0, channel.outboundMessages().size() ); channel.writeInbound( Unpooled.wrappedBuffer( new byte[]{0, 0, 0} ) ); assertEquals( 0, channel.outboundMessages().size() ); channel.writeInbound( Unpooled.wrappedBuffer( new byte[]{0, 1, 0, 0, 0} ) ); assertEquals( 0, channel.outboundMessages().size() ); channel.writeInbound( Unpooled.wrappedBuffer( new byte[]{0, 0, 0} ) ); assertEquals( 0, channel.outboundMessages().size() ); channel.writeInbound( Unpooled.wrappedBuffer( new byte[]{0, 0} ) ); // Then assertEquals( 1, channel.outboundMessages().size() ); assertByteBufEquals( Unpooled.buffer().writeInt( 1 ), channel.readOutbound() ); thrown.expect( NoSuchElementException.class ); channel.pipeline().remove( ProtocolHandshaker.class ); assertTrue( channel.isActive() ); verify( protocol ).install(); }
@Test public void shouldFallbackToNoProtocolIfNoMatch() { // Given BoltProtocol protocol = newBoltProtocol( 1 ); BoltProtocolFactory handlerFactory = newProtocolFactory( 1, protocol ); EmbeddedChannel channel = new EmbeddedChannel( new ProtocolHandshaker( handlerFactory, boltChannel, logProvider, false, true ) ); // When ByteBuf input = Unpooled.wrappedBuffer( // create handshake data new byte[]{(byte) 0x60, (byte) 0x60, (byte) 0xB0, (byte) 0x17}, // preamble new byte[]{0, 0, 0, 0}, // first choice - no protocol new byte[]{0, 0, 0, 2}, // second choise - protocol 1 new byte[]{0, 0, 0, 3}, // third choice - no protocol new byte[]{0, 0, 0, 4} ); // fourth choice - no protocol channel.writeInbound( input ); // Then assertEquals( 1, channel.outboundMessages().size() ); assertByteBufEquals( Unpooled.buffer().writeInt( 0 ), channel.readOutbound() ); assertFalse( channel.isActive() ); verify( protocol, never() ).install(); }
@Test public void shouldRejectIfInsecureWhenEncryptionRequired() { // Given BoltProtocol protocol = newBoltProtocol( 1 ); BoltProtocolFactory handlerFactory = newProtocolFactory( 1, protocol ); EmbeddedChannel channel = new EmbeddedChannel( new ProtocolHandshaker( handlerFactory, boltChannel, logProvider, true, false ) ); // When ByteBuf input = Unpooled.wrappedBuffer( // create handshake data new byte[]{(byte) 0x60, (byte) 0x60, (byte) 0xB0, (byte) 0x17}, // preamble new byte[]{0, 0, 0, 1}, // first choice - no protocol new byte[]{0, 0, 0, 2}, // second choise - protocol 1 new byte[]{0, 0, 0, 3}, // third choice - no protocol new byte[]{0, 0, 0, 4} ); // fourth choice - no protocol channel.writeInbound( input ); // Then assertEquals( 0, channel.outboundMessages().size() ); assertFalse( channel.isActive() ); verify( protocol, never() ).install(); }
@Test public void shouldRejectIfWrongPreamble() { // Given BoltProtocol protocol = newBoltProtocol( 1 ); BoltProtocolFactory handlerFactory = newProtocolFactory( 1, protocol ); EmbeddedChannel channel = new EmbeddedChannel( new ProtocolHandshaker( handlerFactory, boltChannel, logProvider, false, true ) ); // When ByteBuf input = Unpooled.wrappedBuffer( // create handshake data new byte[]{(byte) 0xDE, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF}, // preamble new byte[]{0, 0, 0, 1}, // first choice - no protocol new byte[]{0, 0, 0, 2}, // second choise - protocol 1 new byte[]{0, 0, 0, 3}, // third choice - no protocol new byte[]{0, 0, 0, 4} ); // fourth choice - no protocol channel.writeInbound( input ); // Then assertEquals( 0, channel.outboundMessages().size() ); assertFalse( channel.isActive() ); verify( protocol, never() ).install(); }
@Test public void shouldRejectIfHttp() { // Given BoltProtocol protocol = newBoltProtocol( 1 ); BoltProtocolFactory handlerFactory = newProtocolFactory( 1, protocol ); EmbeddedChannel channel = new EmbeddedChannel( new ProtocolHandshaker( handlerFactory, boltChannel, logProvider, false, true ) ); // When FullHttpRequest request = new DefaultFullHttpRequest( HttpVersion.HTTP_1_1, HttpMethod.POST, "http://hello_world:10000" ); request.headers().setInt( HttpHeaderNames.CONTENT_LENGTH, 0 ); channel.writeInbound( request ); // Then assertEquals( 0, channel.outboundMessages().size() ); assertFalse( channel.isActive() ); verify( protocol, never() ).install(); logProvider.assertExactly( AssertableLogProvider.inLog( ProtocolHandshaker.class ).warn( "Unsupported connection type: 'HTTP'. Bolt protocol only operates over a TCP connection or WebSocket." ) ); }