当前位置: 首页>>代码示例>>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;未经允许,请勿转载。