Move custom name resolvers to NetworkService CTOR

Instead of using NetworkModule we can directly inject them in NetworkService CTOR.

See https://github.com/elastic/elasticsearch/pull/15765#issuecomment-235307974
This commit is contained in:
David Pilato 2016-07-26 18:26:30 +02:00
parent 5e57febe53
commit fde15ae470
23 changed files with 97 additions and 94 deletions

View File

@ -64,6 +64,8 @@ import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TcpTransport; import org.elasticsearch.transport.TcpTransport;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import static org.elasticsearch.common.network.NetworkService.registerCustomNameResolvers;
/** /**
* The transport client allows to create a client that is not part of the cluster, but simply connects to one * The transport client allows to create a client that is not part of the cluster, but simply connects to one
* or more nodes directly by adding their respective addresses using {@link #addTransportAddress(org.elasticsearch.common.transport.TransportAddress)}. * or more nodes directly by adding their respective addresses using {@link #addTransportAddress(org.elasticsearch.common.transport.TransportAddress)}.
@ -106,7 +108,8 @@ public abstract class TransportClient extends AbstractClient {
final List<Closeable> resourcesToClose = new ArrayList<>(); final List<Closeable> resourcesToClose = new ArrayList<>();
final ThreadPool threadPool = new ThreadPool(settings); final ThreadPool threadPool = new ThreadPool(settings);
resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS)); resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS));
final NetworkService networkService = new NetworkService(settings); final NetworkService networkService = new NetworkService(settings,
registerCustomNameResolvers(settings, pluginsService.filterPlugins(DiscoveryPlugin.class)));
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
try { try {
final List<Setting<?>> additionalSettings = new ArrayList<>(); final List<Setting<?>> additionalSettings = new ArrayList<>();
@ -123,7 +126,7 @@ public abstract class TransportClient extends AbstractClient {
for (Module pluginModule : pluginsService.createGuiceModules()) { for (Module pluginModule : pluginsService.createGuiceModules()) {
modules.add(pluginModule); modules.add(pluginModule);
} }
modules.add(new NetworkModule(networkService, settings, true, namedWriteableRegistry, pluginsService.filterPlugins(DiscoveryPlugin.class))); modules.add(new NetworkModule(networkService, settings, true, namedWriteableRegistry));
modules.add(b -> b.bind(ThreadPool.class).toInstance(threadPool)); modules.add(b -> b.bind(ThreadPool.class).toInstance(threadPool));
modules.add(new SearchModule(settings, namedWriteableRegistry, true, pluginsService.filterPlugins(SearchPlugin.class))); modules.add(new SearchModule(settings, namedWriteableRegistry, true, pluginsService.filterPlugins(SearchPlugin.class)));
ActionModule actionModule = new ActionModule(false, true, settings, null, settingsModule.getClusterSettings(), ActionModule actionModule = new ActionModule(false, true, settings, null, settingsModule.getClusterSettings(),

View File

@ -38,17 +38,12 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.ExtensionPoint; import org.elasticsearch.common.util.ExtensionPoint;
import org.elasticsearch.http.HttpServer; import org.elasticsearch.http.HttpServer;
import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.http.HttpServerTransport;
import org.elasticsearch.plugins.DiscoveryPlugin;
import org.elasticsearch.tasks.RawTaskStatus; import org.elasticsearch.tasks.RawTaskStatus;
import org.elasticsearch.tasks.Task; import org.elasticsearch.tasks.Task;
import org.elasticsearch.transport.Transport; import org.elasticsearch.transport.Transport;
import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportService;
import org.elasticsearch.transport.local.LocalTransport; import org.elasticsearch.transport.local.LocalTransport;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* A module to handle registering and binding all network related classes. * A module to handle registering and binding all network related classes.
*/ */
@ -83,10 +78,9 @@ public class NetworkModule extends AbstractModule {
* @param settings The settings for the node * @param settings The settings for the node
* @param transportClient True if only transport classes should be allowed to be registered, false otherwise. * @param transportClient True if only transport classes should be allowed to be registered, false otherwise.
* @param namedWriteableRegistry registry for named writeables for use during streaming * @param namedWriteableRegistry registry for named writeables for use during streaming
* @param discoveryPlugins Discovery plugins
*/ */
public NetworkModule(NetworkService networkService, Settings settings, boolean transportClient, public NetworkModule(NetworkService networkService, Settings settings, boolean transportClient,
NamedWriteableRegistry namedWriteableRegistry, List<DiscoveryPlugin> discoveryPlugins) { NamedWriteableRegistry namedWriteableRegistry) {
this.networkService = networkService; this.networkService = networkService;
this.settings = settings; this.settings = settings;
this.transportClient = transportClient; this.transportClient = transportClient;
@ -96,7 +90,6 @@ public class NetworkModule extends AbstractModule {
registerTaskStatus(ReplicationTask.Status.NAME, ReplicationTask.Status::new); registerTaskStatus(ReplicationTask.Status.NAME, ReplicationTask.Status::new);
registerTaskStatus(RawTaskStatus.NAME, RawTaskStatus::new); registerTaskStatus(RawTaskStatus.NAME, RawTaskStatus::new);
registerBuiltinAllocationCommands(); registerBuiltinAllocationCommands();
registerCustomNameResolvers(discoveryPlugins);
} }
public boolean isTransportClient() { public boolean isTransportClient() {
@ -142,18 +135,6 @@ public class NetworkModule extends AbstractModule {
namedWriteableRegistry.register(AllocationCommand.class, commandName.getPreferredName(), reader); namedWriteableRegistry.register(AllocationCommand.class, commandName.getPreferredName(), reader);
} }
/**
* Register custom name resolver a DiscoveryPlugin might provide
* @param discoveryPlugins Discovery plugins
*/
private void registerCustomNameResolvers(List<DiscoveryPlugin> discoveryPlugins) {
for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) {
NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings);
if (customNameResolver != null) {
this.networkService.addCustomNameResolver(customNameResolver);
}
}
}
/** /**
* The registry of allocation command parsers. * The registry of allocation command parsers.
*/ */

View File

@ -26,6 +26,7 @@ import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.plugins.DiscoveryPlugin;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
@ -33,7 +34,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function; import java.util.function.Function;
@ -90,15 +90,12 @@ public class NetworkService extends AbstractComponent {
InetAddress[] resolveIfPossible(String value) throws IOException; InetAddress[] resolveIfPossible(String value) throws IOException;
} }
private final List<CustomNameResolver> customNameResolvers = new CopyOnWriteArrayList<>();; private final List<CustomNameResolver> customNameResolvers;
public NetworkService(Settings settings) { public NetworkService(Settings settings, List<CustomNameResolver> customNameResolvers) {
super(settings); super(settings);
IfConfig.logIfNecessary(); IfConfig.logIfNecessary();
} this.customNameResolvers = customNameResolvers;
public void addCustomNameResolver(CustomNameResolver customNameResolver) {
this.customNameResolvers.add(customNameResolver);
} }
/** /**
@ -273,4 +270,19 @@ public class NetworkService extends AbstractComponent {
} }
return InetAddress.getAllByName(host); return InetAddress.getAllByName(host);
} }
/**
* Register custom name resolver a DiscoveryPlugin might provide
* @param discoveryPlugins Discovery plugins
*/
public static List<CustomNameResolver> registerCustomNameResolvers(Settings settings, List<DiscoveryPlugin> discoveryPlugins) {
List<CustomNameResolver> customNameResolvers = new ArrayList<>();
for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) {
NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings);
if (customNameResolver != null) {
customNameResolvers.add(customNameResolver);
}
}
return customNameResolvers;
}
} }

View File

@ -133,9 +133,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.elasticsearch.common.network.NetworkService.registerCustomNameResolvers;
/** /**
* A node represent a node within a cluster (<tt>cluster.name</tt>). The {@link #client()} can be used * A node represent a node within a cluster (<tt>cluster.name</tt>). The {@link #client()} can be used
* in order to use a {@link Client} to perform actions/operations against the cluster. * in order to use a {@link Client} to perform actions/operations against the cluster.
@ -264,7 +265,8 @@ public class Node implements Closeable {
throw new IllegalStateException("Failed to created node environment", ex); throw new IllegalStateException("Failed to created node environment", ex);
} }
resourcesToClose.add(resourceWatcherService); resourcesToClose.add(resourceWatcherService);
final NetworkService networkService = new NetworkService(settings); final NetworkService networkService = new NetworkService(settings,
registerCustomNameResolvers(settings, pluginsService.filterPlugins(DiscoveryPlugin.class)));
final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool); final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool);
clusterService.add(scriptModule.getScriptService()); clusterService.add(scriptModule.getScriptService());
resourcesToClose.add(clusterService); resourcesToClose.add(clusterService);
@ -281,8 +283,7 @@ public class Node implements Closeable {
} }
final MonitorService monitorService = new MonitorService(settings, nodeEnvironment, threadPool); final MonitorService monitorService = new MonitorService(settings, nodeEnvironment, threadPool);
modules.add(new NodeModule(this, monitorService)); modules.add(new NodeModule(this, monitorService));
modules.add(new NetworkModule(networkService, settings, false, namedWriteableRegistry, modules.add(new NetworkModule(networkService, settings, false, namedWriteableRegistry));
pluginsService.filterPlugins(DiscoveryPlugin.class)));
modules.add(new DiscoveryModule(this.settings)); modules.add(new DiscoveryModule(this.settings));
ClusterModule clusterModule = new ClusterModule(settings, clusterService); ClusterModule clusterModule = new ClusterModule(settings, clusterService);
modules.add(clusterModule); modules.add(clusterModule);

View File

@ -75,8 +75,7 @@ public class ClusterRerouteRequestTests extends ESTestCase {
public ClusterRerouteRequestTests() { public ClusterRerouteRequestTests() {
namedWriteableRegistry = new NamedWriteableRegistry(); namedWriteableRegistry = new NamedWriteableRegistry();
allocationCommandRegistry = new NetworkModule(null, null, true, namedWriteableRegistry, Collections.emptyList()) allocationCommandRegistry = new NetworkModule(null, null, true, namedWriteableRegistry).getAllocationCommandRegistry();
.getAllocationCommandRegistry();
} }
private ClusterRerouteRequest randomRequest() { private ClusterRerouteRequest randomRequest() {

View File

@ -65,7 +65,7 @@ public class ClusterRerouteTests extends ESAllocationTestCase {
req.writeTo(out); req.writeTo(out);
BytesReference bytes = out.bytes(); BytesReference bytes = out.bytes();
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
new NetworkModule(null, Settings.EMPTY, true, namedWriteableRegistry, Collections.emptyList()); new NetworkModule(null, Settings.EMPTY, true, namedWriteableRegistry);
StreamInput wrap = new NamedWriteableAwareStreamInput(bytes.streamInput(), StreamInput wrap = new NamedWriteableAwareStreamInput(bytes.streamInput(),
namedWriteableRegistry); namedWriteableRegistry);
ClusterRerouteRequest deserializedReq = new ClusterRerouteRequest(); ClusterRerouteRequest deserializedReq = new ClusterRerouteRequest();

View File

@ -437,7 +437,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
// Since the commands are named writeable we need to register them and wrap the input stream // Since the commands are named writeable we need to register them and wrap the input stream
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
new NetworkModule(null, Settings.EMPTY, true, namedWriteableRegistry, Collections.emptyList()); new NetworkModule(null, Settings.EMPTY, true, namedWriteableRegistry);
in = new NamedWriteableAwareStreamInput(in, namedWriteableRegistry); in = new NamedWriteableAwareStreamInput(in, namedWriteableRegistry);
// Now we can read them! // Now we can read them!
@ -483,8 +483,8 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
// move two tokens, parser expected to be "on" `commands` field // move two tokens, parser expected to be "on" `commands` field
parser.nextToken(); parser.nextToken();
parser.nextToken(); parser.nextToken();
AllocationCommandRegistry registry = new NetworkModule(null, Settings.EMPTY, true, new NamedWriteableRegistry(), AllocationCommandRegistry registry = new NetworkModule(null, Settings.EMPTY, true, new NamedWriteableRegistry())
Collections.emptyList()).getAllocationCommandRegistry(); .getAllocationCommandRegistry();
AllocationCommands sCommands = AllocationCommands.fromXContent(parser, ParseFieldMatcher.STRICT, registry); AllocationCommands sCommands = AllocationCommands.fromXContent(parser, ParseFieldMatcher.STRICT, registry);
assertThat(sCommands.commands().size(), equalTo(5)); assertThat(sCommands.commands().size(), equalTo(5));

View File

@ -113,14 +113,14 @@ public class NetworkModuleTests extends ModuleTestCase {
.put(NetworkModule.HTTP_ENABLED.getKey(), false) .put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local") .put(NetworkModule.TRANSPORT_TYPE_KEY, "local")
.build(); .build();
NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry(), NetworkModule module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, false,
Collections.emptyList()); new NamedWriteableRegistry());
module.registerTransportService("custom", FakeTransportService.class); module.registerTransportService("custom", FakeTransportService.class);
assertBinding(module, TransportService.class, FakeTransportService.class); assertBinding(module, TransportService.class, FakeTransportService.class);
assertFalse(module.isTransportClient()); assertFalse(module.isTransportClient());
// check it works with transport only as well // check it works with transport only as well
module = new NetworkModule(new NetworkService(settings), settings, true, new NamedWriteableRegistry(), Collections.emptyList()); module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, true, new NamedWriteableRegistry());
module.registerTransportService("custom", FakeTransportService.class); module.registerTransportService("custom", FakeTransportService.class);
assertBinding(module, TransportService.class, FakeTransportService.class); assertBinding(module, TransportService.class, FakeTransportService.class);
assertTrue(module.isTransportClient()); assertTrue(module.isTransportClient());
@ -130,14 +130,14 @@ public class NetworkModuleTests extends ModuleTestCase {
Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "custom") Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "custom")
.put(NetworkModule.HTTP_ENABLED.getKey(), false) .put(NetworkModule.HTTP_ENABLED.getKey(), false)
.build(); .build();
NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry(), NetworkModule module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, false,
Collections.emptyList()); new NamedWriteableRegistry());
module.registerTransport("custom", FakeTransport.class); module.registerTransport("custom", FakeTransport.class);
assertBinding(module, Transport.class, FakeTransport.class); assertBinding(module, Transport.class, FakeTransport.class);
assertFalse(module.isTransportClient()); assertFalse(module.isTransportClient());
// check it works with transport only as well // check it works with transport only as well
module = new NetworkModule(new NetworkService(settings), settings, true, new NamedWriteableRegistry(), Collections.emptyList()); module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, true, new NamedWriteableRegistry());
module.registerTransport("custom", FakeTransport.class); module.registerTransport("custom", FakeTransport.class);
assertBinding(module, Transport.class, FakeTransport.class); assertBinding(module, Transport.class, FakeTransport.class);
assertTrue(module.isTransportClient()); assertTrue(module.isTransportClient());
@ -147,14 +147,14 @@ public class NetworkModuleTests extends ModuleTestCase {
Settings settings = Settings.builder() Settings settings = Settings.builder()
.put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom") .put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom")
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build(); .put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry(), NetworkModule module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, false,
Collections.emptyList()); new NamedWriteableRegistry());
module.registerHttpTransport("custom", FakeHttpTransport.class); module.registerHttpTransport("custom", FakeHttpTransport.class);
assertBinding(module, HttpServerTransport.class, FakeHttpTransport.class); assertBinding(module, HttpServerTransport.class, FakeHttpTransport.class);
assertFalse(module.isTransportClient()); assertFalse(module.isTransportClient());
// check registration not allowed for transport only // check registration not allowed for transport only
module = new NetworkModule(new NetworkService(settings), settings, true, new NamedWriteableRegistry(), Collections.emptyList()); module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, true, new NamedWriteableRegistry());
assertTrue(module.isTransportClient()); assertTrue(module.isTransportClient());
try { try {
module.registerHttpTransport("custom", FakeHttpTransport.class); module.registerHttpTransport("custom", FakeHttpTransport.class);
@ -167,7 +167,7 @@ public class NetworkModuleTests extends ModuleTestCase {
// not added if http is disabled // not added if http is disabled
settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false) settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false)
.put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build(); .put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build();
module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry(), Collections.emptyList()); module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, false, new NamedWriteableRegistry());
assertNotBound(module, HttpServerTransport.class); assertNotBound(module, HttpServerTransport.class);
assertFalse(module.isTransportClient()); assertFalse(module.isTransportClient());
} }
@ -175,7 +175,7 @@ public class NetworkModuleTests extends ModuleTestCase {
public void testRegisterTaskStatus() { public void testRegisterTaskStatus() {
NamedWriteableRegistry registry = new NamedWriteableRegistry(); NamedWriteableRegistry registry = new NamedWriteableRegistry();
Settings settings = Settings.EMPTY; Settings settings = Settings.EMPTY;
NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, registry, Collections.emptyList()); NetworkModule module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, false, registry);
assertFalse(module.isTransportClient()); assertFalse(module.isTransportClient());
// Builtin reader comes back // Builtin reader comes back

View File

@ -23,6 +23,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Collections;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -36,7 +37,7 @@ public class NetworkServiceTests extends ESTestCase {
* ensure exception if we bind to multicast ipv4 address * ensure exception if we bind to multicast ipv4 address
*/ */
public void testBindMulticastV4() throws Exception { public void testBindMulticastV4() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY); NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
try { try {
service.resolveBindHostAddresses(new String[] { "239.1.1.1" }); service.resolveBindHostAddresses(new String[] { "239.1.1.1" });
fail("should have hit exception"); fail("should have hit exception");
@ -48,7 +49,7 @@ public class NetworkServiceTests extends ESTestCase {
* ensure exception if we bind to multicast ipv6 address * ensure exception if we bind to multicast ipv6 address
*/ */
public void testBindMulticastV6() throws Exception { public void testBindMulticastV6() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY); NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
try { try {
service.resolveBindHostAddresses(new String[] { "FF08::108" }); service.resolveBindHostAddresses(new String[] { "FF08::108" });
fail("should have hit exception"); fail("should have hit exception");
@ -61,7 +62,7 @@ public class NetworkServiceTests extends ESTestCase {
* ensure exception if we publish to multicast ipv4 address * ensure exception if we publish to multicast ipv4 address
*/ */
public void testPublishMulticastV4() throws Exception { public void testPublishMulticastV4() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY); NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
try { try {
service.resolvePublishHostAddresses(new String[] { "239.1.1.1" }); service.resolvePublishHostAddresses(new String[] { "239.1.1.1" });
fail("should have hit exception"); fail("should have hit exception");
@ -74,7 +75,7 @@ public class NetworkServiceTests extends ESTestCase {
* ensure exception if we publish to multicast ipv6 address * ensure exception if we publish to multicast ipv6 address
*/ */
public void testPublishMulticastV6() throws Exception { public void testPublishMulticastV6() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY); NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
try { try {
service.resolvePublishHostAddresses(new String[] { "FF08::108" }); service.resolvePublishHostAddresses(new String[] { "FF08::108" });
fail("should have hit exception"); fail("should have hit exception");
@ -87,7 +88,7 @@ public class NetworkServiceTests extends ESTestCase {
* ensure specifying wildcard ipv4 address will bind to all interfaces * ensure specifying wildcard ipv4 address will bind to all interfaces
*/ */
public void testBindAnyLocalV4() throws Exception { public void testBindAnyLocalV4() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY); NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
assertEquals(InetAddress.getByName("0.0.0.0"), service.resolveBindHostAddresses(new String[] { "0.0.0.0" })[0]); assertEquals(InetAddress.getByName("0.0.0.0"), service.resolveBindHostAddresses(new String[] { "0.0.0.0" })[0]);
} }
@ -95,7 +96,7 @@ public class NetworkServiceTests extends ESTestCase {
* ensure specifying wildcard ipv6 address will bind to all interfaces * ensure specifying wildcard ipv6 address will bind to all interfaces
*/ */
public void testBindAnyLocalV6() throws Exception { public void testBindAnyLocalV6() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY); NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
assertEquals(InetAddress.getByName("::"), service.resolveBindHostAddresses(new String[] { "::" })[0]); assertEquals(InetAddress.getByName("::"), service.resolveBindHostAddresses(new String[] { "::" })[0]);
} }
@ -103,7 +104,7 @@ public class NetworkServiceTests extends ESTestCase {
* ensure specifying wildcard ipv4 address selects reasonable publish address * ensure specifying wildcard ipv4 address selects reasonable publish address
*/ */
public void testPublishAnyLocalV4() throws Exception { public void testPublishAnyLocalV4() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY); NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
InetAddress address = service.resolvePublishHostAddresses(new String[] { "0.0.0.0" }); InetAddress address = service.resolvePublishHostAddresses(new String[] { "0.0.0.0" });
assertFalse(address.isAnyLocalAddress()); assertFalse(address.isAnyLocalAddress());
} }
@ -112,7 +113,7 @@ public class NetworkServiceTests extends ESTestCase {
* ensure specifying wildcard ipv6 address selects reasonable publish address * ensure specifying wildcard ipv6 address selects reasonable publish address
*/ */
public void testPublishAnyLocalV6() throws Exception { public void testPublishAnyLocalV6() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY); NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
InetAddress address = service.resolvePublishHostAddresses(new String[] { "::" }); InetAddress address = service.resolvePublishHostAddresses(new String[] { "::" });
assertFalse(address.isAnyLocalAddress()); assertFalse(address.isAnyLocalAddress());
} }
@ -121,7 +122,7 @@ public class NetworkServiceTests extends ESTestCase {
* ensure we can bind to multiple addresses * ensure we can bind to multiple addresses
*/ */
public void testBindMultipleAddresses() throws Exception { public void testBindMultipleAddresses() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY); NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
InetAddress[] addresses = service.resolveBindHostAddresses(new String[]{"127.0.0.1", "127.0.0.2"}); InetAddress[] addresses = service.resolveBindHostAddresses(new String[]{"127.0.0.1", "127.0.0.2"});
assertThat(addresses.length, is(2)); assertThat(addresses.length, is(2));
} }
@ -130,7 +131,7 @@ public class NetworkServiceTests extends ESTestCase {
* ensure we can't bind to multiple addresses when using wildcard * ensure we can't bind to multiple addresses when using wildcard
*/ */
public void testBindMultipleAddressesWithWildcard() throws Exception { public void testBindMultipleAddressesWithWildcard() throws Exception {
NetworkService service = new NetworkService(Settings.EMPTY); NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList());
try { try {
service.resolveBindHostAddresses(new String[]{"0.0.0.0", "127.0.0.1"}); service.resolveBindHostAddresses(new String[]{"0.0.0.0", "127.0.0.1"});
fail("should have hit exception"); fail("should have hit exception");

View File

@ -45,6 +45,7 @@ import org.elasticsearch.transport.TransportService;
import org.elasticsearch.transport.TransportSettings; import org.elasticsearch.transport.TransportSettings;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -66,7 +67,7 @@ public class UnicastZenPingIT extends ESTestCase {
.put(TransportSettings.PORT.getKey(), startPort + "-" + endPort).build(); .put(TransportSettings.PORT.getKey(), startPort + "-" + endPort).build();
ThreadPool threadPool = new TestThreadPool(getClass().getName()); ThreadPool threadPool = new TestThreadPool(getClass().getName());
NetworkService networkService = new NetworkService(settings); NetworkService networkService = new NetworkService(settings, Collections.emptyList());
ElectMasterService electMasterService = new ElectMasterService(settings); ElectMasterService electMasterService = new ElectMasterService(settings);
NetworkHandle handleA = startServices(settings, threadPool, networkService, "UZP_A", Version.CURRENT); NetworkHandle handleA = startServices(settings, threadPool, networkService, "UZP_A", Version.CURRENT);

View File

@ -36,6 +36,7 @@ import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -63,7 +64,7 @@ public class TransportServiceHandshakeTests extends ESTestCase {
BigArrays.NON_RECYCLING_INSTANCE, BigArrays.NON_RECYCLING_INSTANCE,
new NoneCircuitBreakerService(), new NoneCircuitBreakerService(),
new NamedWriteableRegistry(), new NamedWriteableRegistry(),
new NetworkService(settings)); new NetworkService(settings, Collections.emptyList()));
TransportService transportService = new MockTransportService(settings, transport, threadPool); TransportService transportService = new MockTransportService(settings, transport, threadPool);
transportService.start(); transportService.start();
transportService.acceptIncomingRequests(); transportService.acceptIncomingRequests();

View File

@ -50,6 +50,7 @@ import org.junit.Before;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import static org.elasticsearch.http.HttpTransportSettings.SETTING_CORS_ALLOW_CREDENTIALS; import static org.elasticsearch.http.HttpTransportSettings.SETTING_CORS_ALLOW_CREDENTIALS;
@ -70,7 +71,7 @@ public class Netty3HttpChannelTests extends ESTestCase {
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
networkService = new NetworkService(Settings.EMPTY); networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
threadPool = new TestThreadPool("test"); threadPool = new TestThreadPool("test");
bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
} }

View File

@ -49,6 +49,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -72,7 +73,7 @@ public class Netty3HttpServerPipeliningTests extends ESTestCase {
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
networkService = new NetworkService(Settings.EMPTY); networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
threadPool = new TestThreadPool("test"); threadPool = new TestThreadPool("test");
bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
} }

View File

@ -33,6 +33,7 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -54,7 +55,7 @@ public class Netty3HttpServerTransportTests extends ESTestCase {
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
networkService = new NetworkService(Settings.EMPTY); networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
threadPool = new TestThreadPool("test"); threadPool = new TestThreadPool("test");
bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
} }

View File

@ -38,6 +38,7 @@ import java.io.InputStreamReader;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Collections;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
@ -61,7 +62,7 @@ public class Netty3SizeHeaderFrameDecoderTests extends ESTestCase {
@Before @Before
public void startThreadPool() { public void startThreadPool() {
threadPool = new ThreadPool(settings); threadPool = new ThreadPool(settings);
NetworkService networkService = new NetworkService(settings); NetworkService networkService = new NetworkService(settings, Collections.emptyList());
BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
nettyTransport = new Netty3Transport(settings, threadPool, networkService, bigArrays, new NamedWriteableRegistry(), nettyTransport = new Netty3Transport(settings, threadPool, networkService, bigArrays, new NamedWriteableRegistry(),
new NoneCircuitBreakerService()); new NoneCircuitBreakerService());

View File

@ -43,6 +43,7 @@ import org.elasticsearch.transport.TransportResponseOptions;
import org.elasticsearch.transport.TransportSettings; import org.elasticsearch.transport.TransportSettings;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet; import static java.util.Collections.emptySet;
@ -62,14 +63,14 @@ public class Netty3ScheduledPingTests extends ESTestCase {
CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService(); CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService();
NamedWriteableRegistry registryA = new NamedWriteableRegistry(); NamedWriteableRegistry registryA = new NamedWriteableRegistry();
final Netty3Transport nettyA = new Netty3Transport(settings, threadPool, new NetworkService(settings), final Netty3Transport nettyA = new Netty3Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()),
BigArrays.NON_RECYCLING_INSTANCE, registryA, circuitBreakerService); BigArrays.NON_RECYCLING_INSTANCE, registryA, circuitBreakerService);
MockTransportService serviceA = new MockTransportService(settings, nettyA, threadPool); MockTransportService serviceA = new MockTransportService(settings, nettyA, threadPool);
serviceA.start(); serviceA.start();
serviceA.acceptIncomingRequests(); serviceA.acceptIncomingRequests();
NamedWriteableRegistry registryB = new NamedWriteableRegistry(); NamedWriteableRegistry registryB = new NamedWriteableRegistry();
final Netty3Transport nettyB = new Netty3Transport(settings, threadPool, new NetworkService(settings), final Netty3Transport nettyB = new Netty3Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()),
BigArrays.NON_RECYCLING_INSTANCE, registryB, circuitBreakerService); BigArrays.NON_RECYCLING_INSTANCE, registryB, circuitBreakerService);
MockTransportService serviceB = new MockTransportService(settings, nettyB, threadPool); MockTransportService serviceB = new MockTransportService(settings, nettyB, threadPool);

View File

@ -34,6 +34,8 @@ import org.elasticsearch.transport.TransportService;
import org.elasticsearch.transport.TransportSettings; import org.elasticsearch.transport.TransportSettings;
import org.junit.Before; import org.junit.Before;
import java.util.Collections;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
public class Netty3TransportMultiPortTests extends ESTestCase { public class Netty3TransportMultiPortTests extends ESTestCase {
@ -135,8 +137,8 @@ public class Netty3TransportMultiPortTests extends ESTestCase {
private TcpTransport<?> startTransport(Settings settings, ThreadPool threadPool) { private TcpTransport<?> startTransport(Settings settings, ThreadPool threadPool) {
BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
TcpTransport<?> transport = new Netty3Transport(settings, threadPool, new NetworkService(settings), bigArrays, TcpTransport<?> transport = new Netty3Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()),
new NamedWriteableRegistry(), new NoneCircuitBreakerService()); bigArrays, new NamedWriteableRegistry(), new NoneCircuitBreakerService());
transport.start(); transport.start();
assertThat(transport.lifecycleState(), is(Lifecycle.State.STARTED)); assertThat(transport.lifecycleState(), is(Lifecycle.State.STARTED));

View File

@ -36,6 +36,7 @@ import org.elasticsearch.transport.TransportSettings;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Collections;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet; import static java.util.Collections.emptySet;
@ -47,8 +48,8 @@ public class SimpleNetty3TransportTests extends AbstractSimpleTransportTestCase
Settings settings, Settings settings,
ThreadPool threadPool, final Version version) { ThreadPool threadPool, final Version version) {
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
Transport transport = new Netty3Transport(settings, threadPool, new NetworkService(settings), BigArrays.NON_RECYCLING_INSTANCE, Transport transport = new Netty3Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()),
namedWriteableRegistry, new NoneCircuitBreakerService()) { BigArrays.NON_RECYCLING_INSTANCE, namedWriteableRegistry, new NoneCircuitBreakerService()) {
@Override @Override
protected Version getCurrentVersion() { protected Version getCurrentVersion() {
return version; return version;

View File

@ -26,6 +26,7 @@ import org.elasticsearch.test.ESTestCase;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.Collections;
import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
@ -42,8 +43,7 @@ public class Ec2NetworkTests extends ESTestCase {
.put("network.host", "_ec2_") .put("network.host", "_ec2_")
.build(); .build();
NetworkService networkService = new NetworkService(nodeSettings); NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings)));
networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings));
// TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach.
try { try {
networkService.resolveBindHostAddresses(null); networkService.resolveBindHostAddresses(null);
@ -60,8 +60,7 @@ public class Ec2NetworkTests extends ESTestCase {
.put("network.host", "_ec2:publicIp_") .put("network.host", "_ec2:publicIp_")
.build(); .build();
NetworkService networkService = new NetworkService(nodeSettings); NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings)));
networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings));
// TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach.
try { try {
networkService.resolveBindHostAddresses(null); networkService.resolveBindHostAddresses(null);
@ -78,8 +77,7 @@ public class Ec2NetworkTests extends ESTestCase {
.put("network.host", "_ec2:privateIp_") .put("network.host", "_ec2:privateIp_")
.build(); .build();
NetworkService networkService = new NetworkService(nodeSettings); NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings)));
networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings));
// TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach.
try { try {
networkService.resolveBindHostAddresses(null); networkService.resolveBindHostAddresses(null);
@ -96,8 +94,7 @@ public class Ec2NetworkTests extends ESTestCase {
.put("network.host", "_ec2:privateIpv4_") .put("network.host", "_ec2:privateIpv4_")
.build(); .build();
NetworkService networkService = new NetworkService(nodeSettings); NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings)));
networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings));
// TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach.
try { try {
networkService.resolveBindHostAddresses(null); networkService.resolveBindHostAddresses(null);
@ -114,8 +111,7 @@ public class Ec2NetworkTests extends ESTestCase {
.put("network.host", "_ec2:privateDns_") .put("network.host", "_ec2:privateDns_")
.build(); .build();
NetworkService networkService = new NetworkService(nodeSettings); NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings)));
networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings));
// TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach.
try { try {
networkService.resolveBindHostAddresses(null); networkService.resolveBindHostAddresses(null);
@ -132,8 +128,7 @@ public class Ec2NetworkTests extends ESTestCase {
.put("network.host", "_ec2:publicIpv4_") .put("network.host", "_ec2:publicIpv4_")
.build(); .build();
NetworkService networkService = new NetworkService(nodeSettings); NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings)));
networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings));
// TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach.
try { try {
networkService.resolveBindHostAddresses(null); networkService.resolveBindHostAddresses(null);
@ -150,8 +145,7 @@ public class Ec2NetworkTests extends ESTestCase {
.put("network.host", "_ec2:publicDns_") .put("network.host", "_ec2:publicDns_")
.build(); .build();
NetworkService networkService = new NetworkService(nodeSettings); NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings)));
networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings));
// TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach.
try { try {
networkService.resolveBindHostAddresses(null); networkService.resolveBindHostAddresses(null);
@ -169,8 +163,7 @@ public class Ec2NetworkTests extends ESTestCase {
.put("network.host", "_local_") .put("network.host", "_local_")
.build(); .build();
NetworkService networkService = new NetworkService(nodeSettings); NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings)));
networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings));
InetAddress[] addresses = networkService.resolveBindHostAddresses(null); InetAddress[] addresses = networkService.resolveBindHostAddresses(null);
assertThat(addresses, arrayContaining(networkService.resolveBindHostAddresses(new String[] { "_local_" }))); assertThat(addresses, arrayContaining(networkService.resolveBindHostAddresses(new String[] { "_local_" })));
} }

View File

@ -34,6 +34,7 @@ import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -106,7 +107,7 @@ public class GceDiscoveryTests extends ESTestCase {
protected List<DiscoveryNode> buildDynamicNodes(GceInstancesService gceInstancesService, Settings nodeSettings) { protected List<DiscoveryNode> buildDynamicNodes(GceInstancesService gceInstancesService, Settings nodeSettings) {
GceUnicastHostsProvider provider = new GceUnicastHostsProvider(nodeSettings, gceInstancesService, GceUnicastHostsProvider provider = new GceUnicastHostsProvider(nodeSettings, gceInstancesService,
transportService, new NetworkService(Settings.EMPTY)); transportService, new NetworkService(Settings.EMPTY, Collections.emptyList()));
List<DiscoveryNode> discoveryNodes = provider.buildDynamicNodes(); List<DiscoveryNode> discoveryNodes = provider.buildDynamicNodes();
logger.info("--> nodes found: {}", discoveryNodes); logger.info("--> nodes found: {}", discoveryNodes);

View File

@ -37,7 +37,7 @@ import java.io.InputStream;
import java.net.URL; import java.net.URL;
public class GceMockUtils { public class GceMockUtils {
protected final static ESLogger logger = Loggers.getLogger(GceMockUtils.class); protected static final ESLogger logger = Loggers.getLogger(GceMockUtils.class);
public static final String GCE_METADATA_URL = "http://metadata.google.internal/computeMetadata/v1/instance"; public static final String GCE_METADATA_URL = "http://metadata.google.internal/computeMetadata/v1/instance";

View File

@ -81,7 +81,8 @@ public class GceNetworkTests extends ESTestCase {
* network.host: _local_ * network.host: _local_
*/ */
public void networkHostCoreLocal() throws IOException { public void networkHostCoreLocal() throws IOException {
resolveGce("_local_", new NetworkService(Settings.EMPTY).resolveBindHostAddresses(new String[] { NetworkService.DEFAULT_NETWORK_HOST })); resolveGce("_local_", new NetworkService(Settings.EMPTY, Collections.emptyList())
.resolveBindHostAddresses(new String[] { NetworkService.DEFAULT_NETWORK_HOST }));
} }
/** /**
@ -105,9 +106,8 @@ public class GceNetworkTests extends ESTestCase {
.put("network.host", gceNetworkSetting) .put("network.host", gceNetworkSetting)
.build(); .build();
NetworkService networkService = new NetworkService(nodeSettings);
GceMetadataServiceMock mock = new GceMetadataServiceMock(nodeSettings); GceMetadataServiceMock mock = new GceMetadataServiceMock(nodeSettings);
networkService.addCustomNameResolver(new GceNameResolver(nodeSettings, mock)); NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new GceNameResolver(nodeSettings, mock)));
try { try {
InetAddress[] addresses = networkService.resolveBindHostAddresses(null); InetAddress[] addresses = networkService.resolveBindHostAddresses(null);
if (expected == null) { if (expected == null) {

View File

@ -26,12 +26,14 @@ import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.test.transport.MockTransportService;
import java.util.Collections;
public class MockTcpTransportTests extends AbstractSimpleTransportTestCase { public class MockTcpTransportTests extends AbstractSimpleTransportTestCase {
@Override @Override
protected MockTransportService build(Settings settings, Version version) { protected MockTransportService build(Settings settings, Version version) {
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
Transport transport = new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE, Transport transport = new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE,
new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(settings), version); new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(settings, Collections.emptyList()), version);
MockTransportService mockTransportService = new MockTransportService(Settings.EMPTY, transport, threadPool); MockTransportService mockTransportService = new MockTransportService(Settings.EMPTY, transport, threadPool);
mockTransportService.start(); mockTransportService.start();
return mockTransportService; return mockTransportService;