Remove `MockTcpTransport` for ESIntegTestCase (#36089)

This commit removes the `MockTcpTransport` as a transport option for
`ESIntegTestCase`. It is the first step in replacing the usages of
`MockTcpTransport` with `MockNioTransport`.
This commit is contained in:
Tim Brooks 2018-11-30 09:04:51 -07:00 committed by GitHub
parent da100c5479
commit 26dcbcc8cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 10 additions and 92 deletions

View File

@ -19,8 +19,8 @@
package org.elasticsearch.smoketest; package org.elasticsearch.smoketest;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
@ -30,7 +30,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.transport.MockTcpTransportPlugin;
import org.elasticsearch.transport.client.PreBuiltTransportClient; import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.elasticsearch.transport.nio.MockNioTransportPlugin; import org.elasticsearch.transport.nio.MockNioTransportPlugin;
import org.junit.After; import org.junit.After;
@ -82,16 +81,8 @@ public abstract class ESSmokeClientTestCase extends LuceneTestCase {
.put("client.transport.ignore_cluster_name", true) .put("client.transport.ignore_cluster_name", true)
.put(Environment.PATH_HOME_SETTING.getKey(), tempDir); .put(Environment.PATH_HOME_SETTING.getKey(), tempDir);
final Collection<Class<? extends Plugin>> plugins; final Collection<Class<? extends Plugin>> plugins;
boolean usNio = random().nextBoolean(); String transportKey = MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME;
String transportKey; Class<? extends Plugin> transportPlugin = MockNioTransportPlugin.class;
Class<? extends Plugin> transportPlugin;
if (usNio) {
transportKey = MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME;
transportPlugin = MockNioTransportPlugin.class;
} else {
transportKey = MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME;
transportPlugin = MockTcpTransportPlugin.class;
}
if (random().nextBoolean()) { if (random().nextBoolean()) {
builder.put(NetworkModule.TRANSPORT_TYPE_KEY, transportKey); builder.put(NetworkModule.TRANSPORT_TYPE_KEY, transportKey);
plugins = Collections.singleton(transportPlugin); plugins = Collections.singleton(transportPlugin);

View File

@ -22,7 +22,6 @@ import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.transport.MockTcpTransportPlugin;
import org.elasticsearch.transport.Netty4Plugin; import org.elasticsearch.transport.Netty4Plugin;
import org.elasticsearch.transport.nio.MockNioTransportPlugin; import org.elasticsearch.transport.nio.MockNioTransportPlugin;
import org.elasticsearch.transport.nio.NioTransportPlugin; import org.elasticsearch.transport.nio.NioTransportPlugin;
@ -46,9 +45,7 @@ public abstract class HttpSmokeTestCase extends ESIntegTestCase {
} }
private static String getTypeKey(Class<? extends Plugin> clazz) { private static String getTypeKey(Class<? extends Plugin> clazz) {
if (clazz.equals(MockTcpTransportPlugin.class)) { if (clazz.equals(MockNioTransportPlugin.class)) {
return MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME;
} else if (clazz.equals(MockNioTransportPlugin.class)) {
return MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME; return MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME;
} else if (clazz.equals(NioTransportPlugin.class)) { } else if (clazz.equals(NioTransportPlugin.class)) {
return NioTransportPlugin.NIO_TRANSPORT_NAME; return NioTransportPlugin.NIO_TRANSPORT_NAME;

View File

@ -114,7 +114,6 @@ import org.elasticsearch.search.MockSearchService;
import org.elasticsearch.test.junit.listeners.LoggingListener; import org.elasticsearch.test.junit.listeners.LoggingListener;
import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter; import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.MockTcpTransportPlugin;
import org.elasticsearch.transport.nio.MockNioTransportPlugin; import org.elasticsearch.transport.nio.MockNioTransportPlugin;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.junit.After; import org.junit.After;
@ -992,19 +991,12 @@ public abstract class ESTestCase extends LuceneTestCase {
return geohashGenerator.ofStringLength(random(), minPrecision, maxPrecision); return geohashGenerator.ofStringLength(random(), minPrecision, maxPrecision);
} }
private static boolean useNio;
@BeforeClass
public static void setUseNio() throws Exception {
useNio = randomBoolean();
}
public static String getTestTransportType() { public static String getTestTransportType() {
return useNio ? MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME : MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME; return MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME;
} }
public static Class<? extends Plugin> getTestTransportPlugin() { public static Class<? extends Plugin> getTestTransportPlugin() {
return useNio ? MockNioTransportPlugin.class : MockTcpTransportPlugin.class; return MockNioTransportPlugin.class;
} }
private static final GeohashGenerator geohashGenerator = new GeohashGenerator(); private static final GeohashGenerator geohashGenerator = new GeohashGenerator();

View File

@ -34,7 +34,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.transport.MockTcpTransportPlugin;
import org.elasticsearch.transport.MockTransportClient; import org.elasticsearch.transport.MockTransportClient;
import org.elasticsearch.transport.nio.MockNioTransportPlugin; import org.elasticsearch.transport.nio.MockNioTransportPlugin;
@ -84,14 +83,9 @@ public final class ExternalTestCluster extends TestCluster {
if (addMockTcpTransport) { if (addMockTcpTransport) {
String transport = getTestTransportType(); String transport = getTestTransportType();
clientSettingsBuilder.put(NetworkModule.TRANSPORT_TYPE_KEY, transport); clientSettingsBuilder.put(NetworkModule.TRANSPORT_TYPE_KEY, transport);
if (pluginClasses.contains(MockTcpTransportPlugin.class) == false && if (pluginClasses.contains(MockNioTransportPlugin.class) == false) {
pluginClasses.contains(MockNioTransportPlugin.class) == false) {
pluginClasses = new ArrayList<>(pluginClasses); pluginClasses = new ArrayList<>(pluginClasses);
if (transport.equals(MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME)) { pluginClasses.add(MockNioTransportPlugin.class);
pluginClasses.add(MockNioTransportPlugin.class);
} else {
pluginClasses.add(MockTcpTransportPlugin.class);
}
} }
} }
Settings clientSettings = clientSettingsBuilder.build(); Settings clientSettings = clientSettingsBuilder.build();

View File

@ -1,48 +0,0 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.transport;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.network.NetworkService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.PageCacheRecycler;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.plugins.NetworkPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.threadpool.ThreadPool;
import java.util.Collections;
import java.util.Map;
import java.util.function.Supplier;
public class MockTcpTransportPlugin extends Plugin implements NetworkPlugin {
public static final String MOCK_TCP_TRANSPORT_NAME = "mock-socket-network";
@Override
public Map<String, Supplier<Transport>> getTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
PageCacheRecycler pageCacheRecycler,
CircuitBreakerService circuitBreakerService,
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService) {
return Collections.singletonMap(MOCK_TCP_TRANSPORT_NAME,
() -> new MockTcpTransport(settings, threadPool, bigArrays, circuitBreakerService, namedWriteableRegistry, networkService));
}
}

View File

@ -33,7 +33,7 @@ import java.util.Collection;
@Deprecated @Deprecated
public class MockTransportClient extends TransportClient { public class MockTransportClient extends TransportClient {
private static final Settings DEFAULT_SETTINGS = Settings.builder().put("transport.type.default", private static final Settings DEFAULT_SETTINGS = Settings.builder().put("transport.type.default",
MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).build(); MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME).build();
public MockTransportClient(Settings settings, Class<? extends Plugin>... plugins) { public MockTransportClient(Settings settings, Class<? extends Plugin>... plugins) {
this(settings, Arrays.asList(plugins)); this(settings, Arrays.asList(plugins));
@ -51,15 +51,7 @@ public class MockTransportClient extends TransportClient {
Collection<Class<? extends Plugin>> plugins) { Collection<Class<? extends Plugin>> plugins) {
boolean settingExists = NetworkModule.TRANSPORT_TYPE_SETTING.exists(settings); boolean settingExists = NetworkModule.TRANSPORT_TYPE_SETTING.exists(settings);
String transportType = NetworkModule.TRANSPORT_TYPE_SETTING.get(settings); String transportType = NetworkModule.TRANSPORT_TYPE_SETTING.get(settings);
if (settingExists == false || MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME.equals(transportType)) { if (settingExists == false || MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME.equals(transportType)) {
if (plugins.contains(MockTcpTransportPlugin.class)) {
return plugins;
} else {
plugins = new ArrayList<>(plugins);
plugins.add(MockTcpTransportPlugin.class);
return plugins;
}
} else if (MockNioTransportPlugin.MOCK_NIO_TRANSPORT_NAME.equals(transportType)) {
if (plugins.contains(MockNioTransportPlugin.class)) { if (plugins.contains(MockNioTransportPlugin.class)) {
return plugins; return plugins;
} else { } else {