Search in sources :

Example 61 with Task

use of com.google.cloud.tasks.v2.Task in project java-tasks by googleapis.

the class CloudTasksClientTest method listTasksTest.

@Test
public void listTasksTest() throws Exception {
    Task responsesElement = Task.newBuilder().build();
    ListTasksResponse expectedResponse = ListTasksResponse.newBuilder().setNextPageToken("").addAllTasks(Arrays.asList(responsesElement)).build();
    mockCloudTasks.addResponse(expectedResponse);
    QueueName parent = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]");
    ListTasksPagedResponse pagedListResponse = client.listTasks(parent);
    List<Task> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTasksList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockCloudTasks.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTasksRequest actualRequest = ((ListTasksRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListTasksPagedResponse(com.google.cloud.tasks.v2.CloudTasksClient.ListTasksPagedResponse) Test(org.junit.Test)

Example 62 with Task

use of com.google.cloud.tasks.v2.Task in project java-tasks by googleapis.

the class TasksSampleApplication method main.

/**
 * Runs the Cloud Tasks sample application.
 */
public static void main(String[] args) throws IOException {
    String projectId = ServiceOptions.getDefaultProjectId();
    LocationName parent = LocationName.of(projectId, LOCATION_ID);
    QueueName queueName = QueueName.of(parent.getProject(), parent.getLocation(), GRAALVM_TEST_QUEUE_NAME + UUID.randomUUID().toString());
    try (CloudTasksClient client = CloudTasksClient.create()) {
        // Create queue
        Queue queue = Queue.newBuilder().setName(queueName.toString()).setRateLimits(RateLimits.newBuilder().setMaxConcurrentDispatches(1).build()).build();
        CreateQueueRequest createQueueRequest = CreateQueueRequest.newBuilder().setParent(parent.toString()).setQueue(queue).build();
        Queue createdQueue = client.createQueue(createQueueRequest);
        System.out.println("Test queue ready: " + createdQueue);
        // Create task
        HttpRequest taskTarget = HttpRequest.newBuilder().setUrl("https://google.com").setHttpMethod(HttpMethod.GET).build();
        Task taskRequest = Task.newBuilder().setHttpRequest(taskTarget).build();
        Task task = client.createTask(queueName, taskRequest);
        System.out.println("Created task: " + task);
        // Cleanup
        client.purgeQueue(queueName);
        System.out.println("Queue purged");
        client.deleteQueue(queueName);
        System.out.println("Queue deleted");
    }
}
Also used : HttpRequest(com.google.cloud.tasks.v2.HttpRequest) Task(com.google.cloud.tasks.v2.Task) CreateQueueRequest(com.google.cloud.tasks.v2.CreateQueueRequest) CloudTasksClient(com.google.cloud.tasks.v2.CloudTasksClient) QueueName(com.google.cloud.tasks.v2.QueueName) Queue(com.google.cloud.tasks.v2.Queue) LocationName(com.google.cloud.tasks.v2.LocationName)

Example 63 with Task

use of com.google.cloud.tasks.v2.Task in project java-tasks by googleapis.

the class CloudTasksClientTest method listTasksTest2.

@Test
public void listTasksTest2() throws Exception {
    Task responsesElement = Task.newBuilder().build();
    ListTasksResponse expectedResponse = ListTasksResponse.newBuilder().setNextPageToken("").addAllTasks(Arrays.asList(responsesElement)).build();
    mockCloudTasks.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListTasksPagedResponse pagedListResponse = client.listTasks(parent);
    List<Task> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTasksList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockCloudTasks.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTasksRequest actualRequest = ((ListTasksRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListTasksPagedResponse(com.google.cloud.tasks.v2.CloudTasksClient.ListTasksPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 64 with Task

use of com.google.cloud.tasks.v2.Task in project native-image-support-java by GoogleCloudPlatform.

the class TasksSampleApplication method main.

/**
 * Runs the Cloud Tasks sample application.
 */
public static void main(String[] args) throws IOException {
    String projectId = ServiceOptions.getDefaultProjectId();
    LocationName parent = LocationName.of(projectId, "us-east1");
    QueueName queueName = QueueName.of(parent.getProject(), parent.getLocation(), GRAALVM_TEST_QUEUE_NAME + UUID.randomUUID().toString());
    try (CloudTasksClient client = CloudTasksClient.create()) {
        // Create queue
        Queue queue = Queue.newBuilder().setName(queueName.toString()).setRateLimits(RateLimits.newBuilder().setMaxConcurrentDispatches(1).build()).build();
        CreateQueueRequest createQueueRequest = CreateQueueRequest.newBuilder().setParent(parent.toString()).setQueue(queue).build();
        Queue createdQueue = client.createQueue(createQueueRequest);
        System.out.println("Test queue ready: " + createdQueue);
        // Create task
        HttpRequest taskTarget = HttpRequest.newBuilder().setUrl("https://google.com").setHttpMethod(HttpMethod.GET).build();
        Task taskRequest = Task.newBuilder().setHttpRequest(taskTarget).build();
        Task task = client.createTask(queueName, taskRequest);
        System.out.println("Created task: " + task);
        // Cleanup
        client.purgeQueue(queueName);
        System.out.println("Queue purged");
        client.deleteQueue(queueName);
        System.out.println("Queue deleted");
    }
}
Also used : HttpRequest(com.google.cloud.tasks.v2.HttpRequest) Task(com.google.cloud.tasks.v2.Task) CreateQueueRequest(com.google.cloud.tasks.v2.CreateQueueRequest) CloudTasksClient(com.google.cloud.tasks.v2.CloudTasksClient) QueueName(com.google.cloud.tasks.v2.QueueName) Queue(com.google.cloud.tasks.v2.Queue) LocationName(com.google.cloud.tasks.v2.LocationName)

Example 65 with Task

use of com.google.cloud.tasks.v2.Task in project petals-se-flowable by petalslink.

the class ServiceProviderVacationProcessTest method retrieveUserTask.

/**
 * Retrieve a user task.
 *
 * @param user
 *            The user to which the task is assigned
 * @param processInstanceId
 *            The process instance of the task to retrieve
 * @param isActive
 *            <code>true</code> if the process instance is active, <code>false</code> if it is suspended,
 * @param processStartedBeginFlowLogData
 *            The first MONIT trace of the process instance execution.
 * @param isRetrievedTaskExpected
 *            Expected result: <code>true</code> if a task must be retrieved; <code>false</code> if no task must be
 *            retrieved
 * @throws JAXBException
 * @throws IOException
 */
private final void retrieveUserTask(final String user, final String processInstanceId, final boolean isActive, final FlowLogData processStartedBeginFlowLogData, final boolean isRetrievedTaskExpected) throws Exception {
    // Verify the task basket using integration service
    final GetTasks getTasksReq = new GetTasks();
    getTasksReq.setActive(isActive);
    getTasksReq.setAssignee(user);
    getTasksReq.setProcessInstanceIdentifier(processInstanceId);
    IN_MEMORY_LOG_HANDLER.clear();
    final RequestToProviderMessage requestM = new RequestToProviderMessage(COMPONENT_UNDER_TEST, NATIVE_TASKS_SVC_CFG, ITG_OP_GETTASKS, AbsItfOperation.MEPPatternConstants.IN_OUT.value(), toByteArray(getTasksReq));
    {
        final ResponseMessage getTaskRespMsg = COMPONENT.sendAndGetResponse(requestM);
        assertNotNull("No XML payload in response", getTaskRespMsg.getPayload());
        final Object getTaskRespObj = UNMARSHALLER.unmarshal(getTaskRespMsg.getPayload());
        assertTrue(getTaskRespObj instanceof GetTasksResponse);
        final GetTasksResponse getTaskResp = (GetTasksResponse) getTaskRespObj;
        assertNotNull(getTaskResp.getTasks());
        assertNotNull(getTaskResp.getTasks().getTask());
        if (isRetrievedTaskExpected) {
            assertEquals(1, getTaskResp.getTasks().getTask().size());
            final Task task = getTaskResp.getTasks().getTask().get(0);
            assertEquals(BPMN_PROCESS_DEFINITION_KEY, task.getProcessDefinitionIdentifier());
            assertEquals(processInstanceId, task.getProcessInstanceIdentifier());
            assertEquals(BPMN_PROCESS_1ST_USER_TASK_KEY, task.getTaskIdentifier());
        } else {
            assertEquals(0, getTaskResp.getTasks().getTask().size());
        }
        COMPONENT.sendDoneStatus(getTaskRespMsg);
    }
    // Check MONIT traces about the task basket invocation
    final List<LogRecord> monitLogs_taskBasket = IN_MEMORY_LOG_HANDLER.getAllRecords(Level.MONIT);
    assertEquals(2, monitLogs_taskBasket.size());
    final FlowLogData providerBegin_taskBasket = assertMonitProviderBeginLog(ITG_TASK_PORT_TYPE, ITG_TASK_SERVICE, COMPONENT_UNDER_TEST.getNativeEndpointName(ITG_TASK_SERVICE), ITG_OP_GETTASKS, monitLogs_taskBasket.get(0));
    assertMonitProviderEndLog(providerBegin_taskBasket, monitLogs_taskBasket.get(1));
    assertMonitFlowInstanceIdNotEquals(processStartedBeginFlowLogData, providerBegin_taskBasket);
}
Also used : GetTasks(org.ow2.petals.components.flowable.generic._1.GetTasks) Task(org.ow2.petals.components.flowable.generic._1.Task) RequestToProviderMessage(org.ow2.petals.component.framework.junit.impl.message.RequestToProviderMessage) LogRecord(java.util.logging.LogRecord) GetTasksResponse(org.ow2.petals.components.flowable.generic._1.GetTasksResponse) ResponseMessage(org.ow2.petals.component.framework.junit.ResponseMessage) FlowLogData(org.ow2.petals.commons.log.FlowLogData)

Aggregations

Task (com.google.cloud.tasks.v2.Task)33 Test (org.junit.jupiter.api.Test)23 Task (org.eclipse.bpmn2.Task)17 Test (org.junit.Test)14 CloudTasksClient (com.google.cloud.tasks.v2.CloudTasksClient)11 Task (io.fabric8.tekton.pipeline.v1beta1.Task)8 ByteString (com.google.protobuf.ByteString)7 IOException (java.io.IOException)6 Optional (java.util.Optional)5 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 ArrayList (java.util.ArrayList)4 List (java.util.List)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