Skip to content

Commit

Permalink
Add coverage for exception thrown in fromActionResponse
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Dec 26, 2023
1 parent 1fdf2e7 commit 3ddae25
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.opensearch.common.io.stream.BytesStreamOutput;
import org.opensearch.core.action.ActionResponse;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;

import com.google.common.collect.ImmutableList;

Expand Down Expand Up @@ -68,5 +69,27 @@ public void testFromActionResponse() throws IOException {
ADTaskProfileResponse reserializedResponse = ADTaskProfileResponse.fromActionResponse((ActionResponse) response);
assertEquals(1, reserializedResponse.getNodes().size());
assertEquals(taskId, reserializedResponse.getNodes().get(0).getAdTaskProfile().getTaskId());

BytesStreamOutput output = new BytesStreamOutput();
response.writeNodesTo(output, nodeResponses);
StreamInput input = output.bytes().streamInput();

ActionResponse invalidActionResponse = new TestActionResponse(input);
assertThrows(Exception.class, () -> ADTaskProfileResponse.fromActionResponse(invalidActionResponse));

}

// A test ActionResponse class with an inactive writeTo class. Used to ensure exceptions
// are thrown when parsing implementations of such class.
private class TestActionResponse extends ActionResponse {
public TestActionResponse(StreamInput in) throws IOException {
super(in);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
return;
}
}

}

0 comments on commit 3ddae25

Please sign in to comment.