Skip to content

Commit

Permalink
Add separate TransportVersion parameter to MockTransportService (#94105)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoop committed Feb 27, 2023
1 parent a4ee8f4 commit 0d09580
Show file tree
Hide file tree
Showing 18 changed files with 722 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.discovery.gce;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.cloud.gce.GceInstancesServiceImpl;
import org.elasticsearch.cloud.gce.GceMetadataService;
Expand Down Expand Up @@ -85,7 +86,13 @@ public void setProjectName() {

@Before
public void createTransportService() {
transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null);
transportService = MockTransportService.createNewService(
Settings.EMPTY,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool,
null
);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.http.nio.entity.NStringEntity;
import org.apache.lucene.search.TotalHits;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsAction;
import org.elasticsearch.action.admin.cluster.shards.ClusterSearchShardsGroup;
Expand Down Expand Up @@ -93,12 +94,13 @@ private static MockTransportService startTransport(
final String id,
final List<DiscoveryNode> knownNodes,
final Version version,
final TransportVersion transportVersion,
final ThreadPool threadPool
) {
boolean success = false;
final Settings s = Settings.builder().put("node.name", id).build();
ClusterName clusterName = ClusterName.CLUSTER_NAME_SETTING.get(s);
MockTransportService newService = MockTransportService.createNewService(s, version, threadPool, null);
MockTransportService newService = MockTransportService.createNewService(s, version, transportVersion, threadPool, null);
try {
newService.registerRequestHandler(
ClusterSearchShardsAction.NAME,
Expand Down Expand Up @@ -161,7 +163,15 @@ private static MockTransportService startTransport(
}

public void testSearchSkipUnavailable() throws IOException {
try (MockTransportService remoteTransport = startTransport("node0", new CopyOnWriteArrayList<>(), Version.CURRENT, threadPool)) {
try (
MockTransportService remoteTransport = startTransport(
"node0",
new CopyOnWriteArrayList<>(),
Version.CURRENT,
TransportVersion.CURRENT,
threadPool
)
) {
DiscoveryNode remoteNode = remoteTransport.getLocalDiscoNode();

updateRemoteClusterSettings(Collections.singletonMap("seeds", remoteNode.getAddress().toString()));
Expand Down Expand Up @@ -259,7 +269,15 @@ public void testSearchSkipUnavailable() throws IOException {
}

public void testSkipUnavailableDependsOnSeeds() throws IOException {
try (MockTransportService remoteTransport = startTransport("node0", new CopyOnWriteArrayList<>(), Version.CURRENT, threadPool)) {
try (
MockTransportService remoteTransport = startTransport(
"node0",
new CopyOnWriteArrayList<>(),
Version.CURRENT,
TransportVersion.CURRENT,
threadPool
)
) {
DiscoveryNode remoteNode = remoteTransport.getLocalDiscoNode();

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ public void testCCSCompatibilityCheck() throws Exception {
ActionFilters actionFilters = mock(ActionFilters.class);
when(actionFilters.filters()).thenReturn(new ActionFilter[0]);
try {
TransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool);
TransportService transportService = MockTransportService.createNewService(
Settings.EMPTY,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool
);

ResolveIndexAction.Request request = new ResolveIndexAction.Request(new String[] { "test" }) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ public void testCCSCompatibilityCheck() throws Exception {
ActionFilters actionFilters = mock(ActionFilters.class);
when(actionFilters.filters()).thenReturn(new ActionFilter[0]);
try {
TransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool);
TransportService transportService = MockTransportService.createNewService(
Settings.EMPTY,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool
);

FieldCapabilitiesRequest fieldCapsRequest = new FieldCapabilitiesRequest();
fieldCapsRequest.indexFilter(new DummyQueryBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,15 @@ public void testMergeShardsIterators() {
}

public void testProcessRemoteShards() {
try (TransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null)) {
try (
TransportService transportService = MockTransportService.createNewService(
Settings.EMPTY,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool,
null
)
) {
RemoteClusterService service = transportService.getRemoteClusterService();
assertFalse(service.isCrossClusterSearchEnabled());
Map<String, ClusterSearchShardsResponse> searchShardsResponseMap = new HashMap<>();
Expand Down Expand Up @@ -454,6 +462,7 @@ private MockTransportService[] startTransport(
"node_remote" + i,
knownNodes,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool
);
mockTransportServices[i] = remoteSeedTransport;
Expand Down Expand Up @@ -490,7 +499,15 @@ public void testCCSRemoteReduceMergeFails() throws Exception {
OriginalIndices localIndices = local ? new OriginalIndices(new String[] { "index" }, SearchRequest.DEFAULT_INDICES_OPTIONS) : null;
TransportSearchAction.SearchTimeProvider timeProvider = new TransportSearchAction.SearchTimeProvider(0, 0, () -> 0);
Function<Boolean, AggregationReduceContext> reduceContext = finalReduce -> null;
try (MockTransportService service = MockTransportService.createNewService(settings, Version.CURRENT, threadPool, null)) {
try (
MockTransportService service = MockTransportService.createNewService(
settings,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool,
null
)
) {
service.start();
service.acceptIncomingRequests();
RemoteClusterService remoteClusterService = service.getRemoteClusterService();
Expand Down Expand Up @@ -547,7 +564,15 @@ public void testCCSRemoteReduce() throws Exception {
OriginalIndices localIndices = local ? new OriginalIndices(new String[] { "index" }, SearchRequest.DEFAULT_INDICES_OPTIONS) : null;
int totalClusters = numClusters + (local ? 1 : 0);
TransportSearchAction.SearchTimeProvider timeProvider = new TransportSearchAction.SearchTimeProvider(0, 0, () -> 0);
try (MockTransportService service = MockTransportService.createNewService(settings, Version.CURRENT, threadPool, null)) {
try (
MockTransportService service = MockTransportService.createNewService(
settings,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool,
null
)
) {
service.start();
service.acceptIncomingRequests();
RemoteClusterService remoteClusterService = service.getRemoteClusterService();
Expand Down Expand Up @@ -794,7 +819,15 @@ public void testCollectSearchShards() throws Exception {
Settings.Builder builder = Settings.builder();
MockTransportService[] mockTransportServices = startTransport(numClusters, nodes, remoteIndicesByCluster, builder);
Settings settings = builder.build();
try (MockTransportService service = MockTransportService.createNewService(settings, Version.CURRENT, threadPool, null)) {
try (
MockTransportService service = MockTransportService.createNewService(
settings,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool,
null
)
) {
service.start();
service.acceptIncomingRequests();
RemoteClusterService remoteClusterService = service.getRemoteClusterService();
Expand Down Expand Up @@ -1430,7 +1463,12 @@ public void testCCSCompatibilityCheck() throws Exception {
when(actionFilters.filters()).thenReturn(new ActionFilter[0]);
ThreadPool threadPool = new ThreadPool(settings);
try {
TransportService transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool);
TransportService transportService = MockTransportService.createNewService(
Settings.EMPTY,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool
);

SearchRequest searchRequest = new SearchRequest();
searchRequest.source(new SearchSourceBuilder().query(new DummyQueryBuilder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.elasticsearch.discovery;

import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.coordination.Coordinator;
Expand Down Expand Up @@ -64,7 +65,13 @@ default Map<String, Supplier<SeedHostsProvider>> getSeedHostProviders(

@Before
public void setupDummyServices() {
transportService = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, mock(ThreadPool.class), null);
transportService = MockTransportService.createNewService(
Settings.EMPTY,
Version.CURRENT,
TransportVersion.CURRENT,
mock(ThreadPool.class),
null
);
masterService = mock(MasterService.class);
namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
clusterApplier = mock(ClusterApplier.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.TransportVersion;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.node.tasks.TaskManagerTestCase;
import org.elasticsearch.action.support.PlainActionFuture;
Expand Down Expand Up @@ -113,6 +114,7 @@ private void runTest(
final MockTransportService parentTransportService = MockTransportService.createNewService(
Settings.EMPTY,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool
);
resources.add(parentTransportService);
Expand All @@ -123,6 +125,7 @@ private void runTest(
final MockTransportService childTransportService = MockTransportService.createNewService(
Settings.EMPTY,
Version.CURRENT,
TransportVersion.CURRENT,
threadPool
);
resources.add(childTransportService);
Expand Down

0 comments on commit 0d09580

Please sign in to comment.