本文整理汇总了Java中io.netty.channel.embedded.EmbeddedChannel.readOutbound方法的典型用法代码示例。如果您正苦于以下问题:Java EmbeddedChannel.readOutbound方法的具体用法?Java EmbeddedChannel.readOutbound怎么用?Java EmbeddedChannel.readOutbound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.embedded.EmbeddedChannel
的用法示例。
在下文中一共展示了EmbeddedChannel.readOutbound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
@Tag("fast")
public void encode() {
IsoOnTcpMessage isoOnTcpMessage = new IsoOnTcpMessage(
Unpooled.wrappedBuffer(new byte[]{(byte)0x01,(byte)0x02,(byte)0x03}));
EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
channel.writeOutbound(isoOnTcpMessage);
channel.checkException();
Object obj = channel.readOutbound();
assertThat(obj).isInstanceOf(ByteBuf.class);
ByteBuf byteBuf = (ByteBuf) obj;
assertEquals(4 + 3, byteBuf.readableBytes(),
"The TCP on ISO Header should add 4 bytes to the data sent");
assertEquals(IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER, byteBuf.getByte(0));
assertEquals(4 + 3, byteBuf.getShort(2),
"The length value in the packet should reflect the size of the entire data being sent");
}
示例2: executeNormalChannelRead0
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
private MqttConnAckMessage executeNormalChannelRead0(String clientId, boolean cleanSession, ChannelId channelId)
throws Exception {
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false,
10);
MqttConnectVariableHeader variableHeader = new MqttConnectVariableHeader("MQTT", 4, true, true, true, 0, true,
cleanSession, 60);
MqttConnectPayload payload = new MqttConnectPayload(clientId, "willtopic", "willmessage", "username",
"password");
MqttConnectMessage msg = new MqttConnectMessage(fixedHeader, variableHeader, payload);
ChannelId cid = channelId == null ? TestUtil.newChannelId(clientId, false) : channelId;
EmbeddedChannel channel = new EmbeddedChannel(cid, new ConnectReceiver());
channel.writeInbound(msg);
return channel.readOutbound();
}
示例3: prepare
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Before
public void prepare () throws PropertyVetoException, SQLException {
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
node1.isServer = false;
node2.isServer = true;
contextFactory1 = new MockContextFactory(serverObject1);
contextFactory2 = new MockContextFactory(serverObject2);
node1.ephemeralKeyClient = node2.ephemeralKeyServer;
node2.ephemeralKeyClient = node1.ephemeralKeyServer;
node1.ecdhKeySet = ECDH.getSharedSecret(node1.ephemeralKeyServer, node1.ephemeralKeyClient);
node2.ecdhKeySet = ECDH.getSharedSecret(node2.ephemeralKeyServer, node2.ephemeralKeyClient);
channel1 = new EmbeddedChannel(new ProcessorHandler(contextFactory1.getAuthenticationProcessor(node1), "Encryption1"));
channel2 = new EmbeddedChannel(new ProcessorHandler(contextFactory2.getAuthenticationProcessor(node2), "Encryption2"));
Message m = (Message) channel2.readOutbound();
assertNull(m);
}
示例4: prepare
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Before
public void prepare () {
node1.isServer = false;
node1.intent = ConnectionIntent.GET_IPS;
node2.isServer = true;
contextFactory1 = new MockContextFactory(serverObject1, dbHandler1);
contextFactory2 = new MockContextFactory(serverObject2, dbHandler2);
dbHandler2.fillWithRandomData();
channel1 = new EmbeddedChannel(new ProcessorHandler(contextFactory1.getPeerSeedProcessor(node1), "Seed1"));
channel2 = new EmbeddedChannel(new ProcessorHandler(contextFactory2.getPeerSeedProcessor(node2), "Seed2"));
Message m = (Message) channel2.readOutbound();
assertNull(m);
}
示例5: prepare
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
public void prepare () {
node1 = new ClientObject();
node2 = new ClientObject();
node1.isServer = false;
node2.isServer = true;
contextFactory1 = new MockContextFactory(serverObject1, dbHandler1);
contextFactory2 = new MockContextFactory(serverObject2, dbHandler2);
channel1 = new EmbeddedChannel(new ProcessorHandler(contextFactory1.getSyncProcessor(node1), "Sync1"));
channel2 = new EmbeddedChannel(new ProcessorHandler(contextFactory2.getSyncProcessor(node2), "Sync2"));
Message m = (Message) channel2.readOutbound();
assertNull(m);
}
示例6: prepare
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Before
public void prepare () throws PropertyVetoException, SQLException {
node12.name = "LNPayment12";
node21.name = "LNPayment21";
node23.name = "LNPayment23";
node32.name = "LNPayment32";
node12.pubKeyClient = node2.pubKeyServer;
node21.pubKeyClient = node1.pubKeyServer;
node23.pubKeyClient = node3.pubKeyServer;
node32.pubKeyClient = node2.pubKeyServer;
processor12 = new LNPaymentProcessorImpl(contextFactory1, dbHandler1, node12);
processor21 = new LNPaymentProcessorImpl(contextFactory2, dbHandler2, node21);
processor23 = new LNPaymentProcessorImpl(contextFactory2, dbHandler2, node23);
processor32 = new LNPaymentProcessorImpl(contextFactory3, dbHandler3, node32);
channel12 = new EmbeddedChannel(new ProcessorHandler(processor12, "LNPayment12"));
channel21 = new EmbeddedChannel(new ProcessorHandler(processor21, "LNPayment21"));
channel23 = new EmbeddedChannel(new ProcessorHandler(processor23, "LNPayment23"));
channel32 = new EmbeddedChannel(new ProcessorHandler(processor32, "LNPayment32"));
Message m = (Message) channel21.readOutbound();
assertNull(m);
}
示例7: prepare
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Before
public void prepare () throws PropertyVetoException, SQLException {
node1.isServer = false;
node1.intent = ConnectionIntent.OPEN_CHANNEL;
node2.isServer = true;
contextFactory1 = new EstablishMockContextFactory(serverObject1, dbHandler1);
contextFactory2 = new EstablishMockContextFactory(serverObject2, dbHandler2);
processor1 = new LNEstablishProcessorImpl(contextFactory1, dbHandler1, node1);
processor2 = new LNEstablishProcessorImpl(contextFactory2, dbHandler2, node2);
channel1 = new EmbeddedChannel(new ProcessorHandler(processor1, "LNEstablish1"));
channel2 = new EmbeddedChannel(new ProcessorHandler(processor2, "LNEstablish2"));
contextFactory1.getChannelManager().openChannel(new NodeKey(node1.pubKeyClient), new ChannelOpenListener());
Message m = (Message) channel2.readOutbound();
assertNull(m);
}
示例8: prepare
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Before
public void prepare () throws PropertyVetoException, SQLException {
node1.isServer = false;
node2.isServer = true;
this.node1.name = "LNPayment12";
this.node2.name = "LNPayment21";
processor12 = new LNPaymentProcessorImpl(contextFactory12, dbHandler1, this.node1);
processor21 = new LNPaymentProcessorImpl(contextFactory21, dbHandler2, this.node2);
channel12 = new EmbeddedChannel(new ProcessorHandler(processor12, "LNPayment12"));
channel21 = new EmbeddedChannel(new ProcessorHandler(processor21, "LNPayment21"));
Message m = (Message) channel21.readOutbound();
assertNull(m);
}
示例9: sendRequest
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
static Reply sendRequest(EmbeddedChannel channel, Request request) throws Exception {
channel.writeInbound(request);
Object encodedReply = channel.readOutbound();
for (int i = 0; encodedReply == null && i < 50; i++) {
channel.runPendingTasks();
Thread.sleep(10);
encodedReply = channel.readOutbound();
}
if (encodedReply == null) {
throw new IllegalStateException("No reply to request: " + request);
}
WireCommand decoded = CommandDecoder.parseCommand((ByteBuf) encodedReply);
((ByteBuf) encodedReply).release();
assertNotNull(decoded);
return (Reply) decoded;
}
示例10: testEncode
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
* This unit test case ensures that {@link FileRegionEncoder} indeed wraps {@link FileRegion} to
* {@link ByteBuf}.
* @throws IOException if there is an error.
*/
@Test
public void testEncode() throws IOException {
FileRegionEncoder fileRegionEncoder = new FileRegionEncoder();
EmbeddedChannel channel = new EmbeddedChannel(fileRegionEncoder);
File file = File.createTempFile(UUID.randomUUID().toString(), ".data");
file.deleteOnExit();
Random random = new Random(System.currentTimeMillis());
int dataLength = 1 << 10;
byte[] data = new byte[dataLength];
random.nextBytes(data);
write(file, data);
FileRegion fileRegion = new DefaultFileRegion(file, 0, dataLength);
Assert.assertEquals(0, fileRegion.transfered());
Assert.assertEquals(dataLength, fileRegion.count());
Assert.assertTrue(channel.writeOutbound(fileRegion));
ByteBuf out = (ByteBuf) channel.readOutbound();
byte[] arr = new byte[out.readableBytes()];
out.getBytes(0, arr);
Assert.assertArrayEquals("Data should be identical", data, arr);
}
示例11: shouldInterceptPing
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void shouldInterceptPing() throws Exception {
EmbeddedChannel channel = new EmbeddedChannel(
new PingHandler()
);
TFrame frame = new TFrame(0, FrameType.PingRequest.byteValue(), Integer.MAX_VALUE, Unpooled.EMPTY_BUFFER);
channel.writeInbound(MessageCodec.decode(frame));
TFrame newFrame = channel.readOutbound();
assertNotNull(newFrame);
assertEquals(frame.size, newFrame.size);
assertEquals(FrameType.PingResponse.byteValue(), newFrame.type);
assertEquals(frame.id, newFrame.id);
}
示例12: testEmptyFullContentWithTrailer
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testEmptyFullContentWithTrailer() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new HttpContentCompressor());
ch.writeInbound(newRequest());
FullHttpResponse res = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.EMPTY_BUFFER);
res.trailingHeaders().set("X-Test", "Netty");
ch.writeOutbound(res);
Object o = ch.readOutbound();
assertThat(o, is(instanceOf(FullHttpResponse.class)));
res = (FullHttpResponse) o;
assertThat(res.headers().get(Names.TRANSFER_ENCODING), is(nullValue()));
// Content encoding shouldn't be modified.
assertThat(res.headers().get(Names.CONTENT_ENCODING), is(nullValue()));
assertThat(res.content().readableBytes(), is(0));
assertThat(res.content().toString(CharsetUtil.US_ASCII), is(""));
assertEquals("Netty", res.trailingHeaders().get("X-Test"));
assertThat(ch.readOutbound(), is(nullValue()));
}
示例13: testEmptyBufferBypass
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testEmptyBufferBypass() throws Exception {
EmbeddedChannel channel = new EmbeddedChannel(new HttpResponseEncoder());
// Test writing an empty buffer works when the encoder is at ST_INIT.
channel.writeOutbound(Unpooled.EMPTY_BUFFER);
ByteBuf buffer = (ByteBuf) channel.readOutbound();
assertThat(buffer, is(sameInstance(Unpooled.EMPTY_BUFFER)));
// Leave the ST_INIT state.
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
assertTrue(channel.writeOutbound(response));
buffer = (ByteBuf) channel.readOutbound();
assertEquals("HTTP/1.1 200 OK\r\n\r\n", buffer.toString(CharsetUtil.US_ASCII));
buffer.release();
// Test writing an empty buffer works when the encoder is not at ST_INIT.
channel.writeOutbound(Unpooled.EMPTY_BUFFER);
buffer = (ByteBuf) channel.readOutbound();
assertThat(buffer, is(sameInstance(Unpooled.EMPTY_BUFFER)));
assertFalse(channel.finish());
}
示例14: testExpectContinueResponse4
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testExpectContinueResponse4() {
// request with header "Expect: 100-continue" must be replied with one "100 Continue" response
// case 4: ObjectAggregator is up in chain
HttpRequestDecoder decoder = new HttpRequestDecoder();
HttpObjectAggregator aggregator = new HttpObjectAggregator(1024);
HttpContentDecoder decompressor = new HttpContentDecompressor();
EmbeddedChannel channel = new EmbeddedChannel(decoder, aggregator, decompressor);
String req = "POST / HTTP/1.1\r\n" +
"Content-Length: " + GZ_HELLO_WORLD.length + "\r\n" +
"Expect: 100-continue\r\n" +
"Content-Encoding: gzip\r\n" +
"\r\n";
assertFalse(channel.writeInbound(Unpooled.wrappedBuffer(req.getBytes())));
Object o = channel.readOutbound();
assertThat(o, is(instanceOf(FullHttpResponse.class)));
FullHttpResponse r = (FullHttpResponse) o;
assertEquals(100, r.getStatus().code());
r.release();
assertTrue(channel.writeInbound(Unpooled.wrappedBuffer(GZ_HELLO_WORLD)));
assertHasInboundMessages(channel, true);
assertHasOutboundMessages(channel, false);
assertFalse(channel.finish());
}
示例15: testFullContent
import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testFullContent() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new TestEncoder());
ch.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));
FullHttpResponse res = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(new byte[42]));
res.headers().set(Names.CONTENT_LENGTH, 42);
ch.writeOutbound(res);
assertEncodedResponse(ch);
HttpContent c = (HttpContent) ch.readOutbound();
assertThat(c.content().readableBytes(), is(2));
assertThat(c.content().toString(CharsetUtil.US_ASCII), is("42"));
c.release();
LastHttpContent last = (LastHttpContent) ch.readOutbound();
assertThat(last.content().readableBytes(), is(0));
last.release();
assertThat(ch.readOutbound(), is(nullValue()));
}