Search in sources :

Example 1 with WorkflowClient

use of io.temporal.client.WorkflowClient in project sdk-java by temporalio.

the class AsyncLambdaTest method asyncLambdaCorrectSpanStructureAndBaggagePropagation.

/*
   * We are checking that spans structure looks like this:
   * ClientFunction
   *       |
   *     child
   *       v
   * StartWorkflow:TestWorkflow  -follow>  RunWorkflow:TestWorkflow
   * And async invocation of lambda doesn't create its own child or following spans
   */
@Test
public void asyncLambdaCorrectSpanStructureAndBaggagePropagation() {
    Span span = mockTracer.buildSpan("ClientFunction").start();
    WorkflowClient client = testWorkflowRule.getWorkflowClient();
    try (Scope scope = mockTracer.scopeManager().activate(span)) {
        Span activeSpan = mockTracer.scopeManager().activeSpan();
        final String BAGGAGE_ITEM_VALUE = "baggage-item-value";
        activeSpan.setBaggageItem(BAGGAGE_ITEM_KEY, BAGGAGE_ITEM_VALUE);
        TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).validateBuildWithDefaults());
        assertEquals("Baggage item should be propagated all the way to the lambda body", BAGGAGE_ITEM_VALUE, workflow.workflow("input"));
    } finally {
        span.finish();
    }
    OpenTracingSpansHelper spansHelper = new OpenTracingSpansHelper(mockTracer.finishedSpans());
    MockSpan clientSpan = spansHelper.getSpanByOperationName("ClientFunction");
    MockSpan workflowStartSpan = spansHelper.getByParentSpan(clientSpan).get(0);
    assertEquals(clientSpan.context().spanId(), workflowStartSpan.parentId());
    assertEquals("StartWorkflow:TestWorkflow", workflowStartSpan.operationName());
    MockSpan workflowRunSpan = spansHelper.getByParentSpan(workflowStartSpan).get(0);
    assertEquals(workflowStartSpan.context().spanId(), workflowRunSpan.parentId());
    assertEquals("RunWorkflow:TestWorkflow", workflowRunSpan.operationName());
    assertEquals("Lambda shouldn't create any new spans, it should carry an existing span", 0, spansHelper.getByParentSpan(workflowRunSpan).size());
}
Also used : Scope(io.opentracing.Scope) WorkflowClient(io.temporal.client.WorkflowClient) MockSpan(io.opentracing.mock.MockSpan) Span(io.opentracing.Span) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 2 with WorkflowClient

use of io.temporal.client.WorkflowClient in project sdk-java by temporalio.

the class CustomSpanNamingTest method testActivityFailureSpanStructure.

@Test
public void testActivityFailureSpanStructure() {
    MockSpan span = mockTracer.buildSpan("ClientFunction").start();
    WorkflowClient client = testWorkflowRule.getWorkflowClient();
    try (Scope scope = mockTracer.scopeManager().activate(span)) {
        TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).validateBuildWithDefaults());
        assertEquals("bar", workflow.workflow("input"));
    } finally {
        span.finish();
    }
    OpenTracingSpansHelper spansHelper = new OpenTracingSpansHelper(mockTracer.finishedSpans());
    MockSpan clientSpan = spansHelper.getSpanByOperationName("ClientFunction");
    MockSpan workflowStartSpan = spansHelper.getByParentSpan(clientSpan).get(0);
    assertEquals(clientSpan.context().spanId(), workflowStartSpan.parentId());
    assertEquals("StartWorkflow", workflowStartSpan.operationName());
    assertEquals("TestWorkflow", workflowStartSpan.tags().get("resource.name"));
    MockSpan workflowRunSpan = spansHelper.getByParentSpan(workflowStartSpan).get(0);
    assertEquals(workflowStartSpan.context().spanId(), workflowRunSpan.parentId());
    assertEquals("RunWorkflow", workflowRunSpan.operationName());
    assertEquals("TestWorkflow", workflowRunSpan.tags().get("resource.name"));
    MockSpan activityStartSpan = spansHelper.getByParentSpan(workflowRunSpan).get(0);
    assertEquals(workflowRunSpan.context().spanId(), activityStartSpan.parentId());
    assertEquals("StartActivity", activityStartSpan.operationName());
    assertEquals("Activity", activityStartSpan.tags().get("resource.name"));
    List<MockSpan> activityRunSpans = spansHelper.getByParentSpan(activityStartSpan);
    MockSpan activityFailRunSpan = activityRunSpans.get(0);
    assertEquals(activityStartSpan.context().spanId(), activityFailRunSpan.parentId());
    assertEquals("RunActivity", activityFailRunSpan.operationName());
    assertEquals("Activity", activityFailRunSpan.tags().get("resource.name"));
    assertEquals(true, activityFailRunSpan.tags().get(Tags.ERROR.getKey()));
    MockSpan activitySuccessfulRunSpan = activityRunSpans.get(1);
    assertEquals(activityStartSpan.context().spanId(), activitySuccessfulRunSpan.parentId());
    assertEquals("RunActivity", activitySuccessfulRunSpan.operationName());
    assertEquals("Activity", activitySuccessfulRunSpan.tags().get("resource.name"));
}
Also used : Scope(io.opentracing.Scope) WorkflowClient(io.temporal.client.WorkflowClient) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 3 with WorkflowClient

use of io.temporal.client.WorkflowClient in project sdk-java by temporalio.

the class ExceptionIgnoredTest method testActivityFailureSpanStructure.

@Test
public void testActivityFailureSpanStructure() {
    MockSpan span = mockTracer.buildSpan("ClientFunction").start();
    WorkflowClient client = testWorkflowRule.getWorkflowClient();
    try (Scope scope = mockTracer.scopeManager().activate(span)) {
        TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).validateBuildWithDefaults());
        assertEquals("bar", workflow.workflow("input"));
    } finally {
        span.finish();
    }
    OpenTracingSpansHelper spansHelper = new OpenTracingSpansHelper(mockTracer.finishedSpans());
    MockSpan clientSpan = spansHelper.getSpanByOperationName("ClientFunction");
    MockSpan workflowStartSpan = spansHelper.getByParentSpan(clientSpan).get(0);
    assertEquals(clientSpan.context().spanId(), workflowStartSpan.parentId());
    assertEquals("StartWorkflow:TestWorkflow", workflowStartSpan.operationName());
    MockSpan workflowRunSpan = spansHelper.getByParentSpan(workflowStartSpan).get(0);
    assertEquals(workflowStartSpan.context().spanId(), workflowRunSpan.parentId());
    assertEquals("RunWorkflow:TestWorkflow", workflowRunSpan.operationName());
    MockSpan activityStartSpan = spansHelper.getByParentSpan(workflowRunSpan).get(0);
    assertEquals(workflowRunSpan.context().spanId(), activityStartSpan.parentId());
    assertEquals("StartActivity:Activity", activityStartSpan.operationName());
    List<MockSpan> activityRunSpans = spansHelper.getByParentSpan(activityStartSpan);
    MockSpan failedActivityRunSpan = activityRunSpans.get(0);
    assertEquals(activityStartSpan.context().spanId(), failedActivityRunSpan.parentId());
    assertEquals("RunActivity:Activity", failedActivityRunSpan.operationName());
    assertEquals(true, failedActivityRunSpan.tags().get(Tags.ERROR.getKey()));
    MockSpan failureIgnoredActivityRunSpan = activityRunSpans.get(1);
    assertEquals(activityStartSpan.context().spanId(), failureIgnoredActivityRunSpan.parentId());
    assertEquals("RunActivity:Activity", failureIgnoredActivityRunSpan.operationName());
    assertEquals(false, failureIgnoredActivityRunSpan.tags().get(Tags.ERROR.getKey()));
    MockSpan successfulActivityRunSpan = activityRunSpans.get(2);
    assertEquals(activityStartSpan.context().spanId(), successfulActivityRunSpan.parentId());
    assertEquals("RunActivity:Activity", successfulActivityRunSpan.operationName());
}
Also used : Scope(io.opentracing.Scope) WorkflowClient(io.temporal.client.WorkflowClient) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 4 with WorkflowClient

use of io.temporal.client.WorkflowClient in project sdk-java by temporalio.

the class GlobalTracerTest method testTrivialWorkflowWithGlobalTracer.

/*
   * We are checking that spans structure looks like this:
   * ClientFunction
   *       |
   *     child
   *       v
   * StartWorkflow:TestWorkflow  -follow>  RunWorkflow:TestWorkflow
   */
@Test
public void testTrivialWorkflowWithGlobalTracer() {
    MockSpan span = mockTracer.buildSpan("ClientFunction").start();
    WorkflowClient client = testWorkflowRule.getWorkflowClient();
    try (Scope scope = mockTracer.scopeManager().activate(span)) {
        TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).validateBuildWithDefaults());
        assertEquals("bar", workflow.workflow("input"));
    } finally {
        span.finish();
    }
    OpenTracingSpansHelper spansHelper = new OpenTracingSpansHelper(mockTracer.finishedSpans());
    MockSpan clientSpan = spansHelper.getSpanByOperationName("ClientFunction");
    MockSpan workflowStartSpan = spansHelper.getByParentSpan(clientSpan).get(0);
    assertEquals(clientSpan.context().spanId(), workflowStartSpan.parentId());
    assertEquals("StartWorkflow:TestWorkflow", workflowStartSpan.operationName());
    MockSpan workflowRunSpan = spansHelper.getByParentSpan(workflowStartSpan).get(0);
    assertEquals(workflowStartSpan.context().spanId(), workflowRunSpan.parentId());
    assertEquals("RunWorkflow:TestWorkflow", workflowRunSpan.operationName());
}
Also used : Scope(io.opentracing.Scope) WorkflowClient(io.temporal.client.WorkflowClient) MockSpan(io.opentracing.mock.MockSpan) Test(org.junit.Test)

Example 5 with WorkflowClient

use of io.temporal.client.WorkflowClient in project sdk-java by temporalio.

the class JaegerTest method trivialTest.

@Test
public void trivialTest() {
    Span span = tracer.buildSpan("ClientFunction").start();
    WorkflowClient client = testWorkflowRule.getWorkflowClient();
    try (Scope scope = tracer.scopeManager().activate(span)) {
        TestWorkflow workflow = client.newWorkflowStub(TestWorkflow.class, WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).validateBuildWithDefaults());
        assertEquals("bar", workflow.workflow("input"));
    } finally {
        span.finish();
    }
    List<JaegerSpan> reportedSpans = reporter.getSpans();
    assertNotNull(reportedSpans);
    assertTrue(reportedSpans.size() > 1);
}
Also used : Scope(io.opentracing.Scope) JaegerSpan(io.jaegertracing.internal.JaegerSpan) WorkflowClient(io.temporal.client.WorkflowClient) JaegerSpan(io.jaegertracing.internal.JaegerSpan) Span(io.opentracing.Span) Test(org.junit.Test)

Aggregations

WorkflowClient (io.temporal.client.WorkflowClient)99 Worker (io.temporal.worker.Worker)66 Test (org.junit.Test)55 WorkflowOptions (io.temporal.client.WorkflowOptions)51 WorkflowServiceStubs (io.temporal.serviceclient.WorkflowServiceStubs)41 WorkerFactory (io.temporal.worker.WorkerFactory)33 Scope (io.opentracing.Scope)12 WorkflowException (io.temporal.client.WorkflowException)12 MockSpan (io.opentracing.mock.MockSpan)11 TestWorkflow1 (io.temporal.workflow.shared.TestWorkflows.TestWorkflow1)10 WorkflowTestingTest (io.temporal.internal.testing.WorkflowTestingTest)9 TestWorkflows (io.temporal.workflow.shared.TestWorkflows)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 TimeoutFailure (io.temporal.failure.TimeoutFailure)7 ActivityFailure (io.temporal.failure.ActivityFailure)6 Span (io.opentracing.Span)5 WorkflowFailedException (io.temporal.client.WorkflowFailedException)5 WorkflowStub (io.temporal.client.WorkflowStub)5 WorkflowExecution (io.temporal.api.common.v1.WorkflowExecution)4 NoArgsWorkflow (io.temporal.workflow.shared.TestWorkflows.NoArgsWorkflow)4