use of io.temporal.serviceclient.WorkflowServiceStubs in project sdk-java by temporalio.
the class RegisterTestNamespace method main.
public static void main(String[] args) throws InterruptedException {
if (!useDockerService) {
return;
}
WorkflowServiceStubsOptions.Builder options = WorkflowServiceStubsOptions.newBuilder();
if (serviceAddress != null) {
options.setTarget(serviceAddress);
}
WorkflowServiceStubs service = null;
try {
service = WorkflowServiceStubs.newInstance(options.build());
if (doesNamespaceExist(service)) {
System.out.println("Namespace " + NAMESPACE + " already exists");
} else {
registerNamespace(service);
waitForNamespace(service);
}
System.exit(0);
} finally {
if (service != null) {
service.shutdown();
}
}
System.exit(0);
}
use of io.temporal.serviceclient.WorkflowServiceStubs in project sdk-java by temporalio.
the class PollWorkflowTaskDispatcherTests method aWarningIsLoggedAndWorkflowTaskIsFailedWhenNoHandlerIsRegisteredForTheTaskQueue.
@Test
// TODO: Rewrite as mocking of WorkflowServiceBlockingStub is not possible
@Ignore
public void aWarningIsLoggedAndWorkflowTaskIsFailedWhenNoHandlerIsRegisteredForTheTaskQueue() {
ListAppender<ILoggingEvent> appender = new ListAppender<>();
appender.setContext(context);
appender.start();
logger.addAppender(appender);
AtomicBoolean handled = new AtomicBoolean(false);
Functions.Proc1<PollWorkflowTaskQueueResponse> handler = r -> handled.set(true);
WorkflowServiceGrpc.WorkflowServiceBlockingStub stub = mock(WorkflowServiceGrpc.WorkflowServiceBlockingStub.class);
WorkflowServiceStubs mockService = mock(WorkflowServiceStubs.class);
when(mockService.blockingStub()).thenReturn(stub);
PollWorkflowTaskDispatcher dispatcher = new PollWorkflowTaskDispatcher(mockService, "default", metricsScope);
dispatcher.subscribe("taskqueue1", handler);
PollWorkflowTaskQueueResponse response = CreatePollWorkflowTaskQueueResponse("I Don't Exist TaskQueue");
dispatcher.process(response);
verify(stub, times(1)).respondWorkflowTaskFailed(any());
assertFalse(handled.get());
assertEquals(1, appender.list.size());
ILoggingEvent event = appender.list.get(0);
assertEquals(Level.WARN, event.getLevel());
assertEquals(String.format("No handler is subscribed for the PollWorkflowTaskQueueResponse.WorkflowExecutionTaskQueue %s", "I Don't Exist TaskQueue"), event.getFormattedMessage());
}
use of io.temporal.serviceclient.WorkflowServiceStubs in project sdk-java by temporalio.
the class MetricsTest method testTemporalInvalidRequestMetric.
@Test
public void testTemporalInvalidRequestMetric() throws InterruptedException {
setUp(WorkerFactoryOptions.newBuilder().setWorkerInterceptors(new CorruptedSignalWorkerInterceptor()).build());
try {
WorkflowServiceStubs serviceStubs = testEnvironment.getWorkflowClient().getWorkflowServiceStubs();
serviceStubs.blockingStub().startWorkflowExecution(StartWorkflowExecutionRequest.newBuilder().build());
fail("failure expected");
} catch (StatusRuntimeException e) {
assertEquals(Status.Code.INVALID_ARGUMENT, e.getStatus().getCode());
}
// Wait for reporter
Thread.sleep(REPORTING_FLUSH_TIME);
Map<String, String> tags = new LinkedHashMap<String, String>() {
{
putAll(MetricsTag.defaultTags(MetricsTag.DEFAULT_VALUE));
put(MetricsTag.OPERATION_NAME, "StartWorkflowExecution");
}
};
reporter.assertCounter(TEMPORAL_REQUEST, tags, 1);
tags.put(MetricsTag.STATUS_CODE, "INVALID_ARGUMENT");
reporter.assertCounter(TEMPORAL_REQUEST_FAILURE, tags, 1);
}
use of io.temporal.serviceclient.WorkflowServiceStubs in project sdk-java by temporalio.
the class MetricsTest method testTemporalFailureMetric.
@Test
public void testTemporalFailureMetric() throws InterruptedException {
setUp(WorkerFactoryOptions.newBuilder().setWorkerInterceptors(new CorruptedSignalWorkerInterceptor()).build());
try {
WorkflowServiceStubs serviceStubs = testEnvironment.getWorkflowClient().getWorkflowServiceStubs();
serviceStubs.blockingStub().describeNamespace(DescribeNamespaceRequest.newBuilder().build());
fail("failure expected");
} catch (StatusRuntimeException e) {
assertEquals(Status.Code.UNIMPLEMENTED, e.getStatus().getCode());
}
// Wait for reporter
Thread.sleep(REPORTING_FLUSH_TIME);
Map<String, String> tags = new LinkedHashMap<String, String>() {
{
putAll(MetricsTag.defaultTags(MetricsTag.DEFAULT_VALUE));
put(MetricsTag.OPERATION_NAME, "DescribeNamespace");
}
};
reporter.assertCounter(TEMPORAL_REQUEST, tags, 1);
tags.put(MetricsTag.STATUS_CODE, "UNIMPLEMENTED");
reporter.assertCounter(TEMPORAL_REQUEST_FAILURE, tags, 1);
}
use of io.temporal.serviceclient.WorkflowServiceStubs in project samples-java by temporalio.
the class HelloAsyncLambda method main.
/**
* With our Workflow and Activities defined, we can now start execution. The main method starts
* the worker and then the workflow.
*/
public static void main(String[] args) {
// Get a Workflow service stub.
WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
/*
* Get a Workflow service client which can be used to start, Signal, and Query Workflow Executions.
*/
WorkflowClient client = WorkflowClient.newInstance(service);
/*
* Define the workflow factory. It is used to create workflow workers for a specific task queue.
*/
WorkerFactory factory = WorkerFactory.newInstance(client);
/*
* Define the workflow worker. Workflow workers listen to a defined task queue and process
* workflows and activities.
*/
Worker worker = factory.newWorker(TASK_QUEUE);
/*
* Register our workflow implementation with the worker.
* Workflow implementations must be known to the worker at runtime in
* order to dispatch workflow tasks.
*/
worker.registerWorkflowImplementationTypes(GreetingWorkflowImpl.class);
/**
* Register our Activity Types with the Worker. Since Activities are stateless and thread-safe,
* the Activity Type is a shared instance.
*/
worker.registerActivitiesImplementations(new GreetingActivitiesImpl());
/*
* Start all the workers registered for a specific task queue.
* The started workers then start polling for workflows and activities.
*/
factory.start();
// Define our workflow options
WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setWorkflowId(WORKFLOW_ID).setTaskQueue(TASK_QUEUE).build();
// Create the workflow client stub. It is used to start our workflow execution.
GreetingWorkflow workflow = client.newWorkflowStub(GreetingWorkflow.class, workflowOptions);
/*
* Execute our workflow and wait for it to complete. The call to our getGreeting method is
* synchronous.
*/
String greeting = workflow.getGreeting("World");
// Display workflow execution results
System.out.println(greeting);
System.exit(0);
}
Aggregations