@Test
  public void securityCheckerTest() throws Exception {
    //secuirty validation success case, channel should not be closed.
    ServerMetrics metrics = new ServerMetrics(new MetricRegistry(), this.getClass(), this.getClass());
    EmbeddedChannel channel = createChannelSsl(metrics);
    SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
    Promise<Channel> promise = (Promise<Channel>) sslHandler.handshakeFuture();
    promise.setSuccess(channel);
    Assert.assertTrue("channel should not be closed", channel.isActive());
    Assert.assertEquals("validation success counter mismatch", 1,
        metrics.serverValidateConnectionSuccess.getCount());


    //security validation failure case (throw exception), channel should be closed.
    MockServerSecurityService mockServerSecurityService = (MockServerSecurityService)serverSecurityService;
    mockServerSecurityService.setThrowException(true);
    metrics = new ServerMetrics(new MetricRegistry(), this.getClass(), this.getClass());
    channel = createChannelSsl(metrics);
    sslHandler = channel.pipeline().get(SslHandler.class);
    promise = (Promise<Channel>) sslHandler.handshakeFuture();
    promise.setSuccess(channel);
    Assert.assertTrue("channel should be closed", !channel.isActive());
    Assert.assertEquals("validation success counter mismatch", 1,
        metrics.serverValidateConnectionFailure.getCount());

    //security validation failure case (service closed), channel should be closed.
    serverSecurityService.close();
    metrics = new ServerMetrics(new MetricRegistry(), this.getClass(), this.getClass());
    channel = createChannelSsl(metrics);
    sslHandler = channel.pipeline().get(SslHandler.class);
    promise = (Promise<Channel>) sslHandler.handshakeFuture();
    promise.setSuccess(channel);
    Assert.assertTrue("channel should be closed", !channel.isActive());
    Assert.assertEquals("validation success counter mismatch", 1,
        metrics.serverValidateConnectionFailure.getCount());



  }
Test the code flow where {@link ServerSecurityHandler} waits for the SSL handshake complete event and
apply security policy from channelActive method.
@throws Exception
ambry-rest/src/test/java/com/github/ambry/rest/ServerSecurityHandlerTest.java