Search in sources :

Example 21 with Task

use of com.google.cloud.tasks.v2.Task in project nomulus by google.

the class CloudTasksUtilsTest method testSuccess_createPostTasks_withJitterSeconds.

@SuppressWarnings("ProtoTimestampGetSecondsGetNano")
@Test
void testSuccess_createPostTasks_withJitterSeconds() {
    Task task = cloudTasksUtils.createPostTaskWithJitter("/the/path", "myservice", params, Optional.of(1));
    assertThat(task.getAppEngineHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST);
    assertThat(task.getAppEngineHttpRequest().getRelativeUri()).isEqualTo("/the/path");
    assertThat(task.getAppEngineHttpRequest().getAppEngineRouting().getService()).isEqualTo("myservice");
    assertThat(task.getAppEngineHttpRequest().getHeadersMap().get("Content-Type")).isEqualTo("application/x-www-form-urlencoded");
    assertThat(task.getAppEngineHttpRequest().getBody().toString(StandardCharsets.UTF_8)).isEqualTo("key1=val1&key2=val2&key1=val3");
    assertThat(task.getScheduleTime().getSeconds()).isNotEqualTo(0);
    Instant scheduleTime = Instant.ofEpochSecond(task.getScheduleTime().getSeconds());
    Instant lowerBoundTime = Instant.ofEpochMilli(clock.nowUtc().getMillis());
    Instant upperBound = Instant.ofEpochMilli(clock.nowUtc().plusSeconds(1).getMillis());
    assertThat(scheduleTime.isBefore(lowerBoundTime)).isFalse();
    assertThat(upperBound.isBefore(scheduleTime)).isFalse();
}
Also used : Task(com.google.cloud.tasks.v2.Task) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 22 with Task

use of com.google.cloud.tasks.v2.Task in project nomulus by google.

the class CloudTasksUtilsTest method testSuccess_createGetTasks_withZeroJitterSeconds.

@Test
void testSuccess_createGetTasks_withZeroJitterSeconds() {
    Task task = cloudTasksUtils.createGetTaskWithJitter("/the/path", "myservice", params, Optional.of(0));
    assertThat(task.getAppEngineHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
    assertThat(task.getAppEngineHttpRequest().getRelativeUri()).isEqualTo("/the/path?key1=val1&key2=val2&key1=val3");
    assertThat(task.getAppEngineHttpRequest().getAppEngineRouting().getService()).isEqualTo("myservice");
    assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
}
Also used : Task(com.google.cloud.tasks.v2.Task) Test(org.junit.jupiter.api.Test)

Example 23 with Task

use of com.google.cloud.tasks.v2.Task in project nomulus by google.

the class CloudTasksUtilsTest method testSuccess_createPostTasks.

@Test
void testSuccess_createPostTasks() {
    Task task = cloudTasksUtils.createPostTask("/the/path", "myservice", params);
    assertThat(task.getAppEngineHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST);
    assertThat(task.getAppEngineHttpRequest().getRelativeUri()).isEqualTo("/the/path");
    assertThat(task.getAppEngineHttpRequest().getAppEngineRouting().getService()).isEqualTo("myservice");
    assertThat(task.getAppEngineHttpRequest().getHeadersMap().get("Content-Type")).isEqualTo("application/x-www-form-urlencoded");
    assertThat(task.getAppEngineHttpRequest().getBody().toString(StandardCharsets.UTF_8)).isEqualTo("key1=val1&key2=val2&key1=val3");
    assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
}
Also used : Task(com.google.cloud.tasks.v2.Task) Test(org.junit.jupiter.api.Test)

Example 24 with Task

use of com.google.cloud.tasks.v2.Task in project nomulus by google.

the class CloudTasksUtilsTest method testSuccess_createGetTasks_withEmptyJitterSeconds.

@Test
void testSuccess_createGetTasks_withEmptyJitterSeconds() {
    Task task = cloudTasksUtils.createGetTaskWithJitter("/the/path", "myservice", params, Optional.empty());
    assertThat(task.getAppEngineHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
    assertThat(task.getAppEngineHttpRequest().getRelativeUri()).isEqualTo("/the/path?key1=val1&key2=val2&key1=val3");
    assertThat(task.getAppEngineHttpRequest().getAppEngineRouting().getService()).isEqualTo("myservice");
    assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
}
Also used : Task(com.google.cloud.tasks.v2.Task) Test(org.junit.jupiter.api.Test)

Example 25 with Task

use of com.google.cloud.tasks.v2.Task in project nomulus by google.

the class CloudTasksUtilsTest method testSuccess_enqueueTask.

@Test
void testSuccess_enqueueTask() {
    Task task = cloudTasksUtils.createGetTask("/the/path", "myservice", params);
    cloudTasksUtils.enqueue("test-queue", task);
    verify(mockClient).enqueue("project", "location", "test-queue", task);
}
Also used : Task(com.google.cloud.tasks.v2.Task) Test(org.junit.jupiter.api.Test)

Aggregations

Task (com.google.cloud.tasks.v2.Task)33 Test (org.junit.jupiter.api.Test)19 Task (org.eclipse.bpmn2.Task)17 Test (org.junit.Test)12 CloudTasksClient (com.google.cloud.tasks.v2.CloudTasksClient)11 ByteString (com.google.protobuf.ByteString)7 FlowElement (org.eclipse.bpmn2.FlowElement)5 InputSet (org.eclipse.bpmn2.InputSet)5 AssignmentsInfo (org.kie.workbench.common.stunner.bpmn.definition.property.dataio.AssignmentsInfo)5 Queue (com.google.cloud.tasks.v2.Queue)4 AdHocSubProcess (org.eclipse.bpmn2.AdHocSubProcess)4 BusinessRuleTask (org.eclipse.bpmn2.BusinessRuleTask)4 GlobalTask (org.eclipse.bpmn2.GlobalTask)4 OutputSet (org.eclipse.bpmn2.OutputSet)4 Process (org.eclipse.bpmn2.Process)4 ReceiveTask (org.eclipse.bpmn2.ReceiveTask)4 RootElement (org.eclipse.bpmn2.RootElement)4 ScriptTask (org.eclipse.bpmn2.ScriptTask)4 SendTask (org.eclipse.bpmn2.SendTask)4 ServiceTask (org.eclipse.bpmn2.ServiceTask)4