当前位置: 首页>>代码示例>>Java>>正文


Java EmbeddedChannel.finish方法代码示例

本文整理汇总了Java中io.netty.channel.embedded.EmbeddedChannel.finish方法的典型用法代码示例。如果您正苦于以下问题:Java EmbeddedChannel.finish方法的具体用法?Java EmbeddedChannel.finish怎么用?Java EmbeddedChannel.finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.channel.embedded.EmbeddedChannel的用法示例。


在下文中一共展示了EmbeddedChannel.finish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPrematureClosureWithChunkedEncoding1

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testPrematureClosureWithChunkedEncoding1() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
    ch.writeInbound(
            Unpooled.copiedBuffer("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n", CharsetUtil.US_ASCII));

    // Read the response headers.
    HttpResponse res = (HttpResponse) ch.readInbound();
    assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
    assertThat(res.getStatus(), is(HttpResponseStatus.OK));
    assertThat(res.headers().get(Names.TRANSFER_ENCODING), is("chunked"));
    assertThat(ch.readInbound(), is(nullValue()));

    // Close the connection without sending anything.
    ch.finish();
    // The decoder should not generate the last chunk because it's closed prematurely.
    assertThat(ch.readInbound(), is(nullValue()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:19,代码来源:HttpResponseDecoderTest.java

示例2: testFailsOnIncompleteChunkedResponse

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testFailsOnIncompleteChunkedResponse() {
    HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
    EmbeddedChannel ch = new EmbeddedChannel(codec);

    ch.writeOutbound(releaseLater(
            new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/")));
    assertNotNull(releaseLater(ch.readOutbound()));
    assertNull(ch.readInbound());
    ch.writeInbound(releaseLater(
            Unpooled.copiedBuffer(INCOMPLETE_CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1)));
    assertThat(releaseLater(ch.readInbound()), instanceOf(HttpResponse.class));
    assertThat(releaseLater(ch.readInbound()), instanceOf(HttpContent.class)); // Chunk 'first'
    assertThat(releaseLater(ch.readInbound()), instanceOf(HttpContent.class)); // Chunk 'second'
    assertNull(ch.readInbound());

    try {
        ch.finish();
        fail();
    } catch (CodecException e) {
        assertTrue(e instanceof PrematureChannelClosureException);
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:24,代码来源:HttpClientCodecTest.java

示例3: testNonByteBufPassthrough

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testNonByteBufPassthrough() throws Exception {
    SSLEngine engine = SSLContext.getDefault().createSSLEngine();
    engine.setUseClientMode(false);

    EmbeddedChannel ch = new EmbeddedChannel(new SslHandler(engine));

    Object msg1 = new Object();
    ch.writeOutbound(msg1);
    assertThat(ch.readOutbound(), is(sameInstance(msg1)));

    Object msg2 = new Object();
    ch.writeInbound(msg2);
    assertThat(ch.readInbound(), is(sameInstance(msg2)));

    ch.finish();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:18,代码来源:SslHandlerTest.java

示例4: testLineProtocol

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testLineProtocol() {
    EmbeddedChannel ch = new EmbeddedChannel(new LineDecoder());

    // Ordinary input
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' }));
    assertNull(ch.readInbound());
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'B' }));
    assertNull(ch.readInbound());
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'C' }));
    assertNull(ch.readInbound());
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { '\n' }));
    assertEquals(Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' }), ch.readInbound());

    // Truncated input
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[] { 'A' }));
    assertNull(ch.readInbound());

    ch.finish();
    assertNull(ch.readInbound());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:22,代码来源:ReplayingDecoderTest.java

示例5: testReplacement

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testReplacement() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new BloatedLineDecoder());

    // "AB" should be forwarded to LineDecoder by BloatedLineDecoder.
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[]{'A', 'B'}));
    assertNull(ch.readInbound());

    // "C\n" should be appended to "AB" so that LineDecoder decodes it correctly.
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[]{'C', '\n'}));
    assertEquals(releaseLater(Unpooled.wrappedBuffer(new byte[] { 'A', 'B', 'C' })),
            releaseLater(ch.readInbound()));

    ch.finish();
    assertNull(ch.readInbound());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:ReplayingDecoderTest.java

示例6: testSingleDecode

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testSingleDecode() throws Exception {
    LineDecoder decoder = new LineDecoder();
    decoder.setSingleDecode(true);
    EmbeddedChannel ch = new EmbeddedChannel(decoder);

    // "C\n" should be appended to "AB" so that LineDecoder decodes it correctly.
    ch.writeInbound(Unpooled.wrappedBuffer(new byte[]{'C', '\n' , 'B', '\n'}));
    assertEquals(releaseLater(Unpooled.wrappedBuffer(new byte[] {'C' })), releaseLater(ch.readInbound()));
    assertNull("Must be null as it must only decode one frame", ch.readInbound());

    ch.read();
    ch.finish();
    assertEquals(releaseLater(Unpooled.wrappedBuffer(new byte[] {'B' })), releaseLater(ch.readInbound()));
    assertNull(ch.readInbound());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:17,代码来源:ReplayingDecoderTest.java

示例7: testUnfinishedChunkedHttpRequestIsLastFlag

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
/**
 * Testcase for https://github.com/netty/netty/issues/433
 */
@Test
public void testUnfinishedChunkedHttpRequestIsLastFlag() throws Exception {

    int maxChunkSize = 2000;
    HttpServerCodec httpServerCodec = new HttpServerCodec(1000, 1000, maxChunkSize);
    EmbeddedChannel decoderEmbedder = new EmbeddedChannel(httpServerCodec);

    int totalContentLength = maxChunkSize * 5;
    decoderEmbedder.writeInbound(Unpooled.copiedBuffer(
            "PUT /test HTTP/1.1\r\n" +
            "Content-Length: " + totalContentLength + "\r\n" +
            "\r\n", CharsetUtil.UTF_8));

    int offeredContentLength = (int) (maxChunkSize * 2.5);
    decoderEmbedder.writeInbound(prepareDataChunk(offeredContentLength));
    decoderEmbedder.finish();

    HttpMessage httpMessage = (HttpMessage) decoderEmbedder.readInbound();
    assertNotNull(httpMessage);

    boolean empty = true;
    int totalBytesPolled = 0;
    for (;;) {
        HttpContent httpChunk = (HttpContent) decoderEmbedder.readInbound();
        if (httpChunk == null) {
            break;
        }
        empty = false;
        totalBytesPolled += httpChunk.content().readableBytes();
        assertFalse(httpChunk instanceof LastHttpContent);
        httpChunk.release();
    }
    assertFalse(empty);
    assertEquals(offeredContentLength, totalBytesPolled);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:39,代码来源:HttpServerCodecTest.java

示例8: testBadRequest

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testBadRequest() {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpRequestDecoder(), new HttpObjectAggregator(1024 * 1024));
    ch.writeInbound(Unpooled.copiedBuffer("GET / HTTP/1.0 with extra\r\n", CharsetUtil.UTF_8));
    Object inbound = ch.readInbound();
    assertThat(inbound, is(instanceOf(FullHttpRequest.class)));
    assertTrue(((HttpObject) inbound).getDecoderResult().isFailure());
    assertNull(ch.readInbound());
    ch.finish();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:11,代码来源:HttpObjectAggregatorTest.java

示例9: testConnect

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testConnect() {
    StringBuilder builder = new StringBuilder();
    try {
        builder.append("환영합니다. ")
                .append(InetAddress.getLocalHost().getHostName())
                .append("에 접속하셨습니다!\r\n")
                .append("현재 시간은 ")
                .append(new Date().toString()).append(" 입니다.\r\n");
    }
    catch (UnknownHostException e) {
        fail();
        e.printStackTrace();
    }

    EmbeddedChannel embeddedChannel = 
            new EmbeddedChannel(new TelnetServerHandlerV3());

    String expected = (String) embeddedChannel.readOutbound();
    assertNotNull(expected);

    assertEquals(builder.toString(), (String) expected);

    String request = "hello";
    expected = "입력하신 명령이 '" + request + "' 입니까?\r\n";

    embeddedChannel.writeInbound(request);

    String response = (String) embeddedChannel.readOutbound();
    assertEquals(expected, response);

    embeddedChannel.finish();
}
 
开发者ID:krisjey,项目名称:netty.book.kor,代码行数:34,代码来源:TelnetServerHandlerV3Test.java

示例10: testPrematureClosureWithChunkedEncoding2

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testPrematureClosureWithChunkedEncoding2() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());

    // Write the partial response.
    ch.writeInbound(Unpooled.copiedBuffer(
            "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n8\r\n12345678", CharsetUtil.US_ASCII));

    // Read the response headers.
    HttpResponse res = (HttpResponse) ch.readInbound();
    assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
    assertThat(res.getStatus(), is(HttpResponseStatus.OK));
    assertThat(res.headers().get(Names.TRANSFER_ENCODING), is("chunked"));

    // Read the partial content.
    HttpContent content = (HttpContent) ch.readInbound();
    assertThat(content.content().toString(CharsetUtil.US_ASCII), is("12345678"));
    assertThat(content, is(not(instanceOf(LastHttpContent.class))));
    content.release();

    assertThat(ch.readInbound(), is(nullValue()));

    // Close the connection.
    ch.finish();

    // The decoder should not generate the last chunk because it's closed prematurely.
    assertThat(ch.readInbound(), is(nullValue()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:29,代码来源:HttpResponseDecoderTest.java

示例11: testGarbageHeaders

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testGarbageHeaders() {
    // A response without headers - from https://github.com/netty/netty/issues/2103
    byte[] data = ("<html>\r\n" +
            "<head><title>400 Bad Request</title></head>\r\n" +
            "<body bgcolor=\"white\">\r\n" +
            "<center><h1>400 Bad Request</h1></center>\r\n" +
            "<hr><center>nginx/1.1.19</center>\r\n" +
            "</body>\r\n" +
            "</html>\r\n").getBytes();

    EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());

    ch.writeInbound(Unpooled.wrappedBuffer(data));

    // Garbage input should generate the 999 Unknown response.
    HttpResponse res = (HttpResponse) ch.readInbound();
    assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_0));
    assertThat(res.getStatus().code(), is(999));
    assertThat(res.getDecoderResult().isFailure(), is(true));
    assertThat(res.getDecoderResult().isFinished(), is(true));
    assertThat(ch.readInbound(), is(nullValue()));

    // More garbage should not generate anything (i.e. the decoder discards anything beyond this point.)
    ch.writeInbound(Unpooled.wrappedBuffer(data));
    assertThat(ch.readInbound(), is(nullValue()));

    // Closing the connection should not generate anything since the protocol has been violated.
    ch.finish();
    assertThat(ch.readInbound(), is(nullValue()));
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:32,代码来源:HttpResponseDecoderTest.java

示例12: testFailsOnMissingResponse

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testFailsOnMissingResponse() {
    HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
    EmbeddedChannel ch = new EmbeddedChannel(codec);

    assertTrue(ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "http://localhost/")));
    assertNotNull(releaseLater(ch.readOutbound()));
    try {
        ch.finish();
        fail();
    } catch (CodecException e) {
        assertTrue(e instanceof PrematureChannelClosureException);
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:16,代码来源:HttpClientCodecTest.java

示例13: testDecodeWithStrip

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testDecodeWithStrip() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new LineBasedFrameDecoder(8192, true, false));

    ch.writeInbound(copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII));
    assertEquals("first", releaseLater((ByteBuf) ch.readInbound()).toString(CharsetUtil.US_ASCII));
    assertEquals("second", releaseLater((ByteBuf) ch.readInbound()).toString(CharsetUtil.US_ASCII));
    assertNull(ch.readInbound());
    ch.finish();

    ReferenceCountUtil.release(ch.readInbound());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:13,代码来源:LineBasedFrameDecoderTest.java

示例14: testDecode

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testDecode() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(
            new DelimiterBasedFrameDecoder(8192, true, Delimiters.lineDelimiter()));

    ch.writeInbound(Unpooled.copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII));
    assertEquals("first", releaseLater((ByteBuf) ch.readInbound()).toString(CharsetUtil.US_ASCII));
    assertEquals("second", releaseLater((ByteBuf) ch.readInbound()).toString(CharsetUtil.US_ASCII));
    assertNull(ch.readInbound());
    ch.finish();

    ReferenceCountUtil.release(ch.readInbound());
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:14,代码来源:DelimiterBasedFrameDecoderTest.java

示例15: testMultipleLinesStrippedDelimiters

import io.netty.channel.embedded.EmbeddedChannel; //导入方法依赖的package包/类
@Test
public void testMultipleLinesStrippedDelimiters() {
    EmbeddedChannel ch = new EmbeddedChannel(new DelimiterBasedFrameDecoder(8192, true,
            Delimiters.lineDelimiter()));
    ch.writeInbound(Unpooled.copiedBuffer("TestLine\r\ng\r\n", Charset.defaultCharset()));
    assertEquals("TestLine", releaseLater((ByteBuf) ch.readInbound()).toString(Charset.defaultCharset()));
    assertEquals("g", releaseLater((ByteBuf) ch.readInbound()).toString(Charset.defaultCharset()));
    assertNull(ch.readInbound());
    ch.finish();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:11,代码来源:DelimiterBasedFrameDecoderTest.java


注:本文中的io.netty.channel.embedded.EmbeddedChannel.finish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。