private TcpTransport<?> startTransport(Settings settings, ThreadPool threadPool) {
    BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
    TcpTransport<?> transport =
        new NettyTransport(
            settings,
            threadPool,
            new NetworkService(settings),
            bigArrays,
            new NamedWriteableRegistry(),
            new NoneCircuitBreakerService());
    transport.start();

    assertThat(transport.lifecycleState(), is(Lifecycle.State.STARTED));
    return transport;
  }
  public void testThatDefaultProfileInheritsFromStandardSettings() throws Exception {
    Settings settings =
        Settings.builder()
            .put("network.host", host)
            .put(TransportSettings.PORT.getKey(), 0)
            .put("transport.profiles.client1.port", 0)
            .build();

    ThreadPool threadPool = new TestThreadPool("tst");
    try (TcpTransport<?> transport = startTransport(settings, threadPool)) {
      assertEquals(1, transport.profileBoundAddresses().size());
      assertEquals(1, transport.boundAddress().boundAddresses().length);
    } finally {
      terminate(threadPool);
    }
  }
  public void testThatDefaultProfilePortOverridesGeneralConfiguration() throws Exception {
    Settings settings =
        Settings.builder()
            .put("network.host", host)
            .put(TransportSettings.PORT.getKey(), 22) // will not actually bind to this
            .put("transport.profiles.default.port", 0)
            .build();

    ThreadPool threadPool = new TestThreadPool("tst");
    try (TcpTransport<?> transport = startTransport(settings, threadPool)) {
      assertEquals(0, transport.profileBoundAddresses().size());
      assertEquals(1, transport.boundAddress().boundAddresses().length);
    } finally {
      terminate(threadPool);
    }
  }
  public void testThatProfileWithoutPortSettingsFails() throws Exception {

    Settings settings =
        Settings.builder()
            .put("network.host", host)
            .put(TransportSettings.PORT.getKey(), 0)
            .put("transport.profiles.client1.whatever", "foo")
            .build();

    ThreadPool threadPool = new TestThreadPool("tst");
    try (TcpTransport<?> transport = startTransport(settings, threadPool)) {
      assertEquals(0, transport.profileBoundAddresses().size());
      assertEquals(1, transport.boundAddress().boundAddresses().length);
    } finally {
      terminate(threadPool);
    }
  }
  public void testThatProfileWithoutValidNameIsIgnored() throws Exception {
    Settings settings =
        Settings.builder()
            .put("network.host", host)
            .put(TransportSettings.PORT.getKey(), 0)
            // mimics someone trying to define a profile for .local which is the profile for a node
            // request to itself
            .put(
                "transport.profiles." + TransportService.DIRECT_RESPONSE_PROFILE + ".port",
                22) // will not actually bind to this
            .put("transport.profiles..port", 23) // will not actually bind to this
            .build();

    ThreadPool threadPool = new TestThreadPool("tst");
    try (TcpTransport<?> transport = startTransport(settings, threadPool)) {
      assertEquals(0, transport.profileBoundAddresses().size());
      assertEquals(1, transport.boundAddress().boundAddresses().length);
    } finally {
      terminate(threadPool);
    }
  }