當前位置: 首頁>>代碼示例>>Java>>正文


Java EmbeddedChannel.close方法代碼示例

本文整理匯總了Java中io.netty.channel.embedded.EmbeddedChannel.close方法的典型用法代碼示例。如果您正苦於以下問題:Java EmbeddedChannel.close方法的具體用法?Java EmbeddedChannel.close怎麽用?Java EmbeddedChannel.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.channel.embedded.EmbeddedChannel的用法示例。


在下文中一共展示了EmbeddedChannel.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testReleaseOnSendToClosedChannel

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
public void testReleaseOnSendToClosedChannel() {
    final Settings settings = Settings.builder().build();
    final NamedXContentRegistry registry = xContentRegistry();
    try (Netty4HttpServerTransport httpServerTransport =
                 new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, registry, new NullDispatcher())) {
        final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
        final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
        final Netty4HttpRequest request = new Netty4HttpRequest(registry, httpRequest, embeddedChannel);
        final HttpPipelinedRequest pipelinedRequest = randomBoolean() ? new HttpPipelinedRequest(request.request(), 1) : null;
        final Netty4HttpChannel channel =
                new Netty4HttpChannel(httpServerTransport, request, pipelinedRequest, randomBoolean(), threadPool.getThreadContext());
        final TestResponse response = new TestResponse(bigArrays);
        assertThat(response.content(), instanceOf(Releasable.class));
        embeddedChannel.close();
        channel.sendResponse(response);
        // ESTestCase#after will invoke ensureAllArraysAreReleased which will fail if the response content was not released
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:Netty4HttpChannelTests.java

示例2: testSuccess_oneConnection

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void testSuccess_oneConnection() {
  EmbeddedChannel channel = new EmbeddedChannel();
  metrics.registerActiveConnection(PROTOCOL, CERT_HASH, channel);
  assertThat(channel.isActive()).isTrue();
  assertThat(FrontendMetrics.activeConnectionsGauge)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();
  assertThat(FrontendMetrics.totalConnectionsCounter)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();

  ChannelFuture unusedFuture = channel.close();
  assertThat(channel.isActive()).isFalse();
  assertThat(FrontendMetrics.activeConnectionsGauge).hasNoOtherValues();
  assertThat(FrontendMetrics.totalConnectionsCounter)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:23,代碼來源:FrontendMetricsTest.java

示例3: testFailureDecodeBadRsa

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test(expected = CorruptedFrameException.class)
public void testFailureDecodeBadRsa() throws Exception {
    // Decode our bad RSA key
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(TestVotifierPlugin.r("/bad_public.key"));
    PublicKey badPublicKey = keyFactory.generatePublic(publicKeySpec);

    // Send the bad vote
    EmbeddedChannel channel = createChannel();

    byte[] encrypted = VoteUtil.encodePOJOv1(new Vote("Test", "test", "test", "test"), badPublicKey);
    ByteBuf encryptedByteBuf = Unpooled.wrappedBuffer(encrypted);

    try {
        channel.writeInbound(encryptedByteBuf);
    } finally {
        channel.close();
    }
}
 
開發者ID:NuVotifier,項目名稱:NuVotifier,代碼行數:20,代碼來源:VotifierProtocol1DecoderTest.java

示例4: v1Test

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void v1Test() {
    EmbeddedChannel channel = new EmbeddedChannel(new VotifierProtocolDifferentiator(true, true));

    VotifierSession session = new VotifierSession();
    channel.attr(VotifierSession.KEY).set(session);

    ByteBuf test = Unpooled.buffer(256);
    for (int i = 0; i < 256; i++) {
        test.writeByte(0);
    }
    channel.writeInbound(test);

    assertEquals(VotifierSession.ProtocolVersion.ONE, session.getVersion());
    channel.close();
}
 
開發者ID:NuVotifier,項目名稱:NuVotifier,代碼行數:17,代碼來源:VotifierProtocolDifferentiatorTest.java

示例5: failIfv1NotSupported

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test(expected = DecoderException.class)
public void failIfv1NotSupported() {
    EmbeddedChannel channel = new EmbeddedChannel(new VotifierProtocolDifferentiator(true, false));

    VotifierSession session = new VotifierSession();
    channel.attr(VotifierSession.KEY).set(session);

    ByteBuf test = Unpooled.buffer(256);
    for (int i = 0; i < 256; i++) {
        test.writeByte(0);
    }
    channel.writeInbound(test);

    assertEquals(VotifierSession.ProtocolVersion.ONE, session.getVersion());
    channel.close();
}
 
開發者ID:NuVotifier,項目名稱:NuVotifier,代碼行數:17,代碼來源:VotifierProtocolDifferentiatorTest.java

示例6: tryIdentifyRealVotev1

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void tryIdentifyRealVotev1() throws Exception {
    EmbeddedChannel channel = new EmbeddedChannel(new VotifierProtocolDifferentiator(true, true));

    VotifierSession session = new VotifierSession();
    channel.attr(VotifierSession.KEY).set(session);

    Vote votePojo = new Vote("Test", "test", "test", "test");
    byte[] encrypted = VoteUtil.encodePOJOv1(votePojo);
    ByteBuf encryptedByteBuf = Unpooled.wrappedBuffer(encrypted);

    channel.writeInbound(encryptedByteBuf);

    assertEquals(VotifierSession.ProtocolVersion.ONE, session.getVersion());
    channel.close();
}
 
開發者ID:NuVotifier,項目名稱:NuVotifier,代碼行數:17,代碼來源:VotifierProtocolDifferentiatorTest.java

示例7: sendVote

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
private void sendVote(Vote vote, Key key, boolean expectSuccess) throws Exception {
    // Create a well-formed request
    EmbeddedChannel channel = createChannel();

    JSONObject object = new JSONObject();
    JSONObject payload = vote.serialize();
    payload.put("challenge", SESSION.getChallenge());
    object.put("payload", payload.toString());
    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(key);
    object.put("signature",
            Base64.getEncoder().encodeToString(mac.doFinal(payload.toString().getBytes(StandardCharsets.UTF_8))));

    if (expectSuccess) {
        assertTrue(channel.writeInbound(object.toString()));
        assertEquals(vote, channel.readInbound());
        assertFalse(channel.finish());
    } else {
        try {
            channel.writeInbound(object.toString());
        } finally {
            channel.close();
        }
    }
}
 
開發者ID:NuVotifier,項目名稱:NuVotifier,代碼行數:26,代碼來源:VotifierProtocol2DecoderTest.java

示例8: testFailureDecodeBadPacket

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test(expected = DecoderException.class)
public void testFailureDecodeBadPacket() throws Exception {
    // Create a well-formed request
    EmbeddedChannel channel = createChannel();

    Vote vote = new Vote("Test", "test", "test", "0");
    JSONObject object = new JSONObject();
    JSONObject payload = vote.serialize();
    payload.put("challenge", SESSION.getChallenge());
    object.put("payload", payload.toString());
    // We "forget" the signature.

    try {
        channel.writeInbound(object.toString());
    } finally {
        channel.close();
    }
}
 
開發者ID:NuVotifier,項目名稱:NuVotifier,代碼行數:19,代碼來源:VotifierProtocol2DecoderTest.java

示例9: testFailureDecodeBadVoteField

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test(expected = DecoderException.class)
public void testFailureDecodeBadVoteField() throws Exception {
    // Create a well-formed request
    EmbeddedChannel channel = createChannel();

    Vote vote = new Vote("Test", "test", "test", "0");
    JSONObject object = new JSONObject();
    JSONObject payload = vote.serialize();
    // We "forget" the challenge.
    object.put("payload", payload.toString());
    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(TestVotifierPlugin.getI().getTokens().get("default"));
    object.put("signature",
            Base64.getEncoder().encodeToString(mac.doFinal(payload.toString().getBytes(StandardCharsets.UTF_8))));

    try {
        channel.writeInbound(object.toString());
    } finally {
        channel.close();
    }
}
 
開發者ID:NuVotifier,項目名稱:NuVotifier,代碼行數:22,代碼來源:VotifierProtocol2DecoderTest.java

示例10: testFailureDecodeBadChallenge

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test(expected = DecoderException.class)
public void testFailureDecodeBadChallenge() throws Exception {
    // Create a well-formed request
    EmbeddedChannel channel = createChannel();

    Vote vote = new Vote("Test", "test", "test", "0");
    JSONObject object = new JSONObject();
    JSONObject payload = vote.serialize();
    // We provide the wrong challenge.
    payload.put("challenge", "not a challenge for me");
    object.put("payload", payload.toString());
    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(TestVotifierPlugin.getI().getTokens().get("default"));
    object.put("signature",
            Base64.getEncoder().encode(mac.doFinal(payload.toString().getBytes(StandardCharsets.UTF_8))));

    try {
        channel.writeInbound(object.toString());
    } finally {
        channel.close();
    }
}
 
開發者ID:NuVotifier,項目名稱:NuVotifier,代碼行數:23,代碼來源:VotifierProtocol2DecoderTest.java

示例11: testExceedMaxNumConnections

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void testExceedMaxNumConnections() {
    ConnectionLimitingHandler handler = new ConnectionLimitingHandler(1);

    EmbeddedChannel ch1 = new EmbeddedChannel(handler);
    ch1.writeInbound(ch1);
    assertThat(handler.numConnections()).isEqualTo(1);
    assertThat(ch1.isActive()).isTrue();

    EmbeddedChannel ch2 = new EmbeddedChannel(handler);
    ch2.writeInbound(ch2);
    assertThat(handler.numConnections()).isEqualTo(1);
    assertThat(ch2.isActive()).isFalse();

    ch1.close();
    assertThat(handler.numConnections()).isEqualTo(0);
}
 
開發者ID:line,項目名稱:armeria,代碼行數:18,代碼來源:ConnectionLimitingHandlerTest.java

示例12: testDelimitedLengths

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void testDelimitedLengths() throws Exception {
  Charset charset = CharsetUtil.ISO_8859_1;
  EmbeddedChannel ch = getTestChannel(charset, 100, 0, false);

  String v1 = "a";
  String v2 = "abcdefghij";
  String v3 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrsxt"
      + "uvwxyz";

  writeStringAndAssert(ch, v1, charset, false, false);
  writeStringAndAssert(ch, v2, charset, false, false);
  writeStringAndAssert(ch, v3, charset, false, true);

  writeStringAndAssert(ch, v1, charset, true, false);
  writeStringAndAssert(ch, v2, charset, true, false);
  writeStringAndAssert(ch, v3, charset, true, true);

  writeStringAndAssert(ch, v1, charset, false, false);

  ch.close();
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:23,代碼來源:TestDelimitedLengthFieldBasedFrameDecoder.java

示例13: testMaxFrameLengthOverflow

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void testMaxFrameLengthOverflow() throws Exception {
  Charset charset = CharsetUtil.ISO_8859_1;
  // maxFrameLength plus adjustment would overflow an int
  final long numBytes = Integer.MAX_VALUE - 1;
  final int lengthAdjustment = 10;
  EmbeddedChannel ch = getTestChannel(charset, (int) numBytes, lengthAdjustment, true);

  //this is a bad frame, but will still test the overflow condition
  String longString = String.valueOf(numBytes) + " abcd";

  try {
    ch.writeInbound(Unpooled.copiedBuffer(longString, charset));
    Assert.fail("TooLongFrameException should have been thrown");
  } catch (TooLongFrameException ignored) {
    //ignored
  }
  Assert.assertNull(ch.readInbound());

  ch.close();
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:22,代碼來源:TestDelimitedLengthFieldBasedFrameDecoder.java

示例14: decodeTest

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void decodeTest() throws Exception {
    ByteBuf buf = Unpooled.wrappedBuffer(DatatypeConverter.parseHexBinary("00000000030000006d7920766f696365206973206d792070617373706f72740000"));
    EmbeddedChannel channel = new EmbeddedChannel(new RconDecoder());
    try {
        channel.writeInbound(buf);
        RconMessage message = (RconMessage) channel.readInbound();
        RconMessage intended = new RconMessage(0, 3, "my voice is my passport");
        Assert.assertEquals("Read message is invalid.", intended, message);
    } finally {
        channel.close();
    }
}
 
開發者ID:voxelwind,項目名稱:voxelwind,代碼行數:14,代碼來源:RconEncodeDecodeTest.java

示例15: encodeTest

import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void encodeTest() throws Exception {
    EmbeddedChannel channel = new EmbeddedChannel(new RconEncoder());
    ByteBuf expected = Unpooled.wrappedBuffer(DatatypeConverter.parseHexBinary("00000000030000006d7920766f696365206973206d792070617373706f72740000"));
    try {
        channel.writeOutbound(new RconMessage(0, 3, "my voice is my passport"));
        ByteBuf buf = (ByteBuf) channel.readOutbound();
        Assert.assertEquals("Read message is invalid.", expected, buf);
    } finally {
        expected.release();
        channel.close();
    }
}
 
開發者ID:voxelwind,項目名稱:voxelwind,代碼行數:14,代碼來源:RconEncodeDecodeTest.java


注:本文中的io.netty.channel.embedded.EmbeddedChannel.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。