use of io.temporal.api.common.v1.Payload in project sdk-java by temporalio.
the class ContextAccessor method readSpanContextFromHeader.
public SpanContext readSpanContextFromHeader(Header header, Tracer tracer) {
Payload payload = header.getValues().get(TRACER_HEADER_KEY);
if (payload == null) {
return null;
}
@SuppressWarnings("unchecked") Map<String, String> serializedSpanContext = DataConverter.getDefaultInstance().fromPayload(payload, HashMap.class, HASH_MAP_STRING_STRING_TYPE);
return codec.decode(serializedSpanContext, tracer);
}
use of io.temporal.api.common.v1.Payload in project sdk-java by temporalio.
the class MemoTest method testMemo.
@Test
public void testMemo() {
if (testWorkflowRule.getTestEnvironment() == null) {
return;
}
WorkflowOptions workflowOptions = SDKTestOptions.newWorkflowOptionsWithTimeouts(testWorkflowRule.getTaskQueue()).toBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).setMemo(MEMO).build();
TestNoArgsWorkflowFunc stubF = testWorkflowRule.getWorkflowClient().newWorkflowStub(TestNoArgsWorkflowFunc.class, workflowOptions);
WorkflowExecution executionF = WorkflowClient.start(stubF::func);
GetWorkflowExecutionHistoryResponse historyResp = WorkflowClientHelper.getHistoryPage(testWorkflowRule.getTestEnvironment().getWorkflowService(), SDKTestWorkflowRule.NAMESPACE, executionF, ByteString.EMPTY, new NoopScope());
HistoryEvent startEvent = historyResp.getHistory().getEvents(0);
Memo memoFromEvent = startEvent.getWorkflowExecutionStartedEventAttributes().getMemo();
Payload memoBytes = memoFromEvent.getFieldsMap().get(MEMO_KEY);
String memoRetrieved = GsonJsonPayloadConverter.getInstance().fromData(memoBytes, String.class, String.class);
assertEquals(MEMO_VALUE, memoRetrieved);
}
use of io.temporal.api.common.v1.Payload in project sdk-java by temporalio.
the class ProtoPayloadConverterTest method testProtoMessageTypeExclusion.
@Test
public void testProtoMessageTypeExclusion() {
DataConverter converter = new DefaultDataConverter(new ProtobufPayloadConverter(true));
WorkflowExecution execution = WorkflowExecution.newBuilder().setWorkflowId(UUID.randomUUID().toString()).setRunId(UUID.randomUUID().toString()).build();
Optional<Payloads> data = converter.toPayloads(execution);
Payloads payloads = data.get();
Object field = payloads.getField(payloads.getDescriptorForType().findFieldByName("payloads"));
Payload payload = (Payload) ((List<?>) field).get(0);
Object metadata = payload.getField(payload.getDescriptorForType().findFieldByName("metadata"));
assertEquals(1, ((List<?>) metadata).size());
}
use of io.temporal.api.common.v1.Payload in project sdk-java by temporalio.
the class ProtoPayloadConverterTest method testProtoMessageType.
@Test
public void testProtoMessageType() {
DataConverter converter = DataConverter.getDefaultInstance();
WorkflowExecution execution = WorkflowExecution.newBuilder().setWorkflowId(UUID.randomUUID().toString()).setRunId(UUID.randomUUID().toString()).build();
Optional<Payloads> data = converter.toPayloads(execution);
Payloads payloads = data.get();
Object field = payloads.getField(payloads.getDescriptorForType().findFieldByName("payloads"));
Payload payload = (Payload) ((List<?>) field).get(0);
Object metadata = payload.getField(payload.getDescriptorForType().findFieldByName("metadata"));
MapEntry<?, ?> secondMetadata = (MapEntry<?, ?>) ((List<?>) metadata).get(1);
assertEquals("messageType", secondMetadata.getKey());
assertEquals("temporal.api.common.v1.WorkflowExecution", ((ByteString) secondMetadata.getValue()).toString(StandardCharsets.UTF_8));
}
use of io.temporal.api.common.v1.Payload in project sdk-java by temporalio.
the class ActivityHeartbeatThrottlingTest method activityHeartbeatsGetThrottled.
/**
* Tests that Activity#heartbeat throws ActivityWorkerShutdownException after {@link
* WorkerFactory#shutdown()} is closed.
*/
@Test
public void activityHeartbeatsGetThrottled() throws InterruptedException {
TestWorkflows.NoArgsWorkflow workflow = testWorkflowRule.newWorkflowStub(TestWorkflows.NoArgsWorkflow.class);
WorkflowExecution execution = WorkflowClient.start(workflow::execute);
secondHeartbeatSent.waitForSignal();
DescribeWorkflowExecutionResponse describeResponse = testWorkflowRule.getWorkflowClient().getWorkflowServiceStubs().blockingStub().describeWorkflowExecution(DescribeWorkflowExecutionRequest.newBuilder().setNamespace(testWorkflowRule.getWorkflowClient().getOptions().getNamespace()).setExecution(execution).build());
String payload = new JacksonJsonPayloadConverter().fromData(describeResponse.getPendingActivities(0).getHeartbeatDetails().getPayloads(0), String.class, String.class);
assertEquals("Only the first heartbeat should've get through, others should be throttled", "1", payload);
}
Aggregations