From f998e04c345760583740ede7b3d2b15ee777619f Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Thu, 13 Dec 2018 09:10:18 -0700 Subject: [PATCH] Remove usages of `MockTcpTransport` from zen tests (#36579) We are attempting to replace the usage of the `MockTcpTransport` with the `MockNioTransport`. This commit replaces usages of `MockTcpTransport` in two zen test cases. --- .../discovery/ZenFaultDetectionTests.java | 8 ++-- .../discovery/zen/UnicastZenPingTests.java | 43 ++++++++++--------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java b/server/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java index 03c0df43591ba..fbe3ef00a0656 100644 --- a/server/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java +++ b/server/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java @@ -32,7 +32,7 @@ import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.discovery.zen.FaultDetection; import org.elasticsearch.discovery.zen.MasterFaultDetection; import org.elasticsearch.discovery.zen.NodesFaultDetection; @@ -43,10 +43,10 @@ import org.elasticsearch.test.transport.MockTransportService; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.MockTcpTransport; import org.elasticsearch.transport.TransportConnectionListener; import org.elasticsearch.transport.TransportRequestOptions; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.transport.nio.MockNioTransport; import org.hamcrest.Matcher; import org.hamcrest.Matchers; import org.junit.After; @@ -138,8 +138,8 @@ protected MockTransportService build(Settings settings, Version version) { // trace zenfd actions but keep the default otherwise .putList(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), TransportLivenessAction.NAME) .build(), - new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE, circuitBreakerService, - namedWriteableRegistry, new NetworkService(Collections.emptyList()), version), + new MockNioTransport(settings, version, threadPool, new NetworkService(Collections.emptyList()), + PageCacheRecycler.NON_RECYCLING_INSTANCE, namedWriteableRegistry, circuitBreakerService), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, (boundAddress) -> diff --git a/server/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java b/server/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java index 1c0329a51e32a..c380341b51b86 100644 --- a/server/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java +++ b/server/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java @@ -38,6 +38,7 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.common.util.PageCacheRecycler; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.common.util.concurrent.EsExecutors; @@ -56,6 +57,7 @@ import org.elasticsearch.transport.TransportRequestOptions; import org.elasticsearch.transport.TransportResponseHandler; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.transport.nio.MockNioTransport; import org.junit.After; import org.junit.Before; import org.mockito.Matchers; @@ -143,14 +145,14 @@ public void testSimplePings() throws IOException, InterruptedException, Executio NetworkService networkService = new NetworkService(Collections.emptyList()); - final BiFunction supplier = (s, v) -> new MockTcpTransport( + final BiFunction supplier = (s, v) -> new MockNioTransport( s, + v, threadPool, - BigArrays.NON_RECYCLING_INSTANCE, - new NoneCircuitBreakerService(), - new NamedWriteableRegistry(Collections.emptyList()), networkService, - v); + PageCacheRecycler.NON_RECYCLING_INSTANCE, + new NamedWriteableRegistry(Collections.emptyList()), + new NoneCircuitBreakerService()); NetworkHandle handleA = startServices(settings, threadPool, "UZP_A", Version.CURRENT, supplier); closeables.push(handleA.transportService); @@ -268,14 +270,14 @@ public void testUnknownHostNotCached() throws ExecutionException, InterruptedExc final NetworkService networkService = new NetworkService(Collections.emptyList()); final Map addresses = new HashMap<>(); - final BiFunction supplier = (s, v) -> new MockTcpTransport( + final BiFunction supplier = (s, v) -> new MockNioTransport( s, + v, threadPool, - BigArrays.NON_RECYCLING_INSTANCE, - new NoneCircuitBreakerService(), - new NamedWriteableRegistry(Collections.emptyList()), networkService, - v) { + PageCacheRecycler.NON_RECYCLING_INSTANCE, + new NamedWriteableRegistry(Collections.emptyList()), + new NoneCircuitBreakerService()) { @Override public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException { final TransportAddress[] transportAddresses = addresses.get(address); @@ -634,14 +636,14 @@ public void testPingingTemporalPings() throws ExecutionException, InterruptedExc NetworkService networkService = new NetworkService(Collections.emptyList()); - final BiFunction supplier = (s, v) -> new MockTcpTransport( + final BiFunction supplier = (s, v) -> new MockNioTransport( s, + v, threadPool, - BigArrays.NON_RECYCLING_INSTANCE, - new NoneCircuitBreakerService(), - new NamedWriteableRegistry(Collections.emptyList()), networkService, - v); + PageCacheRecycler.NON_RECYCLING_INSTANCE, + new NamedWriteableRegistry(Collections.emptyList()), + new NoneCircuitBreakerService()); NetworkHandle handleA = startServices(settings, threadPool, "UZP_A", Version.CURRENT, supplier, EnumSet.allOf(Role.class)); closeables.push(handleA.transportService); @@ -689,15 +691,14 @@ public void testPingingTemporalPings() throws ExecutionException, InterruptedExc public void testInvalidHosts() throws InterruptedException { final Logger logger = mock(Logger.class); - final NetworkService networkService = new NetworkService(Collections.emptyList()); - final Transport transport = new MockTcpTransport( + final Transport transport = new MockNioTransport( Settings.EMPTY, + Version.CURRENT, threadPool, - BigArrays.NON_RECYCLING_INSTANCE, - new NoneCircuitBreakerService(), + new NetworkService(Collections.emptyList()), + PageCacheRecycler.NON_RECYCLING_INSTANCE, new NamedWriteableRegistry(Collections.emptyList()), - networkService, - Version.CURRENT) { + new NoneCircuitBreakerService()) { @Override public BoundTransportAddress boundAddress() { return new BoundTransportAddress(