Java Code Examples for io.netty.channel.DefaultChannelId#newInstance()

The following examples show how to use io.netty.channel.DefaultChannelId#newInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WhoisServiceHandlerTest.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccess_ConnectionMetrics_twoConnections() {
  assertThat(channel.isActive()).isTrue();
  verify(metrics).registerActiveConnection(PROTOCOL, CLIENT_HASH, channel);

  // Setup second channel.
  WhoisServiceHandler whoisServiceHandler2 =
      new WhoisServiceHandler(RELAY_HOST, RELAY_PATH, () -> ACCESS_TOKEN, metrics);
  EmbeddedChannel channel2 =
      // We need a new channel id so that it has a different hash code.
      // This only is needed for EmbeddedChannel because it has a dummy hash code implementation.
      new EmbeddedChannel(DefaultChannelId.newInstance(), whoisServiceHandler2);
  assertThat(channel2.isActive()).isTrue();
  verify(metrics).registerActiveConnection(PROTOCOL, CLIENT_HASH, channel2);
  verifyNoMoreInteractions(metrics);
}
 
Example 2
Source File: MainLauncher.java    From AlipayWechatPlatform with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
    //Force to use slf4j
    DefaultChannelId.newInstance();
    System.setProperty("vertx.logger-delegate-factory-class-name",
            "io.vertx.core.logging.SLF4JLogDelegateFactory");
    String[] finalArgs = new String[3 + args.length];
    System.arraycopy(new String[]{"run", "com.turingdi.awp.verticle.MainVerticle", "-conf"}, 0, finalArgs, 0, 3);
    System.arraycopy(args, 0, finalArgs, 3, args.length);
    new Launcher().dispatch(finalArgs);
}
 
Example 3
Source File: EppServiceHandlerTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private EmbeddedChannel setUpNewChannel(EppServiceHandler handler) throws Exception {
  return new EmbeddedChannel(
      DefaultChannelId.newInstance(),
      new ChannelInitializer<EmbeddedChannel>() {
        @Override
        protected void initChannel(EmbeddedChannel ch) throws Exception {
          ch.attr(REMOTE_ADDRESS_KEY).set(CLIENT_ADDRESS);
          ch.attr(CLIENT_CERTIFICATE_PROMISE_KEY).set(ch.eventLoop().newPromise());
          ch.pipeline().addLast(handler);
        }
      });
}
 
Example 4
Source File: FrontendMetricsTest.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Test
public void testSuccess_twoConnections_sameClient() {
  EmbeddedChannel channel1 = new EmbeddedChannel();
  EmbeddedChannel channel2 = new EmbeddedChannel(DefaultChannelId.newInstance());

  metrics.registerActiveConnection(PROTOCOL, CERT_HASH, channel1);
  assertThat(channel1.isActive()).isTrue();
  assertThat(FrontendMetrics.activeConnectionsGauge)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();
  assertThat(FrontendMetrics.totalConnectionsCounter)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();

  metrics.registerActiveConnection(PROTOCOL, CERT_HASH, channel2);
  assertThat(channel2.isActive()).isTrue();
  assertThat(FrontendMetrics.activeConnectionsGauge)
      .hasValueForLabels(2, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();
  assertThat(FrontendMetrics.totalConnectionsCounter)
      .hasValueForLabels(2, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();

  @SuppressWarnings("unused")
  ChannelFuture unusedFuture1 = channel1.close();
  assertThat(channel1.isActive()).isFalse();
  assertThat(FrontendMetrics.activeConnectionsGauge)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();
  assertThat(FrontendMetrics.totalConnectionsCounter)
      .hasValueForLabels(2, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();

  @SuppressWarnings("unused")
  ChannelFuture unusedFuture2 = channel2.close();
  assertThat(channel2.isActive()).isFalse();
  assertThat(FrontendMetrics.activeConnectionsGauge).hasNoOtherValues();
  assertThat(FrontendMetrics.totalConnectionsCounter)
      .hasValueForLabels(2, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();
}
 
Example 5
Source File: FrontendMetricsTest.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Test
public void testSuccess_twoConnections_differentClients() {
  EmbeddedChannel channel1 = new EmbeddedChannel();
  EmbeddedChannel channel2 = new EmbeddedChannel(DefaultChannelId.newInstance());
  String certHash2 = "blahblah_lol_234";

  metrics.registerActiveConnection(PROTOCOL, CERT_HASH, channel1);
  assertThat(channel1.isActive()).isTrue();
  assertThat(FrontendMetrics.activeConnectionsGauge)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();
  assertThat(FrontendMetrics.totalConnectionsCounter)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasNoOtherValues();

  metrics.registerActiveConnection(PROTOCOL, certHash2, channel2);
  assertThat(channel2.isActive()).isTrue();
  assertThat(FrontendMetrics.activeConnectionsGauge)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasValueForLabels(1, PROTOCOL, certHash2)
      .and()
      .hasNoOtherValues();
  assertThat(FrontendMetrics.totalConnectionsCounter)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasValueForLabels(1, PROTOCOL, certHash2)
      .and()
      .hasNoOtherValues();

  ChannelFuture unusedFuture = channel1.close();
  assertThat(channel1.isActive()).isFalse();
  assertThat(FrontendMetrics.activeConnectionsGauge)
      .hasValueForLabels(1, PROTOCOL, certHash2)
      .and()
      .hasNoOtherValues();
  assertThat(FrontendMetrics.totalConnectionsCounter)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasValueForLabels(1, PROTOCOL, certHash2)
      .and()
      .hasNoOtherValues();

  unusedFuture = channel2.close();
  assertThat(channel2.isActive()).isFalse();
  assertThat(FrontendMetrics.activeConnectionsGauge).hasNoOtherValues();
  assertThat(FrontendMetrics.totalConnectionsCounter)
      .hasValueForLabels(1, PROTOCOL, CERT_HASH)
      .and()
      .hasValueForLabels(1, PROTOCOL, certHash2)
      .and()
      .hasNoOtherValues();
}