|
@@ -1,99 +0,0 @@
|
|
|
-/*
|
|
|
- * Licensed to Elastic Search and Shay Banon under one
|
|
|
- * or more contributor license agreements. See the NOTICE file
|
|
|
- * distributed with this work for additional information
|
|
|
- * regarding copyright ownership. Elastic Search licenses this
|
|
|
- * file to you under the Apache License, Version 2.0 (the
|
|
|
- * "License"); you may not use this file except in compliance
|
|
|
- * with the License. You may obtain a copy of the License at
|
|
|
- *
|
|
|
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
- *
|
|
|
- * Unless required by applicable law or agreed to in writing,
|
|
|
- * software distributed under the License is distributed on an
|
|
|
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
- * KIND, either express or implied. See the License for the
|
|
|
- * specific language governing permissions and limitations
|
|
|
- * under the License.
|
|
|
- */
|
|
|
-
|
|
|
-package org.elasticsearch.test.integration.rest.http;
|
|
|
-
|
|
|
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
|
|
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
|
|
-import org.elasticsearch.client.Client;
|
|
|
-import org.elasticsearch.common.http.client.AsyncHttpClient;
|
|
|
-import org.elasticsearch.common.http.client.HttpClientService;
|
|
|
-import org.elasticsearch.common.http.client.Response;
|
|
|
-import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
-import org.elasticsearch.node.internal.InternalNode;
|
|
|
-import org.elasticsearch.test.integration.AbstractNodesTests;
|
|
|
-import org.testng.annotations.AfterMethod;
|
|
|
-import org.testng.annotations.BeforeMethod;
|
|
|
-import org.testng.annotations.Test;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.concurrent.ExecutionException;
|
|
|
-import java.util.concurrent.Future;
|
|
|
-
|
|
|
-import static org.elasticsearch.client.Requests.*;
|
|
|
-import static org.hamcrest.MatcherAssert.*;
|
|
|
-import static org.hamcrest.Matchers.*;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author kimchy (shay.banon)
|
|
|
- */
|
|
|
-public class RestHttpDocumentActions extends AbstractNodesTests {
|
|
|
-
|
|
|
- protected Client client1;
|
|
|
- protected Client client2;
|
|
|
- protected AsyncHttpClient httpClient;
|
|
|
-
|
|
|
- @BeforeMethod public void startNodes() {
|
|
|
- startNode("server1");
|
|
|
- startNode("server2");
|
|
|
- client1 = getClient1();
|
|
|
- client2 = getClient2();
|
|
|
- httpClient = ((InternalNode) node("server1")).injector().getInstance(HttpClientService.class).asyncHttpClient();
|
|
|
- createIndex();
|
|
|
- }
|
|
|
-
|
|
|
- protected void createIndex() {
|
|
|
- logger.info("Creating index test");
|
|
|
- client1.admin().indices().create(createIndexRequest("test")).actionGet();
|
|
|
- }
|
|
|
-
|
|
|
- @AfterMethod public void closeNodes() {
|
|
|
- client1.close();
|
|
|
- client2.close();
|
|
|
- closeAllNodes();
|
|
|
- }
|
|
|
-
|
|
|
- protected Client getClient1() {
|
|
|
- return client("server1");
|
|
|
- }
|
|
|
-
|
|
|
- protected Client getClient2() {
|
|
|
- return client("server2");
|
|
|
- }
|
|
|
-
|
|
|
- @Test public void testSimpleActions() throws IOException, ExecutionException, InterruptedException {
|
|
|
- logger.info("Running Cluster Health");
|
|
|
- ClusterHealthResponse clusterHealth = client1.admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
|
|
|
- logger.info("Done Cluster Health, status " + clusterHealth.status());
|
|
|
- assertThat(clusterHealth.timedOut(), equalTo(false));
|
|
|
- assertThat(clusterHealth.status(), equalTo(ClusterHealthStatus.GREEN));
|
|
|
-
|
|
|
- Future<Response> response = httpClient.preparePut("http://localhost:9200/test/type1/1").setBody(source("1", "test")).execute();
|
|
|
- Map<String, Object> respMap = XContentFactory.xContent(response.get().getResponseBody()).createParser(response.get().getResponseBody()).map();
|
|
|
- assertThat((Boolean) respMap.get("ok"), equalTo(Boolean.TRUE));
|
|
|
- assertThat((String) respMap.get("_id"), equalTo("1"));
|
|
|
- assertThat((String) respMap.get("_type"), equalTo("type1"));
|
|
|
- assertThat((String) respMap.get("_index"), equalTo("test"));
|
|
|
- }
|
|
|
-
|
|
|
- private String source(String id, String nameValue) {
|
|
|
- return "{ type1 : { \"id\" : \"" + id + "\", \"name\" : \"" + nameValue + "\" } }";
|
|
|
- }
|
|
|
-}
|