Search in sources :

Example 1 with ObjectPath

use of org.elasticsearch.test.rest.yaml.ObjectPath in project elasticsearch by elastic.

the class IndexingIT method buildNodeAndVersions.

private Nodes buildNodeAndVersions() throws IOException {
    Response response = client().performRequest("GET", "_nodes");
    ObjectPath objectPath = ObjectPath.createFromResponse(response);
    Map<String, Object> nodesAsMap = objectPath.evaluate("nodes");
    Nodes nodes = new Nodes();
    for (String id : nodesAsMap.keySet()) {
        nodes.add(new Node(id, objectPath.evaluate("nodes." + id + ".name"), Version.fromString(objectPath.evaluate("nodes." + id + ".version")), HttpHost.create(objectPath.evaluate("nodes." + id + ".http.publish_address"))));
    }
    response = client().performRequest("GET", "_cluster/state");
    nodes.setMasterNodeId(ObjectPath.createFromResponse(response).evaluate("master_node"));
    return nodes;
}
Also used : Response(org.elasticsearch.client.Response) ObjectPath(org.elasticsearch.test.rest.yaml.ObjectPath)

Example 2 with ObjectPath

use of org.elasticsearch.test.rest.yaml.ObjectPath in project elasticsearch by elastic.

the class Netty4BadRequestIT method testBadRequest.

public void testBadRequest() throws IOException {
    final Response response = client().performRequest("GET", "/_nodes/settings", Collections.emptyMap());
    final ObjectPath objectPath = ObjectPath.createFromResponse(response);
    final Map<String, Object> map = objectPath.evaluate("nodes");
    int maxMaxInitialLineLength = Integer.MIN_VALUE;
    final Setting<ByteSizeValue> httpMaxInitialLineLength = HttpTransportSettings.SETTING_HTTP_MAX_INITIAL_LINE_LENGTH;
    final String key = httpMaxInitialLineLength.getKey().substring("http.".length());
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        @SuppressWarnings("unchecked") final Map<String, Object> settings = (Map<String, Object>) ((Map<String, Object>) entry.getValue()).get("settings");
        final int maxIntialLineLength;
        if (settings.containsKey("http")) {
            @SuppressWarnings("unchecked") final Map<String, Object> httpSettings = (Map<String, Object>) settings.get("http");
            if (httpSettings.containsKey(key)) {
                maxIntialLineLength = ByteSizeValue.parseBytesSizeValue((String) httpSettings.get(key), key).bytesAsInt();
            } else {
                maxIntialLineLength = httpMaxInitialLineLength.getDefault(Settings.EMPTY).bytesAsInt();
            }
        } else {
            maxIntialLineLength = httpMaxInitialLineLength.getDefault(Settings.EMPTY).bytesAsInt();
        }
        maxMaxInitialLineLength = Math.max(maxMaxInitialLineLength, maxIntialLineLength);
    }
    final String path = "/" + new String(new byte[maxMaxInitialLineLength], Charset.forName("UTF-8")).replace('\0', 'a');
    final ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(randomFrom("GET", "POST", "PUT"), path, Collections.emptyMap()));
    assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(BAD_REQUEST.getStatus()));
    assertThat(e, hasToString(containsString("too_long_frame_exception")));
    assertThat(e, hasToString(matches("An HTTP line is larger than \\d+ bytes")));
}
Also used : Response(org.elasticsearch.client.Response) ObjectPath(org.elasticsearch.test.rest.yaml.ObjectPath) ResponseException(org.elasticsearch.client.ResponseException) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map)

Aggregations

Response (org.elasticsearch.client.Response)2 ObjectPath (org.elasticsearch.test.rest.yaml.ObjectPath)2 Map (java.util.Map)1 ResponseException (org.elasticsearch.client.ResponseException)1 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.hasToString (org.hamcrest.Matchers.hasToString)1