Search in sources :

Example 1 with TestWorkflowReturnString

use of io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString in project sdk-java by temporalio.

the class SignalExternalWorkflowFailureTest method testTerminateWorkflowSignalError.

@Test
public void testTerminateWorkflowSignalError() throws InterruptedException {
    WorkflowOptions options = WorkflowOptions.newBuilder().setTaskQueue(testWorkflowRule.getTaskQueue()).setWorkflowId(WORKFLOW_ID).build();
    TestSignaledWorkflow terminatedWorkflow = testWorkflowRule.getWorkflowClient().newWorkflowStub(TestSignaledWorkflow.class, options);
    WorkflowClient.start(terminatedWorkflow::execute);
    TestWorkflowReturnString signalingWorkflow = testWorkflowRule.newWorkflowStub(TestWorkflowReturnString.class);
    WorkflowClient.start(signalingWorkflow::execute);
    // Wait for terminatedWorkflow to start
    latch.await();
    WorkflowStub stub = WorkflowStub.fromTyped(terminatedWorkflow);
    stub.terminate("Mock terminating workflow");
    // Wait for signalingWorkflow to start and terminatedWorkflow to terminate
    latch2.countDown();
    WorkflowStub workflowStub2 = WorkflowStub.fromTyped(signalingWorkflow);
    assertEquals(workflowStub2.getResult(String.class), "Success!");
}
Also used : WorkflowStub(io.temporal.client.WorkflowStub) TestSignaledWorkflow(io.temporal.workflow.shared.TestWorkflows.TestSignaledWorkflow) WorkflowOptions(io.temporal.client.WorkflowOptions) TestWorkflowReturnString(io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString) TestWorkflowReturnString(io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString) Test(org.junit.Test)

Example 2 with TestWorkflowReturnString

use of io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString in project sdk-java by temporalio.

the class CleanWorkerShutdownHeartBeatingActivityTest method testShutdownHeartBeatingActivity.

/**
 * Tests that Activity#heartbeat throws ActivityWorkerShutdownException after {@link
 * WorkerFactory#shutdown()} is closed.
 */
@Test
public void testShutdownHeartBeatingActivity() throws ExecutionException, InterruptedException {
    TestWorkflowReturnString workflow = testWorkflowRule.newWorkflowStub(TestWorkflowReturnString.class);
    WorkflowExecution execution = WorkflowClient.start(workflow::execute);
    started.get();
    testWorkflowRule.getTestEnvironment().shutdown();
    testWorkflowRule.getTestEnvironment().awaitTermination(10, TimeUnit.MINUTES);
    List<HistoryEvent> events = testWorkflowRule.getHistory(execution).getEventsList();
    boolean found = false;
    for (HistoryEvent e : events) {
        if (e.getEventType() == EventType.EVENT_TYPE_ACTIVITY_TASK_COMPLETED) {
            found = true;
            Payloads ar = e.getActivityTaskCompletedEventAttributes().getResult();
            String r = DataConverter.getDefaultInstance().fromPayloads(0, Optional.of(ar), String.class, String.class);
            assertEquals(EXPECTED_RESULT, r);
        }
    }
    assertTrue("Contains ActivityTaskCompleted", found);
}
Also used : WorkflowExecution(io.temporal.api.common.v1.WorkflowExecution) TestWorkflowReturnString(io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString) HistoryEvent(io.temporal.api.history.v1.HistoryEvent) TestWorkflowReturnString(io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString) Payloads(io.temporal.api.common.v1.Payloads) Test(org.junit.Test)

Example 3 with TestWorkflowReturnString

use of io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString in project sdk-java by temporalio.

the class MetricsTest method testCorruptedSignalMetrics.

@Test
public void testCorruptedSignalMetrics() throws InterruptedException {
    setUp(WorkerFactoryOptions.newBuilder().setWorkerInterceptors(new CorruptedSignalWorkerInterceptor(), // Add noop just to test that list of interceptors is working.
    new WorkerInterceptor() {

        @Override
        public WorkflowInboundCallsInterceptor interceptWorkflow(WorkflowInboundCallsInterceptor next) {
            return next;
        }

        @Override
        public ActivityInboundCallsInterceptor interceptActivity(ActivityInboundCallsInterceptor next) {
            return next;
        }
    }).build());
    Worker worker = testEnvironment.newWorker(TASK_QUEUE);
    worker.registerWorkflowImplementationTypes(SendSignalObjectWorkflowImpl.class, ReceiveSignalObjectWorkflowImpl.class);
    testEnvironment.start();
    WorkflowOptions options = WorkflowOptions.newBuilder().setWorkflowRunTimeout(Duration.ofSeconds(1000)).setTaskQueue(TASK_QUEUE).build();
    WorkflowClient workflowClient = testEnvironment.getWorkflowClient();
    TestWorkflowReturnString workflow = workflowClient.newWorkflowStub(TestWorkflowReturnString.class, options);
    workflow.execute();
    // Wait for reporter
    Thread.sleep(REPORTING_FLUSH_TIME);
    Map<String, String> tags = new LinkedHashMap<String, String>() {

        {
            putAll(MetricsTag.defaultTags(NAMESPACE));
            put(MetricsTag.TASK_QUEUE, TASK_QUEUE);
            put(MetricsTag.WORKFLOW_TYPE, "ReceiveSignalObjectWorkflow");
        }
    };
    reporter.assertCounter(CORRUPTED_SIGNALS_COUNTER, tags, 1);
}
Also used : WorkflowInboundCallsInterceptor(io.temporal.common.interceptors.WorkflowInboundCallsInterceptor) ActivityInboundCallsInterceptor(io.temporal.common.interceptors.ActivityInboundCallsInterceptor) Worker(io.temporal.worker.Worker) WorkflowOptions(io.temporal.client.WorkflowOptions) WorkflowClient(io.temporal.client.WorkflowClient) TestWorkflowReturnString(io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString) TestWorkflowReturnString(io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString) WorkerInterceptor(io.temporal.common.interceptors.WorkerInterceptor) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

TestWorkflowReturnString (io.temporal.workflow.shared.TestWorkflows.TestWorkflowReturnString)3 Test (org.junit.Test)3 WorkflowOptions (io.temporal.client.WorkflowOptions)2 Payloads (io.temporal.api.common.v1.Payloads)1 WorkflowExecution (io.temporal.api.common.v1.WorkflowExecution)1 HistoryEvent (io.temporal.api.history.v1.HistoryEvent)1 WorkflowClient (io.temporal.client.WorkflowClient)1 WorkflowStub (io.temporal.client.WorkflowStub)1 ActivityInboundCallsInterceptor (io.temporal.common.interceptors.ActivityInboundCallsInterceptor)1 WorkerInterceptor (io.temporal.common.interceptors.WorkerInterceptor)1 WorkflowInboundCallsInterceptor (io.temporal.common.interceptors.WorkflowInboundCallsInterceptor)1 Worker (io.temporal.worker.Worker)1 TestSignaledWorkflow (io.temporal.workflow.shared.TestWorkflows.TestSignaledWorkflow)1 LinkedHashMap (java.util.LinkedHashMap)1