當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。