Search in sources :

Example 6 with Empty

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());
}
Also used : Empty(org.opensearch.transport.TransportResponse.Empty) BytesRestResponse(org.opensearch.rest.BytesRestResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) FakeRestChannel(org.opensearch.test.rest.FakeRestChannel) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

Empty (org.opensearch.transport.TransportResponse.Empty)6 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)3 BytesRestResponse (org.opensearch.rest.BytesRestResponse)3 FakeRestChannel (org.opensearch.test.rest.FakeRestChannel)3 FakeRestRequest (org.opensearch.test.rest.FakeRestRequest)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 OpenSearchException (org.opensearch.OpenSearchException)2 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)2 Settings (org.opensearch.common.settings.Settings)2 StatusInfo (org.opensearch.monitor.StatusInfo)2 TransportException (org.opensearch.transport.TransportException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)1 StreamInput (org.opensearch.common.io.stream.StreamInput)1 MockTransport (org.opensearch.test.transport.MockTransport)1 ConnectTransportException (org.opensearch.transport.ConnectTransportException)1 TransportRequest (org.opensearch.transport.TransportRequest)1 TransportService (org.opensearch.transport.TransportService)1