Skip to content

Commit dea60f3

Browse files
committed
Code formatting
1 parent 89197ef commit dea60f3

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

saas-modules/temporal/src/main/java/com/baeldung/temporal/workflows/hello/HelloWorkflow.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
@WorkflowInterface
77
public interface HelloWorkflow {
8-
98
@WorkflowMethod
109
String hello(String person);
11-
1210
}

saas-modules/temporal/src/main/java/com/baeldung/temporal/workflows/hello/HelloWorkflowApplication.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@ public class HelloWorkflowApplication {
1212
private static final String QUEUE_NAME = "say-hello-queue";
1313
private static final Logger log = LoggerFactory.getLogger(HelloWorkflowApplication.class);
1414

15-
1615
public static void main(String[] args) {
1716

1817
log.info("Creating worker...");
19-
WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs();
20-
WorkflowClient client = WorkflowClient.newInstance(service);
18+
var service = WorkflowServiceStubs.newLocalServiceStubs();
19+
var client = WorkflowClient.newInstance(service);
2120
var factory = WorkerFactory.newInstance(client);
22-
Worker worker = factory.newWorker(QUEUE_NAME);
21+
var worker = factory.newWorker(QUEUE_NAME);
2322

2423
log.info("Registering workflows and activities...");
2524
HelloWorkflowRegistrar.newInstance().register(worker);
2625

2726
log.info("Starting worker...");
2827
factory.start();
29-
3028
}
3129
}

saas-modules/temporal/src/main/java/com/baeldung/temporal/workflows/hello/HelloWorkflowImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ public class HelloWorkflowImpl implements HelloWorkflow {
1515
.build()
1616
);
1717

18-
1918
@Override
2019
public String hello(String person) {
2120
return activity.sayHello(person);
2221
}
23-
2422
}

saas-modules/temporal/src/test/java/com/baeldung/temporal/HelloWorkerUnitTest.java

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
import com.baeldung.temporal.workflows.hello.HelloWorkflowRegistrar;
55
import io.temporal.client.WorkflowClient;
66
import io.temporal.client.WorkflowOptions;
7+
import io.temporal.serviceclient.WorkflowServiceStubs;
8+
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
79
import io.temporal.testing.TestWorkflowEnvironment;
810
import io.temporal.worker.Worker;
11+
import io.temporal.workflow.Workflow;
912
import org.junit.jupiter.api.AfterEach;
1013
import org.junit.jupiter.api.BeforeEach;
1114
import org.junit.jupiter.api.Test;
1215
import org.slf4j.Logger;
1316
import org.slf4j.LoggerFactory;
1417

18+
import java.util.Optional;
1519
import java.util.UUID;
1620

1721
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -34,6 +38,17 @@ public void startWorker() {
3438
worker = testEnv.newWorker(QUEUE_NAME);
3539
HelloWorkflowRegistrar.newInstance().register(worker);
3640
client = testEnv.getWorkflowClient();
41+
42+
// var serviceStubs = WorkflowServiceStubs.newServiceStubs(WorkflowServiceStubsOptions
43+
// .newBuilder()
44+
// .setTarget("localhost:7233")
45+
// .setEnableKeepAlive(true)
46+
// .setEnableHttps(false)
47+
// .build());
48+
//
49+
// client = WorkflowClient.newInstance(serviceStubs);
50+
51+
testEnv.start();
3752
}
3853

3954
@AfterEach
@@ -42,10 +57,7 @@ public void stopWorker() {
4257
}
4358

4459
@Test
45-
void givenPerson_whenSayHello_thenSuccess() throws Exception {
46-
47-
// We must register all activities/worklows before starting the test environment
48-
testEnv.start();
60+
void givenPerson_whenSayHelloAsync_thenSuccess() throws Exception {
4961

5062
// Create workflow stub wich allow us to create workflow instances
5163
var wfid = UUID.randomUUID().toString();
@@ -59,12 +71,33 @@ void givenPerson_whenSayHello_thenSuccess() throws Exception {
5971

6072
// Invoke workflow asynchronously.
6173
var execution = WorkflowClient.start(workflow::hello,"Baeldung");
74+
var workflowStub = client.newUntypedWorkflowStub(execution.getWorkflowId());
75+
76+
// Retrieve a CompletableFuture we can use to wait for the result.
77+
var future = workflowStub.getResultAsync(String.class);
78+
log.info("Waiting for workflow to complete...");
79+
var result = future.get();
80+
log.info("Workflow completed with result: {}", result);
81+
assertEquals("Hello, Baeldung", result);
82+
}
83+
84+
@Test
85+
void givenPerson_whenSayHelloSync_thenSuccess() throws Exception {
6286

63-
// Create a blocking workflow using tbe execution's workflow id
64-
var syncWorkflow = client.newWorkflowStub(HelloWorkflow.class,execution.getWorkflowId());
87+
// Create workflow stub wich allow us to create workflow instances
88+
var wfid = UUID.randomUUID().toString();
89+
var workflow = client.newWorkflowStub(
90+
HelloWorkflow.class,
91+
WorkflowOptions.newBuilder()
92+
.setTaskQueue(QUEUE_NAME)
93+
.setWorkflowId(wfid)
94+
.build()
95+
);
6596

97+
// Invoke workflow synchronously.
98+
var result = workflow.hello("Baeldung");
6699

67100
// The sync workflow stub will block until it completes. Notice that the call argumento here is ignored!
68-
assertEquals("Hello, Baeldung", syncWorkflow.hello("ignored"));
101+
assertEquals("Hello, Baeldung", result);
69102
}
70103
}

0 commit comments

Comments
 (0)