Skip to content

Commit

Permalink
Fix issue when calling Delete PIT endpoint and no PITs exist
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Jan 2, 2024
1 parent 6a01d2f commit 82c92de
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
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 @@ -34,6 +35,7 @@
import org.opensearch.transport.RemoteClusterConnectionTests;
import org.opensearch.transport.Transport;
import org.junit.Before;
import org.opensearch.transport.TransportService;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -262,6 +264,51 @@ 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 82c92de

Please sign in to comment.