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()));
}
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");
}
}
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()));
}
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");
}
}
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);
}
Aggregations