Skip to content

Commit

Permalink
add itest for JsonData deserialization
Browse files Browse the repository at this point in the history
Signed-off-by: bfindlay <[email protected]>
  • Loading branch information
Bfindlay committed Nov 26, 2023
1 parent cb4ffe0 commit aa9f389
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
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);
}
}
}
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 {}
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());
}
}

0 comments on commit aa9f389

Please sign in to comment.