// See https://github.com/netty/netty/issues/3967
  @Test
  public void testCloseChannelOnCreation() {
    EmbeddedChannel channel = new EmbeddedChannel();
    channel.close().syncUninterruptibly();

    final PendingWriteQueue queue = new PendingWriteQueue(channel.pipeline().firstContext());

    IllegalStateException ex = new IllegalStateException();
    ChannelPromise promise = channel.newPromise();
    queue.add(1L, promise);
    queue.removeAndFailAll(ex);
    assertSame(ex, promise.cause());
  }
  private void verifyFailure(String bad) throws Exception {
    // Send the bad vote
    EmbeddedChannel channel = createChannel();

    byte[] encrypted =
        RSA.encrypt(
            bad.getBytes(StandardCharsets.UTF_8),
            TestVotifierPlugin.getI().getProtocolV1Key().getPublic());
    ByteBuf encryptedByteBuf = Unpooled.wrappedBuffer(encrypted);

    try {
      channel.writeInbound(encryptedByteBuf);
    } finally {
      channel.close();
    }
  }
  @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();

    String voteString = "VOTE\nTest\ntest\ntest\ntest\n";
    byte[] encrypted = RSA.encrypt(voteString.getBytes(StandardCharsets.UTF_8), badPublicKey);
    ByteBuf encryptedByteBuf = Unpooled.wrappedBuffer(encrypted);

    try {
      channel.writeInbound(encryptedByteBuf);
    } finally {
      channel.close();
    }
  }