Skip to content

Commit

Permalink
Fix issue when calling Delete PIT endpoint and no PITs exist (opensea…
Browse files Browse the repository at this point in the history
…rch-project#11711)

Signed-off-by: Craig Perkins <[email protected]>
Signed-off-by: Shivansh Arora <[email protected]>
  • Loading branch information
cwperks authored and shiv0408 committed Apr 25, 2024
1 parent 8126c0c commit 951607d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix for stuck update action in a bulk with `retry_on_conflict` property ([#11152](https://github.com/opensearch-project/OpenSearch/issues/11152))
- Fix template setting override for replication type ([#11417](https://github.com/opensearch-project/OpenSearch/pull/11417))
- Fix Automatic addition of protocol broken in #11512 ([#11609](https://github.com/opensearch-project/OpenSearch/pull/11609))
- Fix issue when calling Delete PIT endpoint and no PITs exist ([#11711](https://github.com/opensearch-project/OpenSearch/pull/11711))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void deletePitContexts(
) {
if (nodeToContextsMap.size() == 0) {
listener.onResponse(new DeletePitResponse(Collections.emptyList()));
return;
}
final Set<String> clusters = nodeToContextsMap.values()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.core.tasks.TaskId;
import org.opensearch.index.query.IdsQueryBuilder;
import org.opensearch.index.query.MatchAllQueryBuilder;
Expand All @@ -33,6 +34,7 @@
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.RemoteClusterConnectionTests;
import org.opensearch.transport.Transport;
import org.opensearch.transport.TransportService;
import org.junit.Before;

import java.util.ArrayList;
Expand Down Expand Up @@ -262,6 +264,46 @@ public void getAllPits(ActionListener<GetAllPitNodesResponse> getAllPitsListener
}
}

public void testDeleteAllPITSuccessWhenNoPITsExist() throws InterruptedException, ExecutionException {
ActionFilters actionFilters = mock(ActionFilters.class);
when(actionFilters.filters()).thenReturn(new ActionFilter[0]);
List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
try (MockTransportService cluster1Transport = startTransport("cluster_1_node", knownNodes, Version.CURRENT)) {
knownNodes.add(cluster1Transport.getLocalDiscoNode());
TransportService mockTransportService = mock(TransportService.class);
PitService pitService = new PitService(clusterServiceMock, mock(SearchTransportService.class), mockTransportService, client) {
@Override
public void getAllPits(ActionListener<GetAllPitNodesResponse> getAllPitsListener) {
List<ListPitInfo> list = new ArrayList<>();
GetAllPitNodeResponse getAllPitNodeResponse = new GetAllPitNodeResponse(cluster1Transport.getLocalDiscoNode(), list);
List<GetAllPitNodeResponse> nodeList = new ArrayList();
nodeList.add(getAllPitNodeResponse);
getAllPitsListener.onResponse(new GetAllPitNodesResponse(new ClusterName("cn"), nodeList, new ArrayList()));
}
};
TransportDeletePitAction action = new TransportDeletePitAction(
mockTransportService,
actionFilters,
namedWriteableRegistry,
pitService
);
DeletePitRequest deletePITRequest = new DeletePitRequest("_all");
ActionListener<DeletePitResponse> listener = new ActionListener<DeletePitResponse>() {
@Override
public void onResponse(DeletePitResponse deletePitResponse) {
assertEquals(RestStatus.OK, deletePitResponse.status());
assertEquals(0, deletePitResponse.getDeletePitResults().size());
}

@Override
public void onFailure(Exception e) {
fail("Should not receive Exception");
}
};
action.execute(task, deletePITRequest, listener);
}
}

public void testDeletePitWhenNodeIsDown() throws InterruptedException, ExecutionException {
List<DiscoveryNode> deleteNodesInvoked = new CopyOnWriteArrayList<>();
ActionFilters actionFilters = mock(ActionFilters.class);
Expand Down

0 comments on commit 951607d

Please sign in to comment.