Search in sources :

Example 81 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class MoreLikeThisQueryBuilderTests method testItemSerializationBwc.

public void testItemSerializationBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("AQVpbmRleAEEdHlwZQEODXsiZm9vIjoiYmFyIn0A/wD//////////QAAAAAAAAAA");
    final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2, Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        Item item = new Item(in);
        assertEquals(XContentType.JSON, item.xContentType());
        assertEquals("{\"foo\":\"bar\"}", item.doc().utf8ToString());
        assertEquals("index", item.index());
        assertEquals("type", item.type());
        try (BytesStreamOutput out = new BytesStreamOutput()) {
            out.setVersion(version);
            item.writeTo(out);
            assertArrayEquals(data, out.bytes().toBytesRef().bytes);
        }
    }
}
Also used : Item(org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item) Version(org.elasticsearch.Version) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 82 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class RestMainActionTests method testHeadResponse.

public void testHeadResponse() throws Exception {
    final String nodeName = "node1";
    final ClusterName clusterName = new ClusterName("cluster1");
    final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
    final boolean available = randomBoolean();
    final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
    final Version version = Version.CURRENT;
    final Build build = Build.CURRENT;
    final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
    XContentBuilder builder = JsonXContent.contentBuilder();
    RestRequest restRequest = new FakeRestRequest() {

        @Override
        public Method method() {
            return Method.HEAD;
        }
    };
    BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
    assertNotNull(response);
    assertEquals(expectedStatus, response.status());
// the empty responses are handled in the HTTP layer so we do
// not assert on them here
}
Also used : FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) RestRequest(org.elasticsearch.rest.RestRequest) RestStatus(org.elasticsearch.rest.RestStatus) Version(org.elasticsearch.Version) MainResponse(org.elasticsearch.action.main.MainResponse) Build(org.elasticsearch.Build) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ClusterName(org.elasticsearch.cluster.ClusterName) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 83 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class RestMainActionTests method testGetResponse.

public void testGetResponse() throws Exception {
    final String nodeName = "node1";
    final ClusterName clusterName = new ClusterName("cluster1");
    final String clusterUUID = randomAsciiOfLengthBetween(10, 20);
    final boolean available = randomBoolean();
    final RestStatus expectedStatus = available ? RestStatus.OK : RestStatus.SERVICE_UNAVAILABLE;
    final Version version = Version.CURRENT;
    final Build build = Build.CURRENT;
    final boolean prettyPrint = randomBoolean();
    final MainResponse mainResponse = new MainResponse(nodeName, version, clusterName, clusterUUID, build, available);
    XContentBuilder builder = JsonXContent.contentBuilder();
    Map<String, String> params = new HashMap<>();
    if (prettyPrint == false) {
        params.put("pretty", String.valueOf(prettyPrint));
    }
    RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withParams(params).build();
    BytesRestResponse response = RestMainAction.convertMainResponse(mainResponse, restRequest, builder);
    assertNotNull(response);
    assertEquals(expectedStatus, response.status());
    assertThat(response.content().length(), greaterThan(0));
    XContentBuilder responseBuilder = JsonXContent.contentBuilder();
    if (prettyPrint) {
        // do this to mimic what the rest layer does
        responseBuilder.prettyPrint().lfAtEnd();
    }
    mainResponse.toXContent(responseBuilder, ToXContent.EMPTY_PARAMS);
    BytesReference xcontentBytes = responseBuilder.bytes();
    assertEquals(xcontentBytes, response.content());
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) HashMap(java.util.HashMap) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) RestRequest(org.elasticsearch.rest.RestRequest) RestStatus(org.elasticsearch.rest.RestStatus) Version(org.elasticsearch.Version) MainResponse(org.elasticsearch.action.main.MainResponse) Build(org.elasticsearch.Build) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) ClusterName(org.elasticsearch.cluster.ClusterName) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 84 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class SimulatePipelineRequestTests method testSerializationWithXContentBwc.

public void testSerializationWithXContentBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("AAAAAnt9AAA=");
    final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2, Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        SimulatePipelineRequest request = new SimulatePipelineRequest();
        request.readFrom(in);
        assertEquals(XContentType.JSON, request.getXContentType());
        assertEquals("{}", request.getSource().utf8ToString());
        try (BytesStreamOutput out = new BytesStreamOutput()) {
            out.setVersion(version);
            request.writeTo(out);
            assertArrayEquals(data, out.bytes().toBytesRef().bytes);
        }
    }
}
Also used : Version(org.elasticsearch.Version) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 85 with Version

use of org.elasticsearch.Version in project elasticsearch by elastic.

the class PipelineConfigurationTests method testSerializationBwc.

public void testSerializationBwc() throws IOException {
    final byte[] data = Base64.getDecoder().decode("ATECe30AAAA=");
    final Version version = randomFrom(Version.V_5_0_0, Version.V_5_0_1, Version.V_5_0_2, Version.V_5_0_3_UNRELEASED, Version.V_5_1_1_UNRELEASED, Version.V_5_1_2_UNRELEASED, Version.V_5_2_0_UNRELEASED);
    try (StreamInput in = StreamInput.wrap(data)) {
        in.setVersion(version);
        PipelineConfiguration configuration = PipelineConfiguration.readFrom(in);
        assertEquals(XContentType.JSON, configuration.getXContentType());
        assertEquals("{}", configuration.getConfig().utf8ToString());
        try (BytesStreamOutput out = new BytesStreamOutput()) {
            out.setVersion(version);
            configuration.writeTo(out);
            assertArrayEquals(data, out.bytes().toBytesRef().bytes);
        }
    }
}
Also used : Version(org.elasticsearch.Version) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Aggregations

Version (org.elasticsearch.Version)124 Settings (org.elasticsearch.common.settings.Settings)51 StreamInput (org.elasticsearch.common.io.stream.StreamInput)21 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)20 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)16 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)14 IOException (java.io.IOException)13 SearchResponse (org.elasticsearch.action.search.SearchResponse)12 List (java.util.List)11 Map (java.util.Map)11 ClusterState (org.elasticsearch.cluster.ClusterState)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ClusterName (org.elasticsearch.cluster.ClusterName)9 TimeValue (org.elasticsearch.common.unit.TimeValue)9 VersionUtils.randomVersion (org.elasticsearch.test.VersionUtils.randomVersion)9 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)8 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)8 GeoPoint (org.elasticsearch.common.geo.GeoPoint)8