Simplify port usage in transport tests (#44157)
Simplifies AbstractSimpleTransportTestCase to use JVM-local ports and also adds an assertion so that cases like #44134 can be more easily debugged. The likely reason for that one is that a test, which was repeated again and again while always spawning a fresh Gradle worker (due to Gradle daemon) kept increasing Gradle worker IDs, causing an overflow at some point.
This commit is contained in:
parent
5886aefeed
commit
2ee07f1ff4
|
@ -29,16 +29,11 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.common.util.PageCacheRecycler;
|
||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.test.transport.MockTransportService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.AbstractSimpleTransportTestCase;
|
||||
import org.elasticsearch.transport.BindTransportException;
|
||||
import org.elasticsearch.transport.ConnectTransportException;
|
||||
import org.elasticsearch.transport.ConnectionProfile;
|
||||
import org.elasticsearch.transport.TcpChannel;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportSettings;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
@ -50,10 +45,10 @@ import static org.hamcrest.Matchers.containsString;
|
|||
|
||||
public class SimpleNetty4TransportTests extends AbstractSimpleTransportTestCase {
|
||||
|
||||
public static MockTransportService nettyFromThreadPool(Settings settings, ThreadPool threadPool, final Version version,
|
||||
ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
@Override
|
||||
protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
|
||||
Transport transport = new Netty4Transport(settings, version, threadPool, new NetworkService(Collections.emptyList()),
|
||||
return new Netty4Transport(settings, version, threadPool, new NetworkService(Collections.emptyList()),
|
||||
PageCacheRecycler.NON_RECYCLING_INSTANCE, namedWriteableRegistry, new NoneCircuitBreakerService()) {
|
||||
|
||||
@Override
|
||||
|
@ -66,18 +61,6 @@ public class SimpleNetty4TransportTests extends AbstractSimpleTransportTestCase
|
|||
}
|
||||
}
|
||||
};
|
||||
MockTransportService mockTransportService =
|
||||
MockTransportService.createNewService(settings, transport, version, threadPool, clusterSettings, Collections.emptySet());
|
||||
mockTransportService.start();
|
||||
return mockTransportService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MockTransportService build(Settings settings, Version version, ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
settings = Settings.builder().put(settings).put(TransportSettings.PORT.getKey(), "0").build();
|
||||
MockTransportService transportService = nettyFromThreadPool(settings, threadPool, version, clusterSettings, doHandshake);
|
||||
transportService.start();
|
||||
return transportService;
|
||||
}
|
||||
|
||||
public void testConnectException() throws UnknownHostException {
|
||||
|
@ -91,27 +74,4 @@ public class SimpleNetty4TransportTests extends AbstractSimpleTransportTestCase
|
|||
}
|
||||
}
|
||||
|
||||
public void testBindUnavailableAddress() {
|
||||
// this is on a lower level since it needs access to the TransportService before it's started
|
||||
int port = serviceA.boundAddress().publishAddress().getPort();
|
||||
Settings settings = Settings.builder()
|
||||
.put(Node.NODE_NAME_SETTING.getKey(), "foobar")
|
||||
.put(TransportSettings.TRACE_LOG_INCLUDE_SETTING.getKey(), "")
|
||||
.put(TransportSettings.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING")
|
||||
.put(TransportSettings.PORT.getKey(), port)
|
||||
.build();
|
||||
ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
|
||||
BindTransportException bindTransportException = expectThrows(BindTransportException.class, () -> {
|
||||
MockTransportService transportService =
|
||||
nettyFromThreadPool(settings, threadPool, Version.CURRENT, clusterSettings, true);
|
||||
try {
|
||||
transportService.start();
|
||||
} finally {
|
||||
transportService.stop();
|
||||
transportService.close();
|
||||
}
|
||||
});
|
||||
assertEquals("Failed to bind to ["+ port + "]", bindTransportException.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,16 +29,11 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.common.util.MockPageCacheRecycler;
|
||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.test.transport.MockTransportService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.AbstractSimpleTransportTestCase;
|
||||
import org.elasticsearch.transport.BindTransportException;
|
||||
import org.elasticsearch.transport.ConnectTransportException;
|
||||
import org.elasticsearch.transport.ConnectionProfile;
|
||||
import org.elasticsearch.transport.TcpChannel;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportSettings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
|
@ -52,11 +47,11 @@ import static org.hamcrest.Matchers.instanceOf;
|
|||
|
||||
public class SimpleNioTransportTests extends AbstractSimpleTransportTestCase {
|
||||
|
||||
public MockTransportService nioFromThreadPool(Settings settings, ThreadPool threadPool, final Version version,
|
||||
ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
@Override
|
||||
protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
|
||||
NetworkService networkService = new NetworkService(Collections.emptyList());
|
||||
Transport transport = new NioTransport(settings, version, threadPool, networkService, new MockPageCacheRecycler(settings),
|
||||
return new NioTransport(settings, version, threadPool, networkService, new MockPageCacheRecycler(settings),
|
||||
namedWriteableRegistry, new NoneCircuitBreakerService(), new NioGroupFactory(settings, logger)) {
|
||||
|
||||
@Override
|
||||
|
@ -69,20 +64,6 @@ public class SimpleNioTransportTests extends AbstractSimpleTransportTestCase {
|
|||
}
|
||||
}
|
||||
};
|
||||
MockTransportService mockTransportService =
|
||||
MockTransportService.createNewService(settings, transport, version, threadPool, clusterSettings, Collections.emptySet());
|
||||
mockTransportService.start();
|
||||
return mockTransportService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MockTransportService build(Settings settings, Version version, ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
settings = Settings.builder().put(settings)
|
||||
.put(TransportSettings.PORT.getKey(), "0")
|
||||
.build();
|
||||
MockTransportService transportService = nioFromThreadPool(settings, threadPool, version, clusterSettings, doHandshake);
|
||||
transportService.start();
|
||||
return transportService;
|
||||
}
|
||||
|
||||
public void testConnectException() throws UnknownHostException {
|
||||
|
@ -97,26 +78,4 @@ public class SimpleNioTransportTests extends AbstractSimpleTransportTestCase {
|
|||
assertThat(cause, instanceOf(IOException.class));
|
||||
}
|
||||
}
|
||||
|
||||
public void testBindUnavailableAddress() {
|
||||
// this is on a lower level since it needs access to the TransportService before it's started
|
||||
int port = serviceA.boundAddress().publishAddress().getPort();
|
||||
Settings settings = Settings.builder()
|
||||
.put(Node.NODE_NAME_SETTING.getKey(), "foobar")
|
||||
.put(TransportSettings.TRACE_LOG_INCLUDE_SETTING.getKey(), "")
|
||||
.put(TransportSettings.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING")
|
||||
.put(TransportSettings.PORT.getKey(), port)
|
||||
.build();
|
||||
ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
|
||||
BindTransportException bindTransportException = expectThrows(BindTransportException.class, () -> {
|
||||
MockTransportService transportService = nioFromThreadPool(settings, threadPool, Version.CURRENT, clusterSettings, true);
|
||||
try {
|
||||
transportService.start();
|
||||
} finally {
|
||||
transportService.stop();
|
||||
transportService.close();
|
||||
}
|
||||
});
|
||||
assertEquals("Failed to bind to ["+ port + "]", bindTransportException.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.elasticsearch.test.InternalTestCluster;
|
|||
import org.elasticsearch.test.MockHttpTransport;
|
||||
import org.elasticsearch.test.MockLogAppender;
|
||||
import org.elasticsearch.test.NodeConfigurationSource;
|
||||
import org.elasticsearch.test.transport.MockTransportService;
|
||||
import org.elasticsearch.transport.RemoteTransportException;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
|
@ -59,7 +60,7 @@ public class SingleNodeDiscoveryIT extends ESIntegTestCase {
|
|||
.builder()
|
||||
.put(super.nodeSettings(nodeOrdinal))
|
||||
.put("discovery.type", "single-node")
|
||||
.put("transport.port", "0")
|
||||
.put("transport.port", MockTransportService.getPortRange())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
|
@ -105,14 +105,32 @@ public final class MockTransportService extends TransportService {
|
|||
return createNewService(settings, mockTransport, version, threadPool, clusterSettings, Collections.emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Some tests use MockTransportService to do network based testing. Yet, we run tests in multiple JVMs that means
|
||||
* concurrent tests could claim port that another JVM just released and if that test tries to simulate a disconnect it might
|
||||
* be smart enough to re-connect depending on what is tested. To reduce the risk, since this is very hard to debug we use
|
||||
* a different default port range per JVM unless the incoming settings override it
|
||||
* use a non-default base port otherwise some cluster in this JVM might reuse a port
|
||||
*/
|
||||
private static int getBasePort() {
|
||||
final int basePort = 10300 + (ESTestCase.TEST_WORKER_VM * 100);
|
||||
if (basePort < 10300 || basePort >= 65000) {
|
||||
// to ensure we don't get illegal ports above 65536 in the getPortRange method
|
||||
throw new AssertionError("Expected basePort to be between 10300 and 65000 but was " + basePort);
|
||||
}
|
||||
return basePort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a unique port range for this JVM starting from the computed base port (see {@link #getBasePort()})
|
||||
*/
|
||||
public static String getPortRange() {
|
||||
int basePort = getBasePort();
|
||||
return basePort + "-" + (basePort + 99); // upper bound is inclusive
|
||||
}
|
||||
|
||||
public static MockNioTransport newMockTransport(Settings settings, Version version, ThreadPool threadPool) {
|
||||
// some tests use MockTransportService to do network based testing. Yet, we run tests in multiple JVMs that means
|
||||
// concurrent tests could claim port that another JVM just released and if that test tries to simulate a disconnect it might
|
||||
// be smart enough to re-connect depending on what is tested. To reduce the risk, since this is very hard to debug we use
|
||||
// a different default port range per JVM unless the incoming settings override it
|
||||
// use a non-default base port otherwise some cluster in this JVM might reuse a port
|
||||
int basePort = 10300 + (ESTestCase.TEST_WORKER_VM * 100);
|
||||
settings = Settings.builder().put(TransportSettings.PORT.getKey(), basePort + "-" + (basePort + 100)).put(settings).build();
|
||||
settings = Settings.builder().put(TransportSettings.PORT.getKey(), getPortRange()).put(settings).build();
|
||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables());
|
||||
return new MockNioTransport(settings, version, threadPool, new NetworkService(Collections.emptyList()),
|
||||
new MockPageCacheRecycler(settings), namedWriteableRegistry, new NoneCircuitBreakerService());
|
||||
|
|
|
@ -92,6 +92,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.elasticsearch.test.transport.MockTransportService.getPortRange;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -116,7 +117,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase {
|
|||
protected volatile DiscoveryNode nodeB;
|
||||
protected volatile MockTransportService serviceB;
|
||||
|
||||
protected abstract MockTransportService build(Settings settings, Version version, ClusterSettings clusterSettings, boolean doHandshake);
|
||||
protected abstract Transport build(Settings settings, Version version, ClusterSettings clusterSettings, boolean doHandshake);
|
||||
|
||||
protected int channelsPerNodeConnection() {
|
||||
// This is a customized profile for this test case.
|
||||
|
@ -175,13 +176,17 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase {
|
|||
private MockTransportService buildService(final String name, final Version version, @Nullable ClusterSettings clusterSettings,
|
||||
Settings settings, boolean acceptRequests, boolean doHandshake) {
|
||||
Settings updatedSettings = Settings.builder()
|
||||
.put(TransportSettings.PORT.getKey(), getPortRange())
|
||||
.put(settings)
|
||||
.put(Node.NODE_NAME_SETTING.getKey(), name)
|
||||
.build();
|
||||
if (clusterSettings == null) {
|
||||
clusterSettings = new ClusterSettings(updatedSettings, getSupportedSettings());
|
||||
}
|
||||
MockTransportService service = build(updatedSettings, version, clusterSettings, doHandshake);
|
||||
Transport transport = build(updatedSettings, version, clusterSettings, doHandshake);
|
||||
MockTransportService service = MockTransportService.createNewService(updatedSettings, transport, version, threadPool,
|
||||
clusterSettings, Collections.emptySet());
|
||||
service.start();
|
||||
if (acceptRequests) {
|
||||
service.acceptIncomingRequests();
|
||||
}
|
||||
|
@ -1992,7 +1997,7 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase {
|
|||
|
||||
public void testTcpHandshake() {
|
||||
assumeTrue("only tcp transport has a handshake method", serviceA.getOriginalTransport() instanceof TcpTransport);
|
||||
try (MockTransportService service = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null)) {
|
||||
try (MockTransportService service = buildService("TS_BAD", Version.CURRENT, Settings.EMPTY)) {
|
||||
service.addMessageListener(new TransportMessageListener() {
|
||||
@Override
|
||||
public void onRequestReceived(long requestId, String action) {
|
||||
|
@ -2654,6 +2659,17 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase {
|
|||
.toSet()));
|
||||
}
|
||||
|
||||
public void testBindUnavailableAddress() {
|
||||
int port = serviceA.boundAddress().publishAddress().getPort();
|
||||
Settings settings = Settings.builder()
|
||||
.put(Node.NODE_NAME_SETTING.getKey(), "foobar")
|
||||
.put(TransportSettings.PORT.getKey(), port)
|
||||
.build();
|
||||
BindTransportException bindTransportException = expectThrows(BindTransportException.class,
|
||||
() -> buildService("test", Version.CURRENT, settings));
|
||||
assertEquals("Failed to bind to ["+ port + "]", bindTransportException.getMessage());
|
||||
}
|
||||
|
||||
public void testChannelCloseWhileConnecting() {
|
||||
try (MockTransportService service = buildService("TS_C", version0, Settings.EMPTY)) {
|
||||
AtomicBoolean connectionClosedListenerCalled = new AtomicBoolean(false);
|
||||
|
|
|
@ -29,16 +29,11 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.common.util.MockPageCacheRecycler;
|
||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.test.transport.MockTransportService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.AbstractSimpleTransportTestCase;
|
||||
import org.elasticsearch.transport.BindTransportException;
|
||||
import org.elasticsearch.transport.ConnectTransportException;
|
||||
import org.elasticsearch.transport.ConnectionProfile;
|
||||
import org.elasticsearch.transport.TcpChannel;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportSettings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
|
@ -52,11 +47,11 @@ import static org.hamcrest.Matchers.instanceOf;
|
|||
|
||||
public class SimpleMockNioTransportTests extends AbstractSimpleTransportTestCase {
|
||||
|
||||
public static MockTransportService nioFromThreadPool(Settings settings, ThreadPool threadPool, final Version version,
|
||||
ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
@Override
|
||||
protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
|
||||
NetworkService networkService = new NetworkService(Collections.emptyList());
|
||||
Transport transport = new MockNioTransport(settings, version, threadPool, networkService, new MockPageCacheRecycler(settings),
|
||||
return new MockNioTransport(settings, version, threadPool, networkService, new MockPageCacheRecycler(settings),
|
||||
namedWriteableRegistry, new NoneCircuitBreakerService()) {
|
||||
|
||||
@Override
|
||||
|
@ -69,20 +64,6 @@ public class SimpleMockNioTransportTests extends AbstractSimpleTransportTestCase
|
|||
}
|
||||
}
|
||||
};
|
||||
MockTransportService mockTransportService =
|
||||
MockTransportService.createNewService(settings, transport, version, threadPool, clusterSettings, Collections.emptySet());
|
||||
mockTransportService.start();
|
||||
return mockTransportService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MockTransportService build(Settings settings, Version version, ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
settings = Settings.builder().put(settings)
|
||||
.put(TransportSettings.PORT.getKey(), "0")
|
||||
.build();
|
||||
MockTransportService transportService = nioFromThreadPool(settings, threadPool, version, clusterSettings, doHandshake);
|
||||
transportService.start();
|
||||
return transportService;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -102,24 +83,4 @@ public class SimpleMockNioTransportTests extends AbstractSimpleTransportTestCase
|
|||
assertThat(cause, instanceOf(IOException.class));
|
||||
}
|
||||
}
|
||||
|
||||
public void testBindUnavailableAddress() {
|
||||
// this is on a lower level since it needs access to the TransportService before it's started
|
||||
int port = serviceA.boundAddress().publishAddress().getPort();
|
||||
Settings settings = Settings.builder()
|
||||
.put(Node.NODE_NAME_SETTING.getKey(), "foobar")
|
||||
.put(TransportSettings.PORT.getKey(), port)
|
||||
.build();
|
||||
ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
|
||||
BindTransportException bindTransportException = expectThrows(BindTransportException.class, () -> {
|
||||
MockTransportService transportService = nioFromThreadPool(settings, threadPool, Version.CURRENT, clusterSettings, true);
|
||||
try {
|
||||
transportService.start();
|
||||
} finally {
|
||||
transportService.stop();
|
||||
transportService.close();
|
||||
}
|
||||
});
|
||||
assertEquals("Failed to bind to ["+ port + "]", bindTransportException.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.elasticsearch.env.TestEnvironment;
|
|||
import org.elasticsearch.test.transport.MockTransportService;
|
||||
import org.elasticsearch.test.transport.StubbableTransport;
|
||||
import org.elasticsearch.transport.AbstractSimpleTransportTestCase;
|
||||
import org.elasticsearch.transport.BindTransportException;
|
||||
import org.elasticsearch.transport.ConnectTransportException;
|
||||
import org.elasticsearch.transport.ConnectionProfile;
|
||||
import org.elasticsearch.transport.TcpChannel;
|
||||
|
@ -28,7 +27,6 @@ import org.elasticsearch.transport.TcpTransport;
|
|||
import org.elasticsearch.transport.TestProfiles;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportService;
|
||||
import org.elasticsearch.transport.TransportSettings;
|
||||
import org.elasticsearch.xpack.core.XPackSettings;
|
||||
import org.elasticsearch.xpack.core.common.socket.SocketAccess;
|
||||
import org.elasticsearch.xpack.core.ssl.SSLClientAuth;
|
||||
|
@ -46,7 +44,6 @@ import javax.net.ssl.SSLParameters;
|
|||
import javax.net.ssl.SSLServerSocket;
|
||||
import javax.net.ssl.SSLServerSocketFactory;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.InetAddress;
|
||||
|
@ -117,24 +114,7 @@ public abstract class AbstractSimpleSecurityTransportTestCase extends AbstractSi
|
|||
Throwable cause = e.getCause();
|
||||
assertThat(cause, instanceOf(IOException.class));
|
||||
}
|
||||
}
|
||||
|
||||
public void testBindUnavailableAddress() {
|
||||
// this is on a lower level since it needs access to the TransportService before it's started
|
||||
int port = serviceA.boundAddress().publishAddress().getPort();
|
||||
Settings settings = Settings.builder()
|
||||
.put(TransportSettings.PORT.getKey(), port)
|
||||
.build();
|
||||
BindTransportException bindTransportException = expectThrows(BindTransportException.class, () -> {
|
||||
MockTransportService transportService = buildService("TS_C", Version.CURRENT, settings);
|
||||
try {
|
||||
transportService.start();
|
||||
} finally {
|
||||
transportService.stop();
|
||||
transportService.close();
|
||||
}
|
||||
});
|
||||
assertEquals("Failed to bind to [" + port + "]", bindTransportException.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,26 +14,23 @@ import org.elasticsearch.common.settings.ClusterSettings;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.PageCacheRecycler;
|
||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||
import org.elasticsearch.test.transport.MockTransportService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.ConnectionProfile;
|
||||
import org.elasticsearch.transport.TcpChannel;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportSettings;
|
||||
import org.elasticsearch.xpack.security.transport.AbstractSimpleSecurityTransportTestCase;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class SimpleSecurityNetty4ServerTransportTests extends AbstractSimpleSecurityTransportTestCase {
|
||||
|
||||
public MockTransportService nettyFromThreadPool(Settings settings, ThreadPool threadPool, final Version version,
|
||||
ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
@Override
|
||||
protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
|
||||
NetworkService networkService = new NetworkService(Collections.emptyList());
|
||||
Settings settings1 = Settings.builder()
|
||||
.put(settings)
|
||||
.put("xpack.security.transport.ssl.enabled", true).build();
|
||||
Transport transport = new SecurityNetty4ServerTransport(settings1, version, threadPool,
|
||||
return new SecurityNetty4ServerTransport(settings1, version, threadPool,
|
||||
networkService, PageCacheRecycler.NON_RECYCLING_INSTANCE, namedWriteableRegistry,
|
||||
new NoneCircuitBreakerService(), null, createSSLService(settings1)) {
|
||||
|
||||
|
@ -47,22 +44,5 @@ public class SimpleSecurityNetty4ServerTransportTests extends AbstractSimpleSecu
|
|||
}
|
||||
}
|
||||
};
|
||||
MockTransportService mockTransportService =
|
||||
MockTransportService.createNewService(settings, transport, version, threadPool, clusterSettings,
|
||||
Collections.emptySet());
|
||||
mockTransportService.start();
|
||||
return mockTransportService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MockTransportService build(Settings settings, Version version, ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
if (TransportSettings.PORT.exists(settings) == false) {
|
||||
settings = Settings.builder().put(settings)
|
||||
.put(TransportSettings.PORT.getKey(), "0")
|
||||
.build();
|
||||
}
|
||||
MockTransportService transportService = nettyFromThreadPool(settings, threadPool, version, clusterSettings, doHandshake);
|
||||
transportService.start();
|
||||
return transportService;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,12 +14,9 @@ import org.elasticsearch.common.settings.ClusterSettings;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.MockPageCacheRecycler;
|
||||
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
|
||||
import org.elasticsearch.test.transport.MockTransportService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.transport.ConnectionProfile;
|
||||
import org.elasticsearch.transport.TcpChannel;
|
||||
import org.elasticsearch.transport.Transport;
|
||||
import org.elasticsearch.transport.TransportSettings;
|
||||
import org.elasticsearch.transport.nio.NioGroupFactory;
|
||||
import org.elasticsearch.xpack.security.transport.AbstractSimpleSecurityTransportTestCase;
|
||||
|
||||
|
@ -27,14 +24,14 @@ import java.util.Collections;
|
|||
|
||||
public class SimpleSecurityNioTransportTests extends AbstractSimpleSecurityTransportTestCase {
|
||||
|
||||
public MockTransportService nioFromThreadPool(Settings settings, ThreadPool threadPool, final Version version,
|
||||
ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
@Override
|
||||
protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
|
||||
NetworkService networkService = new NetworkService(Collections.emptyList());
|
||||
Settings settings1 = Settings.builder()
|
||||
.put(settings)
|
||||
.put("xpack.security.transport.ssl.enabled", true).build();
|
||||
Transport transport = new SecurityNioTransport(settings1, version, threadPool, networkService, new MockPageCacheRecycler(settings),
|
||||
return new SecurityNioTransport(settings1, version, threadPool, networkService, new MockPageCacheRecycler(settings),
|
||||
namedWriteableRegistry, new NoneCircuitBreakerService(), null, createSSLService(settings1),
|
||||
new NioGroupFactory(settings, logger)) {
|
||||
|
||||
|
@ -48,22 +45,5 @@ public class SimpleSecurityNioTransportTests extends AbstractSimpleSecurityTrans
|
|||
}
|
||||
}
|
||||
};
|
||||
MockTransportService mockTransportService =
|
||||
MockTransportService.createNewService(settings, transport, version, threadPool, clusterSettings,
|
||||
Collections.emptySet());
|
||||
mockTransportService.start();
|
||||
return mockTransportService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MockTransportService build(Settings settings, Version version, ClusterSettings clusterSettings, boolean doHandshake) {
|
||||
if (TransportSettings.PORT.exists(settings) == false) {
|
||||
settings = Settings.builder().put(settings)
|
||||
.put(TransportSettings.PORT.getKey(), "0")
|
||||
.build();
|
||||
}
|
||||
MockTransportService transportService = nioFromThreadPool(settings, threadPool, version, clusterSettings, doHandshake);
|
||||
transportService.start();
|
||||
return transportService;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue