Skip to content

Commit f998e04

Browse files
authored
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.
1 parent 2afa7fa commit f998e04

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

server/src/test/java/org/elasticsearch/discovery/ZenFaultDetectionTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.elasticsearch.common.settings.ClusterSettings;
3333
import org.elasticsearch.common.settings.Settings;
3434
import org.elasticsearch.common.unit.ByteSizeValue;
35-
import org.elasticsearch.common.util.BigArrays;
35+
import org.elasticsearch.common.util.PageCacheRecycler;
3636
import org.elasticsearch.discovery.zen.FaultDetection;
3737
import org.elasticsearch.discovery.zen.MasterFaultDetection;
3838
import org.elasticsearch.discovery.zen.NodesFaultDetection;
@@ -43,10 +43,10 @@
4343
import org.elasticsearch.test.transport.MockTransportService;
4444
import org.elasticsearch.threadpool.TestThreadPool;
4545
import org.elasticsearch.threadpool.ThreadPool;
46-
import org.elasticsearch.transport.MockTcpTransport;
4746
import org.elasticsearch.transport.TransportConnectionListener;
4847
import org.elasticsearch.transport.TransportRequestOptions;
4948
import org.elasticsearch.transport.TransportService;
49+
import org.elasticsearch.transport.nio.MockNioTransport;
5050
import org.hamcrest.Matcher;
5151
import org.hamcrest.Matchers;
5252
import org.junit.After;
@@ -138,8 +138,8 @@ protected MockTransportService build(Settings settings, Version version) {
138138
// trace zenfd actions but keep the default otherwise
139139
.putList(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), TransportLivenessAction.NAME)
140140
.build(),
141-
new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE, circuitBreakerService,
142-
namedWriteableRegistry, new NetworkService(Collections.emptyList()), version),
141+
new MockNioTransport(settings, version, threadPool, new NetworkService(Collections.emptyList()),
142+
PageCacheRecycler.NON_RECYCLING_INSTANCE, namedWriteableRegistry, circuitBreakerService),
143143
threadPool,
144144
TransportService.NOOP_TRANSPORT_INTERCEPTOR,
145145
(boundAddress) ->

server/src/test/java/org/elasticsearch/discovery/zen/UnicastZenPingTests.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.elasticsearch.common.transport.TransportAddress;
3939
import org.elasticsearch.common.unit.TimeValue;
4040
import org.elasticsearch.common.util.BigArrays;
41+
import org.elasticsearch.common.util.PageCacheRecycler;
4142
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
4243
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
4344
import org.elasticsearch.common.util.concurrent.EsExecutors;
@@ -56,6 +57,7 @@
5657
import org.elasticsearch.transport.TransportRequestOptions;
5758
import org.elasticsearch.transport.TransportResponseHandler;
5859
import org.elasticsearch.transport.TransportService;
60+
import org.elasticsearch.transport.nio.MockNioTransport;
5961
import org.junit.After;
6062
import org.junit.Before;
6163
import org.mockito.Matchers;
@@ -143,14 +145,14 @@ public void testSimplePings() throws IOException, InterruptedException, Executio
143145

144146
NetworkService networkService = new NetworkService(Collections.emptyList());
145147

146-
final BiFunction<Settings, Version, Transport> supplier = (s, v) -> new MockTcpTransport(
148+
final BiFunction<Settings, Version, Transport> supplier = (s, v) -> new MockNioTransport(
147149
s,
150+
v,
148151
threadPool,
149-
BigArrays.NON_RECYCLING_INSTANCE,
150-
new NoneCircuitBreakerService(),
151-
new NamedWriteableRegistry(Collections.emptyList()),
152152
networkService,
153-
v);
153+
PageCacheRecycler.NON_RECYCLING_INSTANCE,
154+
new NamedWriteableRegistry(Collections.emptyList()),
155+
new NoneCircuitBreakerService());
154156

155157
NetworkHandle handleA = startServices(settings, threadPool, "UZP_A", Version.CURRENT, supplier);
156158
closeables.push(handleA.transportService);
@@ -268,14 +270,14 @@ public void testUnknownHostNotCached() throws ExecutionException, InterruptedExc
268270
final NetworkService networkService = new NetworkService(Collections.emptyList());
269271

270272
final Map<String, TransportAddress[]> addresses = new HashMap<>();
271-
final BiFunction<Settings, Version, Transport> supplier = (s, v) -> new MockTcpTransport(
273+
final BiFunction<Settings, Version, Transport> supplier = (s, v) -> new MockNioTransport(
272274
s,
275+
v,
273276
threadPool,
274-
BigArrays.NON_RECYCLING_INSTANCE,
275-
new NoneCircuitBreakerService(),
276-
new NamedWriteableRegistry(Collections.emptyList()),
277277
networkService,
278-
v) {
278+
PageCacheRecycler.NON_RECYCLING_INSTANCE,
279+
new NamedWriteableRegistry(Collections.emptyList()),
280+
new NoneCircuitBreakerService()) {
279281
@Override
280282
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException {
281283
final TransportAddress[] transportAddresses = addresses.get(address);
@@ -634,14 +636,14 @@ public void testPingingTemporalPings() throws ExecutionException, InterruptedExc
634636

635637
NetworkService networkService = new NetworkService(Collections.emptyList());
636638

637-
final BiFunction<Settings, Version, Transport> supplier = (s, v) -> new MockTcpTransport(
639+
final BiFunction<Settings, Version, Transport> supplier = (s, v) -> new MockNioTransport(
638640
s,
641+
v,
639642
threadPool,
640-
BigArrays.NON_RECYCLING_INSTANCE,
641-
new NoneCircuitBreakerService(),
642-
new NamedWriteableRegistry(Collections.emptyList()),
643643
networkService,
644-
v);
644+
PageCacheRecycler.NON_RECYCLING_INSTANCE,
645+
new NamedWriteableRegistry(Collections.emptyList()),
646+
new NoneCircuitBreakerService());
645647

646648
NetworkHandle handleA = startServices(settings, threadPool, "UZP_A", Version.CURRENT, supplier, EnumSet.allOf(Role.class));
647649
closeables.push(handleA.transportService);
@@ -689,15 +691,14 @@ public void testPingingTemporalPings() throws ExecutionException, InterruptedExc
689691

690692
public void testInvalidHosts() throws InterruptedException {
691693
final Logger logger = mock(Logger.class);
692-
final NetworkService networkService = new NetworkService(Collections.emptyList());
693-
final Transport transport = new MockTcpTransport(
694+
final Transport transport = new MockNioTransport(
694695
Settings.EMPTY,
696+
Version.CURRENT,
695697
threadPool,
696-
BigArrays.NON_RECYCLING_INSTANCE,
697-
new NoneCircuitBreakerService(),
698+
new NetworkService(Collections.emptyList()),
699+
PageCacheRecycler.NON_RECYCLING_INSTANCE,
698700
new NamedWriteableRegistry(Collections.emptyList()),
699-
networkService,
700-
Version.CURRENT) {
701+
new NoneCircuitBreakerService()) {
701702
@Override
702703
public BoundTransportAddress boundAddress() {
703704
return new BoundTransportAddress(

0 commit comments

Comments
 (0)