Repository: searchbox-io/Jest
Pull request #497 (2017-04-19 14:35:39)

Add support for pending cluster tasks
https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-pending.html


Patch:
diff --git a/jest-common/src/main/java/io/searchbox/cluster/PendingClusterTasks.java b/jest-common/src/main/java/io/searchbox/cluster/PendingClusterTasks.java
new file mode 100644
index 00000000..b801272c
--- /dev/null
+++ b/jest-common/src/main/java/io/searchbox/cluster/PendingClusterTasks.java
@@ -0,0 +1,28 @@
+package io.searchbox.cluster;
+
+import io.searchbox.action.AbstractAction;
+import io.searchbox.action.GenericResultAbstractAction;
+
+public class PendingClusterTasks extends GenericResultAbstractAction {
+    protected PendingClusterTasks(Builder builder) {
+        super(builder);
+        setURI(buildURI());
+    }
+
+    @Override
+    protected String buildURI() {
+        return super.buildURI() + "/_cluster/pending_tasks";
+    }
+
+    @Override
+    public String getRestMethodName() {
+        return "GET";
+    }
+
+    public static class Builder extends AbstractAction.Builder<PendingClusterTasks, Builder> {
+        @Override
+        public PendingClusterTasks build() {
+            return new PendingClusterTasks(this);
+        }
+    }
+}


Test patch:
diff --git a/jest-common/src/test/java/io/searchbox/cluster/PendingClusterTasksTest.java b/jest-common/src/test/java/io/searchbox/cluster/PendingClusterTasksTest.java
new file mode 100644
index 00000000..8f630808
--- /dev/null
+++ b/jest-common/src/test/java/io/searchbox/cluster/PendingClusterTasksTest.java
@@ -0,0 +1,14 @@
+package io.searchbox.cluster;
+
+import io.searchbox.action.Action;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class PendingClusterTasksTest {
+    @Test
+    public void testUriGeneration() {
+        Action action = new PendingClusterTasks.Builder().build();
+        assertEquals("/_cluster/pending_tasks", action.getURI());
+    }
+}
diff --git a/jest/src/test/java/io/searchbox/cluster/PendingClusterTasksIntegrationTest.java b/jest/src/test/java/io/searchbox/cluster/PendingClusterTasksIntegrationTest.java
new file mode 100644
index 00000000..65da9135
--- /dev/null
+++ b/jest/src/test/java/io/searchbox/cluster/PendingClusterTasksIntegrationTest.java
@@ -0,0 +1,22 @@
+package io.searchbox.cluster;
+
+import com.google.common.collect.Iterables;
+import io.searchbox.client.JestResult;
+import io.searchbox.common.AbstractIntegrationTest;
+import org.elasticsearch.test.ESIntegTestCase;
+import org.junit.Test;
+
+import java.io.IOException;
+
+@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1)
+public class PendingClusterTasksIntegrationTest extends AbstractIntegrationTest {
+    @Test
+    public void pendingClusterTasks() throws IOException {
+        PendingClusterTasks pendingClusterTasks = new PendingClusterTasks.Builder().build();
+        JestResult result = client.execute(pendingClusterTasks);
+        assertTrue(result.getErrorMessage(), result.isSucceeded());
+
+        assertTrue(result.getJsonObject().get("tasks").isJsonArray());
+        assertTrue(Iterables.isEmpty(result.getJsonObject().getAsJsonArray("tasks")));
+    }
+}