Пример #1
0
  @Test(timeout = 10000)
  public void testBindDeadLock() throws Exception {
    final Bootstrap bootstrapA = new Bootstrap();
    bootstrapA.group(groupA);
    bootstrapA.channel(LocalChannel.class);
    bootstrapA.handler(dummyHandler);

    final Bootstrap bootstrapB = new Bootstrap();
    bootstrapB.group(groupB);
    bootstrapB.channel(LocalChannel.class);
    bootstrapB.handler(dummyHandler);

    List<Future<?>> bindFutures = new ArrayList<Future<?>>();

    // Try to bind from each other.
    for (int i = 0; i < 1024; i++) {
      bindFutures.add(
          groupA
              .next()
              .submit(
                  new Runnable() {
                    @Override
                    public void run() {
                      bootstrapB.bind(LocalAddress.ANY);
                    }
                  }));

      bindFutures.add(
          groupB
              .next()
              .submit(
                  new Runnable() {
                    @Override
                    public void run() {
                      bootstrapA.bind(LocalAddress.ANY);
                    }
                  }));
    }

    for (Future<?> f : bindFutures) {
      f.sync();
    }
  }
Пример #2
0
  @Test
  public void testAsyncResolutionSuccess() throws Exception {

    final Bootstrap bootstrapA = new Bootstrap();
    bootstrapA.group(groupA);
    bootstrapA.channel(LocalChannel.class);
    bootstrapA.resolver(new TestAddressResolverGroup(true));
    bootstrapA.handler(dummyHandler);

    final ServerBootstrap bootstrapB = new ServerBootstrap();
    bootstrapB.group(groupB);
    bootstrapB.channel(LocalServerChannel.class);
    bootstrapB.childHandler(dummyHandler);
    SocketAddress localAddress = bootstrapB.bind(LocalAddress.ANY).sync().channel().localAddress();

    // Connect to the server using the asynchronous resolver.
    bootstrapA.connect(localAddress).sync();
  }
Пример #3
0
  @Test
  public void testAsyncResolutionFailure() throws Exception {

    final Bootstrap bootstrapA = new Bootstrap();
    bootstrapA.group(groupA);
    bootstrapA.channel(LocalChannel.class);
    bootstrapA.resolver(new TestAddressResolverGroup(false));
    bootstrapA.handler(dummyHandler);

    final ServerBootstrap bootstrapB = new ServerBootstrap();
    bootstrapB.group(groupB);
    bootstrapB.channel(LocalServerChannel.class);
    bootstrapB.childHandler(dummyHandler);
    SocketAddress localAddress = bootstrapB.bind(LocalAddress.ANY).sync().channel().localAddress();

    // Connect to the server using the asynchronous resolver.
    ChannelFuture connectFuture = bootstrapA.connect(localAddress);

    // Should fail with the UnknownHostException.
    assertThat(connectFuture.await(10000), is(true));
    assertThat(connectFuture.cause(), is(instanceOf(UnknownHostException.class)));
    assertThat(connectFuture.channel().isOpen(), is(false));
  }