Search in sources :

Example 26 with Task

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

the class CloudTasksUtilsTest method testSuccess_enqueueTasks_iterable.

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

Example 27 with Task

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

the class CloudTasksUtilsTest method testSuccess_createGetTasks_withJitterSeconds.

@SuppressWarnings("ProtoTimestampGetSecondsGetNano")
@Test
void testSuccess_createGetTasks_withJitterSeconds() {
    Task task = cloudTasksUtils.createGetTaskWithJitter("/the/path", "myservice", params, Optional.of(100));
    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");
    Instant scheduleTime = Instant.ofEpochSecond(task.getScheduleTime().getSeconds());
    Instant lowerBoundTime = Instant.ofEpochMilli(clock.nowUtc().getMillis());
    Instant upperBound = Instant.ofEpochMilli(clock.nowUtc().plusSeconds(100).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 28 with Task

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

the class CloudTasksUtilsTest method testSuccess_createGetTasks.

@Test
void testSuccess_createGetTasks() {
    Task task = cloudTasksUtils.createGetTask("/the/path", "myservice", params);
    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 29 with Task

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

the class ServiceProviderCallActivityProcessTest method nominal.

/**
 * <p>
 * Check the message processing where: a valid request is sent to create a new process instance from web channel.
 * </p>
 * <p>
 * Expected results:
 * </p>
 * <ul>
 * <li>the process instance is correctly created in the Flowable engine,</li>
 * <li>the process instance is automatically completed with the right service call.</li>
 * </ul>
 */
@Test
public void nominal() throws Exception {
    final GregorianCalendar now = new GregorianCalendar();
    // Create a new instance of the process definition
    final StringBuilder callActivityId_level1 = new StringBuilder();
    final StringBuilder callActivityId_level2 = new StringBuilder();
    {
        final Start start = new Start();
        start.setCustomer(BPMN_USER);
        start.setAddress(CUSTOMER_ADRESS);
        start.setDate(now.getTime());
        // Send the 1st valid request for start event 'request
        final RequestToProviderMessage request_1 = new RequestToProviderMessage(COMPONENT_UNDER_TEST, CALL_ACTIVITY_PROVIDER_SU, OPERATION_START, AbsItfOperation.MEPPatternConstants.IN_OUT.value(), toByteArray(start));
        // Assert the response of the 1st valid request
        final ServiceProviderImplementation archiverServiceImpl = this.getArchiveAttachmentsServiceImpl(new ArchiverResponse(), now, callActivityId_level2);
        COMPONENT.sendAndCheckResponseAndSendStatus(request_1, archiverServiceImpl, new MessageChecks() {

            @Override
            public void checks(final Message message) throws Exception {
                // Check the reply
                final Source fault = message.getFault();
                assertNull("Unexpected fault", (fault == null ? null : SourceHelper.toString(fault)));
                assertNotNull("No XML payload in response", message.getPayload());
                final Object responseObj = UNMARSHALLER.unmarshal(message.getPayload());
                assertTrue(responseObj instanceof StartResponse);
                final StartResponse response = (StartResponse) responseObj;
                assertNotNull(response.getCaseFileNumber());
                callActivityId_level1.append(response.getCaseFileNumber());
            }
        }, ExchangeStatus.DONE);
    }
    // Wait the request of the 2nd service task
    final String callActivityId_level3;
    {
        final RequestMessage coreServiceRequestMsg = COMPONENT_UNDER_TEST.pollRequestFromConsumer();
        assertNotNull("No XML payload in response", coreServiceRequestMsg.getPayload());
        final Object coreServiceRequestObj = UNMARSHALLER.unmarshal(coreServiceRequestMsg.getPayload());
        assertTrue(coreServiceRequestObj instanceof Execute);
        final Execute coreServiceRequest = (Execute) coreServiceRequestObj;
        callActivityId_level3 = coreServiceRequest.getOrderId();
        final ResponseMessage coreServiceResponseMsg = new ResponseToConsumerMessage(coreServiceRequestMsg, toByteArray(new ExecuteResponse()));
        COMPONENT_UNDER_TEST.pushResponseToConsumer(coreServiceResponseMsg);
        final StatusMessage coreServiceStatusMsg = COMPONENT_UNDER_TEST.pollStatusFromConsumer();
        assertEquals(ExchangeStatus.DONE, coreServiceStatusMsg.getStatus());
    }
    this.assertProcessInstancePending(callActivityId_level1.toString(), "processLevel1");
    this.assertProcessInstancePending(callActivityId_level2.toString(), "processLevel2");
    // TODO: Investigate why the process instance level 3 is not finished here. Perhaps not yet in historic part
    // assertProcessInstanceFinished(callActivityId_level3);
    this.waitUserTaskAssignment(callActivityId_level2.toString(), "usertask1", BPMN_USER);
    this.assertCurrentUserTask(callActivityId_level2.toString(), "usertask1", BPMN_USER);
    // Check some variables of process instances
    {
        final ProcessInstanceQuery processInstQuery = this.flowableClient.getRuntimeService().createProcessInstanceQuery();
        final ProcessInstance processInstance = processInstQuery.processInstanceId(callActivityId_level1.toString()).includeProcessVariables().singleResult();
        assertNotNull(processInstance.getProcessVariables().get("date"));
        // 'date' is a java.util.Date
        assertEquals(now.getTime(), processInstance.getProcessVariables().get("date"));
    }
    {
        final ProcessInstanceQuery processInstQuery = this.flowableClient.getRuntimeService().createProcessInstanceQuery();
        final ProcessInstance processInstance = processInstQuery.processInstanceId(callActivityId_level2.toString()).includeProcessVariables().singleResult();
        assertNotNull(processInstance.getProcessVariables().get("dateLevel2"));
        // 'dateLevel2' is a date represented as a String using ISO format
        assertEquals(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").format(now.getTime()), processInstance.getProcessVariables().get("dateLevel2"));
    }
    // Retrieve the user task basket using integration service
    {
        final GetTasks getTasksReq = new GetTasks();
        getTasksReq.setActive(true);
        getTasksReq.setAssignee(BPMN_USER);
        // getTasksReq.setProcessInstanceIdentifier(processInstanceId);
        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());
        assertEquals(1, getTaskResp.getTasks().getTask().size());
        final Task task = getTaskResp.getTasks().getTask().get(0);
        assertEquals("processLevel2", task.getProcessDefinitionIdentifier());
        assertEquals(callActivityId_level2.toString(), task.getProcessInstanceIdentifier());
        assertEquals("usertask1", task.getTaskIdentifier());
        COMPONENT.sendDoneStatus(getTaskRespMsg);
    }
    // Complete the user task
    {
        final Unlock userTaskRequest = new Unlock();
        userTaskRequest.setCallActivityId(callActivityId_level2.toString());
        userTaskRequest.setUnlocker(BPMN_USER);
        final RequestToProviderMessage userTaskRequestMsg = new RequestToProviderMessage(COMPONENT_UNDER_TEST, CALL_ACTIVITY_PROVIDER_SU, OPERATION_UNLOCK, AbsItfOperation.MEPPatternConstants.IN_OUT.value(), toByteArray(userTaskRequest));
        final ResponseMessage userTaskResponseMsg = COMPONENT.sendAndGetResponse(userTaskRequestMsg);
        COMPONENT.sendStatus(new StatusToProviderMessage(userTaskResponseMsg, ExchangeStatus.DONE), false);
        // Check the reply
        assertNull("Unexpected fault", (userTaskResponseMsg.isFault() ? SourceHelper.toString(userTaskResponseMsg.getFault()) : null));
        assertNotNull("No XML payload in response", userTaskResponseMsg.getPayload());
        final Object userTaskResponseObj = UNMARSHALLER.unmarshal(userTaskResponseMsg.getPayload());
        assertTrue(userTaskResponseObj instanceof UnlockAck);
    }
    // Wait the end of the process instance
    this.waitEndOfProcessInstance(callActivityId_level1.toString());
    // Assertions about state of process instance at Flowable Level
    this.assertProcessInstanceFinished(callActivityId_level1.toString());
    // Check MONIT traces
    final List<LogRecord> allMonitLogs = IN_MEMORY_LOG_HANDLER.getAllRecords(Level.MONIT);
    final LogRecord firstLogOfProcessService = new MonitLogFilter(allMonitLogs).traceCode(TraceCode.PROVIDE_FLOW_STEP_BEGIN).interfaceName(new QName("http://petals.ow2.org/se-flowable/unit-test/call-activity/level1", "call-activity")).serviceName(new QName("http://petals.ow2.org/se-flowable/unit-test/call-activity/level1", "call-activity-service")).operationName(new QName("http://petals.ow2.org/se-flowable/unit-test/call-activity/level1", "start")).singleResult();
    final String flowInstanceIdProcessService = (String) ((FlowLogData) firstLogOfProcessService.getParameters()[0]).get(FlowLogData.FLOW_INSTANCE_ID_PROPERTY_NAME);
    final LogRecord firstLogOfProcess = new MonitLogFilter(allMonitLogs).traceCode(TraceCode.CONSUME_EXT_FLOW_STEP_BEGIN).property(FlowLogData.CORRELATED_FLOW_INSTANCE_ID_PROPERTY_NAME, flowInstanceIdProcessService).singleResult();
    final String flowInstanceIdProcess = (String) ((FlowLogData) firstLogOfProcess.getParameters()[0]).get(FlowLogData.FLOW_INSTANCE_ID_PROPERTY_NAME);
    final List<LogRecord> processMonitLogs = new MonitLogFilter(allMonitLogs).flowInstanceId(flowInstanceIdProcess).results();
    assertEquals(12, processMonitLogs.size());
    final FlowLogData initialProcessFlowLogData = assertMonitConsumerExtBeginLog(processMonitLogs.get(0));
    final String processInstanceId = (String) initialProcessFlowLogData.get(FlowableActivityFlowStepData.PROCESS_INSTANCE_ID_KEY);
    assertNotNull("process instance id missing in log trace", processInstanceId);
    final FlowLogData firstCallActivity = assertMonitProviderBeginLog(initialProcessFlowLogData, null, null, null, null, processMonitLogs.get(1));
    assertEquals(processInstanceId, firstCallActivity.get(FlowableActivityFlowStepData.PROCESS_INSTANCE_ID_KEY));
    assertEquals("processLevel2", firstCallActivity.get(FlowableActivityFlowStepData.CALL_ACTIVITY_DEFINITION_KEY));
    final String callActivityInstanceId_1 = (String) firstCallActivity.get(FlowableActivityFlowStepData.CALL_ACTIVITY_INSTANCE_ID_KEY);
    assertNotNull("call activity instance id missing in log trace", callActivityInstanceId_1);
    final FlowLogData archiverFlowLogData = assertMonitProviderBeginLog(firstCallActivity, ARCHIVE_INTERFACE, ARCHIVE_SERVICE, ARCHIVE_ENDPOINT, ARCHIVER_OPERATION, processMonitLogs.get(2));
    assertMonitProviderEndLog(archiverFlowLogData, processMonitLogs.get(3));
// TODO: Uncomment following block when problem about flowStepId/previousFlowStepId on two consecutive
// service tasks will be checked. See:
// https://cdeneux.framaboard.org/?controller=TaskViewController&action=show&task_id=251&project_id=1
/*
        final FlowLogData secondCallActivity = assertMonitProviderBeginLog(archiverFlowLogData, null, null, null,
                null, processMonitLogs.get(4));
        assertEquals(callActivityInstanceId_1,
                secondCallActivity.get(FlowableActivityFlowStepData.PROCESS_INSTANCE_ID_KEY));
        assertEquals("processLevel3",
                secondCallActivity.get(FlowableActivityFlowStepData.CALL_ACTIVITY_DEFINITION_KEY));
        final String callActivityInstanceId_2 = (String) secondCallActivity
                .get(FlowableActivityFlowStepData.CALL_ACTIVITY_INSTANCE_ID_KEY);
        assertNotNull("call activity instance id missing in log trace", callActivityInstanceId_2);

        assertMonitProviderEndLog(assertMonitProviderBeginLog(secondCallActivity, CORE_SVC_INTERFACE, CORE_SVC_SERVICE,
                CORE_SVC_ENDPOINT, CORE_SVC_OPERATION, processMonitLogs.get(5)), processMonitLogs.get(6));
        */
}
Also used : Task(org.ow2.petals.components.flowable.generic._1.Task) RequestToProviderMessage(org.ow2.petals.component.framework.junit.impl.message.RequestToProviderMessage) StatusToProviderMessage(org.ow2.petals.component.framework.junit.impl.message.StatusToProviderMessage) RequestMessage(org.ow2.petals.component.framework.junit.RequestMessage) RequestToProviderMessage(org.ow2.petals.component.framework.junit.impl.message.RequestToProviderMessage) StatusMessage(org.ow2.petals.component.framework.junit.StatusMessage) ResponseMessage(org.ow2.petals.component.framework.junit.ResponseMessage) FaultToConsumerMessage(org.ow2.petals.component.framework.junit.impl.message.FaultToConsumerMessage) StatusToConsumerMessage(org.ow2.petals.component.framework.junit.impl.message.StatusToConsumerMessage) Message(org.ow2.petals.component.framework.junit.Message) ResponseToConsumerMessage(org.ow2.petals.component.framework.junit.impl.message.ResponseToConsumerMessage) Execute(org.ow2.petals.se_flowable.unit_test.call_activity.coreservice.Execute) Start(org.ow2.petals.se_flowable.unit_test.call_activity.level1.Start) GetTasksResponse(org.ow2.petals.components.flowable.generic._1.GetTasksResponse) StartResponse(org.ow2.petals.se_flowable.unit_test.call_activity.level1.StartResponse) FlowLogData(org.ow2.petals.commons.log.FlowLogData) Source(javax.xml.transform.Source) LogRecord(java.util.logging.LogRecord) RequestMessage(org.ow2.petals.component.framework.junit.RequestMessage) ResponseToConsumerMessage(org.ow2.petals.component.framework.junit.impl.message.ResponseToConsumerMessage) MessageChecks(org.ow2.petals.component.framework.junit.helpers.MessageChecks) StatusToProviderMessage(org.ow2.petals.component.framework.junit.impl.message.StatusToProviderMessage) QName(javax.xml.namespace.QName) GregorianCalendar(java.util.GregorianCalendar) Unlock(org.ow2.petals.se_flowable.unit_test.call_activity.level1.Unlock) ExecuteResponse(org.ow2.petals.se_flowable.unit_test.call_activity.coreservice.ExecuteResponse) ResponseMessage(org.ow2.petals.component.framework.junit.ResponseMessage) UnlockAck(org.ow2.petals.se_flowable.unit_test.call_activity.level1.UnlockAck) StatusMessage(org.ow2.petals.component.framework.junit.StatusMessage) GetTasks(org.ow2.petals.components.flowable.generic._1.GetTasks) ProcessInstanceQuery(org.flowable.engine.runtime.ProcessInstanceQuery) ServiceProviderImplementation(org.ow2.petals.component.framework.junit.helpers.ServiceProviderImplementation) MonitLogFilter(org.ow2.petals.component.framework.junit.MonitLogFilter) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ArchiverResponse(org.ow2.petals.se_flowable.unit_test.call_activity.archivageservice.ArchiverResponse) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 30 with Task

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

the class SpringBootWithTektonTest method shouldContainPipelineWithM2Workspace.

@Test
public void shouldContainPipelineWithM2Workspace() {
    KubernetesList list = Serialization.unmarshalAsList(getClass().getClassLoader().getResourceAsStream("META-INF/dekorate/tekton-pipeline.yml"));
    assertNotNull(list);
    Pipeline p = findFirst(list, Pipeline.class).orElseThrow(() -> new IllegalStateException());
    assertNotNull(p);
    assertTrue(p.getSpec().getWorkspaces().stream().filter(w -> w.getName().equals("pipeline-m2-ws")).findAny().isPresent(), "Pipeline should contain workspace named 'pipeline-m2-ws'");
    Optional<PipelineTask> buildTask = findTask("project-build", p);
    assertTrue(buildTask.isPresent());
    assertTrue(buildTask.get().getWorkspaces().stream().filter(w -> w.getName().equals("m2") && w.getWorkspace().equals("pipeline-m2-ws")).findAny().isPresent(), "Build task should contain workspace 'm2 -> pipeline-m2-ws'");
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Pipeline(io.fabric8.tekton.pipeline.v1beta1.Pipeline) WorkspaceBinding(io.fabric8.tekton.pipeline.v1beta1.WorkspaceBinding) Serialization(io.dekorate.utils.Serialization) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) TaskRun(io.fabric8.tekton.pipeline.v1beta1.TaskRun) Test(org.junit.jupiter.api.Test) PipelineTask(io.fabric8.tekton.pipeline.v1beta1.PipelineTask) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Task(io.fabric8.tekton.pipeline.v1beta1.Task) PipelineRun(io.fabric8.tekton.pipeline.v1beta1.PipelineRun) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) PipelineTask(io.fabric8.tekton.pipeline.v1beta1.PipelineTask) Pipeline(io.fabric8.tekton.pipeline.v1beta1.Pipeline) Test(org.junit.jupiter.api.Test)

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