Search in sources :

Example 1 with RestTaskClient

use of org.infinispan.client.rest.RestTaskClient in project infinispan by infinispan.

the class TasksResourceTest method testParameterizedTaskExec.

@Test
public void testParameterizedTaskExec() {
    RestTaskClient taskClient = client.tasks();
    CompletionStage<RestResponse> response = taskClient.exec("PARAMETERIZED_TASK", singletonMap("parameter", "Hello"));
    ResponseAssertion.assertThat(response).isOk();
    Json jsonNode = Json.read(join(response).getBody());
    assertEquals("Hello", jsonNode.asString());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) RestTaskClient(org.infinispan.client.rest.RestTaskClient) Test(org.testng.annotations.Test)

Example 2 with RestTaskClient

use of org.infinispan.client.rest.RestTaskClient in project infinispan by infinispan.

the class TasksResourceTest method testTaskList.

@Test
public void testTaskList() {
    RestTaskClient taskClient = adminClient.tasks();
    RestResponse response = join(taskClient.list(ALL));
    ResponseAssertion.assertThat(response).isOk();
    Json jsonNode = Json.read(response.getBody());
    assertEquals(4, jsonNode.asList().size());
    Json task = jsonNode.at(0);
    assertEquals("Dummy", task.at("type").asString());
    assertEquals("ONE_NODE", task.at("execution_mode").asString());
    assertEquals("DummyRole", task.at("allowed_role").asString());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) RestTaskClient(org.infinispan.client.rest.RestTaskClient) Test(org.testng.annotations.Test)

Example 3 with RestTaskClient

use of org.infinispan.client.rest.RestTaskClient in project infinispan by infinispan.

the class TasksResourceTest method testFailingTaskExec.

@Test
public void testFailingTaskExec() {
    RestTaskClient taskClient = client.tasks();
    CompletionStage<RestResponse> response = taskClient.exec("FAILING_TASK");
    ResponseAssertion.assertThat(response).isError();
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestTaskClient(org.infinispan.client.rest.RestTaskClient) Test(org.testng.annotations.Test)

Example 4 with RestTaskClient

use of org.infinispan.client.rest.RestTaskClient in project infinispan by infinispan.

the class TasksResourceTest method testTaskExec.

@Test
public void testTaskExec() {
    RestTaskClient taskClient = client.tasks();
    RestResponse response = join(taskClient.exec("SUCCESSFUL_TASK"));
    ResponseAssertion.assertThat(response).isOk();
    Json jsonNode = Json.read(response.getBody());
    assertEquals("result", jsonNode.asString());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Json(org.infinispan.commons.dataconversion.internal.Json) RestTaskClient(org.infinispan.client.rest.RestTaskClient) Test(org.testng.annotations.Test)

Example 5 with RestTaskClient

use of org.infinispan.client.rest.RestTaskClient in project infinispan by infinispan.

the class TasksResourceTest method testTaskUpload.

@Test
public void testTaskUpload() throws Exception {
    RestTaskClient taskClient = client.tasks();
    String script = getResourceAsString("hello.js", getClass().getClassLoader());
    RestEntity scriptEntity = RestEntity.create(APPLICATION_JAVASCRIPT, script);
    CompletionStage<RestResponse> response = taskClient.uploadScript("hello", scriptEntity);
    ResponseAssertion.assertThat(response).isOk();
    response = taskClient.exec("hello", Collections.singletonMap("greetee", "Friend"));
    ResponseAssertion.assertThat(response).isOk();
    Json jsonNode = Json.read(join(response).getBody());
    assertEquals("Hello Friend", jsonNode.asString());
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) Util.getResourceAsString(org.infinispan.commons.util.Util.getResourceAsString) Json(org.infinispan.commons.dataconversion.internal.Json) RestTaskClient(org.infinispan.client.rest.RestTaskClient) Test(org.testng.annotations.Test)

Aggregations

RestResponse (org.infinispan.client.rest.RestResponse)5 RestTaskClient (org.infinispan.client.rest.RestTaskClient)5 Test (org.testng.annotations.Test)5 Json (org.infinispan.commons.dataconversion.internal.Json)4 RestEntity (org.infinispan.client.rest.RestEntity)1 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)1