Skip to content

Commit

Permalink
cleanup MappingUpdatedAction to remove unexecuted code
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Oct 31, 2022
1 parent 21f93e3 commit 6462c72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.opensearch.cluster.action.index;

import org.opensearch.OpenSearchException;
import org.opensearch.Version;
import org.opensearch.action.ActionListener;
import org.opensearch.action.admin.indices.mapping.put.AutoPutMappingAction;
import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest;
Expand Down Expand Up @@ -156,16 +155,11 @@ protected void sendUpdateMapping(Index index, Mapping mappingUpdate, ActionListe
putMappingRequest.setConcreteIndex(index);
putMappingRequest.source(mappingUpdate.toString(), XContentType.JSON);
putMappingRequest.clusterManagerNodeTimeout(dynamicMappingUpdateTimeout);
putMappingRequest.timeout(TimeValue.ZERO);
if (clusterService.state().nodes().getMinNodeVersion().onOrAfter(Version.V_3_0_0)) {
client.execute(
AutoPutMappingAction.INSTANCE,
putMappingRequest,
ActionListener.wrap(r -> listener.onResponse(null), listener::onFailure)
);
} else {
client.putMapping(putMappingRequest, ActionListener.wrap(r -> listener.onResponse(null), listener::onFailure));
}
client.execute(
AutoPutMappingAction.INSTANCE,
putMappingRequest,
ActionListener.wrap(r -> listener.onResponse(null), listener::onFailure)
);
}

// todo: this explicit unwrap should not be necessary, but is until guessRootCause is fixed to allow wrapped non-es exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,36 +153,6 @@ protected void sendUpdateMapping(Index index, Mapping mappingUpdate, ActionListe
assertTrue(fut2.isDone());
}

public void testSendUpdateMappingUsingPutMappingAction() {
DiscoveryNodes nodes = DiscoveryNodes.builder()
.add(new DiscoveryNode("first", buildNewFakeTransportAddress(), Version.V_2_0_0))
.build();
ClusterState clusterState = ClusterState.builder(new ClusterName("_name")).nodes(nodes).build();
ClusterService clusterService = mock(ClusterService.class);
when(clusterService.state()).thenReturn(clusterState);

IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class);
AdminClient adminClient = mock(AdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
Client client = mock(Client.class);
when(client.admin()).thenReturn(adminClient);

MappingUpdatedAction mua = new MappingUpdatedAction(
Settings.EMPTY,
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS),
clusterService
);
mua.setClient(client);

Settings indexSettings = Settings.builder().put(SETTING_VERSION_CREATED, Version.CURRENT).build();
final Mapper.BuilderContext context = new Mapper.BuilderContext(indexSettings, new ContentPath());
RootObjectMapper rootObjectMapper = new RootObjectMapper.Builder("name").build(context);
Mapping update = new Mapping(Version.V_2_0_0, rootObjectMapper, new MetadataFieldMapper[0], Map.of());

mua.sendUpdateMapping(new Index("name", "uuid"), update, ActionListener.wrap(() -> {}));
verify(indicesAdminClient).putMapping(any(), any());
}

public void testSendUpdateMappingUsingAutoPutMappingAction() {
DiscoveryNodes nodes = DiscoveryNodes.builder()
.add(new DiscoveryNode("first", buildNewFakeTransportAddress(), Version.V_3_0_0))
Expand Down

0 comments on commit 6462c72

Please sign in to comment.