-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add itest for JsonData deserialization
Signed-off-by: bfindlay <[email protected]>
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractTasksIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.opensearch.client.opensearch.integTest; | ||
|
||
import org.junit.Test; | ||
import org.opensearch.client.opensearch.tasks.Status; | ||
|
||
public abstract class AbstractTasksIT extends OpenSearchJavaClientTestCase { | ||
|
||
@Test | ||
public void getTasks_waitForCompletionFalse_jsonDataStatusCanBeDeserialized() { | ||
try { | ||
javaClient().indices().create(b -> b.index("test-index-a").settings(s -> s.refreshInterval(v -> v.time("1s")))); | ||
javaClient().index(b -> b.index("test-index-a").id("a").document(new IndexData("test"))); | ||
javaClient().indices().refresh(b -> b.index("test-index-a")); | ||
|
||
final var deleteByQueryResponse = javaClient().deleteByQuery( | ||
d -> d.index("test-index-a").query(q -> q.matchAll(m -> m.queryName("match-all"))).waitForCompletion(false) | ||
); | ||
|
||
javaClient().indices().refresh(b -> b.index("test-index-a")); | ||
|
||
Thread.sleep(2000); | ||
final var tasksResponse = javaClient().tasks().get(t -> t.taskId(deleteByQueryResponse.task())); | ||
|
||
assertNotNull(tasksResponse.response()); | ||
assertTrue(tasksResponse.completed()); | ||
|
||
// Deserialize the JsonData to a typed Status response | ||
final Status taskStatus = tasksResponse.task().status().to(Status.class); | ||
|
||
assertTrue(tasksResponse.completed()); | ||
|
||
// Ensure the JsonData can be deserialized | ||
assertEquals(1, taskStatus.total()); | ||
assertEquals(0, taskStatus.updated()); | ||
assertEquals(0, taskStatus.created()); | ||
assertEquals(1, taskStatus.deleted()); | ||
assertEquals(1, taskStatus.batches()); | ||
assertEquals(0, taskStatus.noops()); | ||
assertEquals(0, taskStatus.versionConflicts()); | ||
assertEquals(0, taskStatus.retries().bulk()); | ||
assertEquals(0, taskStatus.retries().search()); | ||
assertEquals(0, taskStatus.throttledMillis()); | ||
assertEquals(-1f, taskStatus.requestsPerSecond(), 0.01); | ||
} catch (Exception e) { | ||
fail(e.getMessage()); | ||
} | ||
} | ||
|
||
public class IndexData { | ||
private String title; | ||
|
||
public IndexData(String title) { | ||
this.title = title; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("IndexData{title='%s'}", title); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...-client/src/test/java/org/opensearch/client/opensearch/integTest/httpclient5/TasksIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.opensearch.client.opensearch.integTest.httpclient5; | ||
|
||
import org.opensearch.client.opensearch.integTest.AbstractTasksIT; | ||
|
||
public class TasksIT extends AbstractTasksIT implements HttpClient5TransportSupport {} |
16 changes: 16 additions & 0 deletions
16
java-client/src/test/java/org/opensearch/client/opensearch/integTest/restclient/TasksIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.opensearch.client.opensearch.integTest.restclient; | ||
|
||
import java.io.IOException; | ||
import org.apache.hc.core5.http.HttpHost; | ||
import org.opensearch.client.json.jackson.JacksonJsonpMapper; | ||
import org.opensearch.client.opensearch.integTest.AbstractTasksIT; | ||
import org.opensearch.client.transport.OpenSearchTransport; | ||
import org.opensearch.client.transport.rest_client.RestClientTransport; | ||
import org.opensearch.common.settings.Settings; | ||
|
||
public class TasksIT extends AbstractTasksIT { | ||
@Override | ||
public OpenSearchTransport buildTransport(Settings settings, HttpHost[] hosts) throws IOException { | ||
return new RestClientTransport(buildClient(settings, hosts), new JacksonJsonpMapper()); | ||
} | ||
} |