Search in sources :

Example 1 with Payload

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);
}
Also used : Payload(io.temporal.api.common.v1.Payload)

Example 2 with Payload

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);
}
Also used : TestNoArgsWorkflowFunc(io.temporal.workflow.shared.TestMultiArgWorkflowFunctions.TestNoArgsWorkflowFunc) WorkflowOptions(io.temporal.client.WorkflowOptions) WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) Payload(io.temporal.api.common.v1.Payload) GetWorkflowExecutionHistoryResponse(io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse) ByteString(com.google.protobuf.ByteString) HistoryEvent(io.temporal.api.history.v1.HistoryEvent) NoopScope(com.uber.m3.tally.NoopScope) Memo(io.temporal.api.common.v1.Memo) Test(org.junit.Test)

Example 3 with Payload

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());
}
Also used : WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) Payload(io.temporal.api.common.v1.Payload) Payloads(io.temporal.api.common.v1.Payloads) Test(org.junit.Test)

Example 4 with Payload

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));
}
Also used : MapEntry(com.google.protobuf.MapEntry) WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) Payload(io.temporal.api.common.v1.Payload) Payloads(io.temporal.api.common.v1.Payloads) Test(org.junit.Test)

Example 5 with Payload

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);
}
Also used : DescribeWorkflowExecutionResponse(io.temporal.api.workflowservice.v1.DescribeWorkflowExecutionResponse) JacksonJsonPayloadConverter(io.temporal.common.converter.JacksonJsonPayloadConverter) WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) TestWorkflows(io.temporal.workflow.shared.TestWorkflows) Test(org.junit.Test)

Aggregations

Payload (io.temporal.api.common.v1.Payload)12 Payload (dev.hawala.xns.level0.Payload)6 WorkflowExecution (io.temporal.api.common.v1.WorkflowExecution)6 Test (org.junit.Test)6 ByteString (com.google.protobuf.ByteString)5 PEX (dev.hawala.xns.level2.PEX)5 Error (dev.hawala.xns.level2.Error)4 DataConverter (io.temporal.common.converter.DataConverter)4 SearchAttributes (io.temporal.api.common.v1.SearchAttributes)3 WorkflowOptions (io.temporal.client.WorkflowOptions)3 HashMap (java.util.HashMap)3 NoopScope (com.uber.m3.tally.NoopScope)2 Payloads (io.temporal.api.common.v1.Payloads)2 HistoryEvent (io.temporal.api.history.v1.HistoryEvent)2 DescribeWorkflowExecutionResponse (io.temporal.api.workflowservice.v1.DescribeWorkflowExecutionResponse)2 GetWorkflowExecutionHistoryResponse (io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse)2 DataConverterException (io.temporal.common.converter.DataConverterException)2 TestNoArgsWorkflowFunc (io.temporal.workflow.shared.TestMultiArgWorkflowFunctions.TestNoArgsWorkflowFunc)2 SecretKey (javax.crypto.SecretKey)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1