List of usage examples for io.netty.channel.embedded EmbeddedChannel flushOutbound
public EmbeddedChannel flushOutbound()
From source file:io.crate.protocols.postgres.PostgresWireProtocolTest.java
License:Apache License
@Test public void testDescribePortalMessage() throws Exception { PostgresWireProtocol ctx = new PostgresWireProtocol(sqlOperations, new AlwaysOKNullAuthentication(), null); EmbeddedChannel channel = new EmbeddedChannel(ctx.decoder, ctx.handler); {// w ww . jav a 2 s. c o m ByteBuf buffer = Unpooled.buffer(); ClientMessages.sendStartupMessage(buffer, "doc"); ClientMessages.sendParseMessage(buffer, "S1", "select ? in (1, 2, 3)", new int[] { PGTypes.get(DataTypes.LONG).oid() }); ClientMessages.sendBindMessage(buffer, "P1", "S1", Collections.singletonList(1)); channel.writeInbound(buffer); // we're not interested in the startup, parse, or bind replies channel.flushOutbound(); channel.outboundMessages().clear(); } { // try portal describe message ByteBuf buffer = Unpooled.buffer(); ClientMessages.sendDescribeMessage(buffer, ClientMessages.DescribeType.PORTAL, "P1"); channel.writeInbound(buffer); // we should get back a RowDescription message ByteBuf response = channel.readOutbound(); assertThat(response.readByte(), is((byte) 'T')); assertThat(response.readInt(), is(42)); assertThat(response.readShort(), is((short) 1)); assertThat(PostgresWireProtocol.readCString(response), is("($1 IN (1, 2, 3))")); assertThat(response.readInt(), is(0)); assertThat(response.readShort(), is((short) 0)); assertThat(response.readInt(), is(PGTypes.get(DataTypes.BOOLEAN).oid())); assertThat(response.readShort(), is((short) PGTypes.get(DataTypes.BOOLEAN).typeLen())); assertThat(response.readInt(), is(PGTypes.get(DataTypes.LONG).typeMod())); assertThat(response.readShort(), is((short) 0)); } }
From source file:io.crate.protocols.postgres.PostgresWireProtocolTest.java
License:Apache License
@Test public void testDescribeStatementMessage() throws Exception { PostgresWireProtocol ctx = new PostgresWireProtocol(sqlOperations, new AlwaysOKNullAuthentication(), null); EmbeddedChannel channel = new EmbeddedChannel(ctx.decoder, ctx.handler); {/*from w ww . j a v a2 s . c o m*/ ByteBuf buffer = Unpooled.buffer(); ClientMessages.sendStartupMessage(buffer, "doc"); ClientMessages.sendParseMessage(buffer, "S1", "select ? in (1, 2, 3)", new int[0]); channel.writeInbound(buffer); // we're not interested in the startup, parse, or bind replies channel.flushOutbound(); channel.outboundMessages().clear(); } { // try the describe statement variant ByteBuf buffer = Unpooled.buffer(); ClientMessages.sendDescribeMessage(buffer, ClientMessages.DescribeType.STATEMENT, "S1"); channel.writeInbound(buffer); // we should get back a ParameterDescription message ByteBuf response = channel.readOutbound(); assertThat(response.readByte(), is((byte) 't')); assertThat(response.readInt(), is(10)); assertThat(response.readShort(), is((short) 1)); assertThat(response.readInt(), is(PGTypes.get(DataTypes.LONG).oid())); // we should get back a RowDescription message response = channel.readOutbound(); assertThat(response.readByte(), is((byte) 'T')); assertThat(response.readInt(), is(42)); assertThat(response.readShort(), is((short) 1)); assertThat(PostgresWireProtocol.readCString(response), is("($1 IN (1, 2, 3))")); assertThat(response.readInt(), is(0)); assertThat(response.readShort(), is((short) 0)); assertThat(response.readInt(), is(PGTypes.get(DataTypes.BOOLEAN).oid())); assertThat(response.readShort(), is((short) PGTypes.get(DataTypes.BOOLEAN).typeLen())); assertThat(response.readInt(), is(PGTypes.get(DataTypes.LONG).typeMod())); assertThat(response.readShort(), is((short) 0)); } }