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