Skip to content

Commit 9dded5d

Browse files
committed
Renamed EchoHandler to EchoClient
1 parent 66487a9 commit 9dded5d

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

core/src/main/java/io/temporal/samples/nexus/handler/EchoHandler.java renamed to core/src/main/java/io/temporal/samples/nexus/handler/EchoClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
import io.temporal.samples.nexus.service.NexusService;
44

5-
public interface EchoHandler {
5+
public interface EchoClient {
66
NexusService.EchoOutput echo(NexusService.EchoInput input);
77
}

core/src/main/java/io/temporal/samples/nexus/handler/EchoHandlerImpl.java renamed to core/src/main/java/io/temporal/samples/nexus/handler/EchoClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// Note that this is a class, not a Temporal worker. This is to demonstrate that Nexus services can
66
// simply call a class instead of a worker for fast operations that don't need retry handling.
7-
public class EchoHandlerImpl implements EchoHandler {
7+
public class EchoClientImpl implements EchoClient {
88
@Override
99
public NexusService.EchoOutput echo(NexusService.EchoInput input) {
1010
return new NexusService.EchoOutput(input.getMessage());

core/src/main/java/io/temporal/samples/nexus/handler/NexusServiceImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313
// return OperationHandler that correspond to the operations defined in the service interface.
1414
@ServiceImpl(service = NexusService.class)
1515
public class NexusServiceImpl {
16-
private final EchoHandler echoHandler;
16+
private final EchoClient echoClient;
1717

18-
// The injected EchoHandler makes this class unit-testable.
18+
// The injected EchoClient makes this class unit-testable.
1919
// The no-arg constructor provides a default; the second allows tests to inject a mock.
2020
// If you are not using the sync call or do not need to mock a handler, then you will not
2121
// need this constructor pairing.
2222
public NexusServiceImpl() {
23-
this(new EchoHandlerImpl());
23+
this(new EchoClientImpl());
2424
}
2525

26-
public NexusServiceImpl(EchoHandler echoHandler) {
27-
this.echoHandler = echoHandler;
26+
public NexusServiceImpl(EchoClient echoClient) {
27+
this.echoClient = echoClient;
2828
}
2929

3030
// The Echo Nexus Service exemplifies making a synchronous call using OperationHandler.sync.
31-
// In this case, it is calling the EchoHandler class - not a workflow - and simply returning the
31+
// In this case, it is calling the EchoClient class - not a workflow - and simply returning the
3232
// result.
3333
@OperationImpl
3434
public OperationHandler<NexusService.EchoInput, NexusService.EchoOutput> echo() {
@@ -38,7 +38,7 @@ public OperationHandler<NexusService.EchoInput, NexusService.EchoOutput> echo()
3838
// calling
3939
// Nexus.getOperationContext().getWorkflowClient(ctx) to make arbitrary calls such as
4040
// signaling, querying, or listing workflows.
41-
(ctx, details, input) -> echoHandler.echo(input));
41+
(ctx, details, input) -> echoClient.echo(input));
4242
}
4343

4444
@OperationImpl

core/src/test/java/io/temporal/samples/nexus/caller/CallerWorkflowJunit5MockTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.mockito.Mockito.*;
55

6-
import io.temporal.samples.nexus.handler.EchoHandler;
6+
import io.temporal.samples.nexus.handler.EchoClient;
77
import io.temporal.samples.nexus.handler.HelloHandlerWorkflow;
88
import io.temporal.samples.nexus.handler.NexusServiceImpl;
99
import io.temporal.samples.nexus.service.NexusService;
@@ -20,7 +20,7 @@ public class CallerWorkflowJunit5MockTest {
2020

2121
// Sync Nexus operations run inline in the handler thread — there is no backing workflow to
2222
// register a factory for. To mock one, inject a mock dependency into the service implementation.
23-
private static final EchoHandler mockEchoHandler = mock(EchoHandler.class);
23+
private static final EchoClient mockEchoClient = mock(EchoClient.class);
2424

2525
@RegisterExtension
2626
public static final TestWorkflowExtension testWorkflowExtension =
@@ -29,7 +29,7 @@ public class CallerWorkflowJunit5MockTest {
2929
// the TestWorkflowExtension will, by default, automatically create a Nexus service
3030
// endpoint and workflows registered as part of the TestWorkflowExtension will
3131
// automatically inherit the endpoint if none is set.
32-
.setNexusServiceImplementation(new NexusServiceImpl(mockEchoHandler))
32+
.setNexusServiceImplementation(new NexusServiceImpl(mockEchoClient))
3333
// The Echo Nexus handler service just makes a call to a class, so no extra setup is
3434
// needed. But the Hello Nexus service needs a worker for both the caller and handler
3535
// in order to run, and the Echo Nexus caller service needs a worker.
@@ -66,8 +66,8 @@ public void testHelloWorkflow(
6666
public void testEchoWorkflow(
6767
TestWorkflowEnvironment testEnv, Worker worker, EchoCallerWorkflow workflow) {
6868
// Sync Nexus operations run inline in the handler thread — there is no backing workflow to
69-
// register a factory for. Instead, stub the injected EchoHandler dependency directly.
70-
when(mockEchoHandler.echo(any())).thenReturn(new NexusService.EchoOutput("mocked echo"));
69+
// register a factory for. Instead, stub the injected EchoClient dependency directly.
70+
when(mockEchoClient.echo(any())).thenReturn(new NexusService.EchoOutput("mocked echo"));
7171
testEnv.start();
7272

7373
// Execute a workflow waiting for it to complete.

core/src/test/java/io/temporal/samples/nexus/caller/CallerWorkflowMockTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import static org.mockito.Mockito.when;
77

88
import io.temporal.client.WorkflowOptions;
9-
import io.temporal.samples.nexus.handler.EchoHandler;
9+
import io.temporal.samples.nexus.handler.EchoClient;
1010
import io.temporal.samples.nexus.handler.HelloHandlerWorkflow;
1111
import io.temporal.samples.nexus.handler.NexusServiceImpl;
1212
import io.temporal.samples.nexus.service.NexusService;
@@ -19,9 +19,9 @@
1919

2020
public class CallerWorkflowMockTest {
2121

22-
// Inject a mock EchoHandler so sync Nexus operations can be stubbed per test.
22+
// Inject a mock EchoClient so sync Nexus operations can be stubbed per test.
2323
// JUnit 4 creates a new test class instance per test method, so this mock is fresh each time.
24-
private final EchoHandler mockEchoHandler = mock(EchoHandler.class);
24+
private final EchoClient mockEchoClient = mock(EchoClient.class);
2525

2626
@Rule
2727
public TestWorkflowRule testWorkflowRule =
@@ -30,7 +30,7 @@ public class CallerWorkflowMockTest {
3030
// the TestWorkflowRule will, by default, automatically create a Nexus service endpoint
3131
// and workflows registered as part of the TestWorkflowRule
3232
// will automatically inherit the endpoint if none is set.
33-
.setNexusServiceImplementation(new NexusServiceImpl(mockEchoHandler))
33+
.setNexusServiceImplementation(new NexusServiceImpl(mockEchoClient))
3434
// The Echo Nexus handler service just makes a call to a class, so no extra setup is
3535
// needed. But the Hello Nexus service needs a worker for both the caller and handler
3636
// in order to run.
@@ -73,8 +73,8 @@ public void testHelloWorkflow() {
7373
@Test
7474
public void testEchoWorkflow() {
7575
// Sync Nexus operations run inline in the handler thread — there is no backing workflow to
76-
// register a factory for. Instead, stub the injected EchoHandler dependency directly.
77-
when(mockEchoHandler.echo(any())).thenReturn(new NexusService.EchoOutput("mocked echo"));
76+
// register a factory for. Instead, stub the injected EchoCient dependency directly.
77+
when(mockEchoClient.echo(any())).thenReturn(new NexusService.EchoOutput("mocked echo"));
7878
testWorkflowRule.getTestEnvironment().start();
7979

8080
EchoCallerWorkflow workflow =

0 commit comments

Comments
 (0)