use of org.opensearch.transport.TransportResponse.Empty in project OpenSearch by opensearch-project.
the class RestBuilderListenerTests method testXContentBuilderNotClosedInBuildResponseAssertionsDisabled.
public void testXContentBuilderNotClosedInBuildResponseAssertionsDisabled() throws Exception {
AtomicReference<XContentBuilder> builderAtomicReference = new AtomicReference<>();
RestBuilderListener<TransportResponse.Empty> builderListener = new RestBuilderListener<Empty>(new FakeRestChannel(new FakeRestRequest(), randomBoolean(), 1)) {
@Override
public RestResponse buildResponse(Empty empty, XContentBuilder builder) throws Exception {
builderAtomicReference.set(builder);
return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
}
@Override
boolean assertBuilderClosed(XContentBuilder xContentBuilder) {
// don't check the actual builder being closed so we can test auto close
return true;
}
};
builderListener.buildResponse(Empty.INSTANCE);
assertNotNull(builderAtomicReference.get());
assertTrue(builderAtomicReference.get().generator().isClosed());
}
Aggregations