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