Skip to content

Commit 4caea60

Browse files
committed
build: unit tests for jsonrpc
1 parent e8b6fba commit 4caea60

13 files changed

Lines changed: 1268 additions & 10 deletions

File tree

modules/jooby-jsonrpc/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,20 @@
2525
<version>${jooby.version}</version>
2626
<optional>true</optional>
2727
</dependency>
28+
<dependency>
29+
<groupId>org.junit.jupiter</groupId>
30+
<artifactId>junit-jupiter-api</artifactId>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.mockito</groupId>
35+
<artifactId>mockito-core</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.mockito</groupId>
40+
<artifactId>mockito-junit-jupiter</artifactId>
41+
<scope>test</scope>
42+
</dependency>
2843
</dependencies>
2944
</project>

modules/jooby-jsonrpc/src/main/java/io/jooby/jsonrpc/JsonRpcErrorCode.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
package io.jooby.jsonrpc;
77

8+
import java.util.Objects;
9+
810
import io.jooby.StatusCode;
911

1012
/**
@@ -132,7 +134,7 @@ public boolean isProtocol() {
132134
*/
133135
public static JsonRpcErrorCode of(StatusCode status) {
134136
for (var errorCode : values()) {
135-
if (!errorCode.protocol && errorCode.statusCode.value() == status.value()) {
137+
if (!errorCode.protocol && Objects.equals(errorCode.statusCode, status)) {
136138
return errorCode;
137139
}
138140
}

modules/jooby-jsonrpc/src/main/java/io/jooby/jsonrpc/JsonRpcModule.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
* {
4343
* install(new Jackson3Module());
4444
* install(new JsonRpcJackson3Module());
45-
* * install(new JsonRpcModule(new MyServiceRpc_())
45+
* install(new JsonRpcModule(new MyServiceRpc_())
4646
* .invoker(new MyJsonRpcMiddleware()));
4747
* }
4848
* }</pre>
4949
*
50-
* @author Edgar Espina
50+
* @author edgar
5151
* @since 4.0.17
5252
*/
5353
public class JsonRpcModule implements Extension {
@@ -83,12 +83,14 @@ public JsonRpcModule(JsonRpcService service, JsonRpcService... services) {
8383
/**
8484
* Adds a {@link JsonRpcInvoker} middleware to the execution pipeline.
8585
*
86-
* <p>Middlewares are composed together to form a {@link JsonRpcChain}. When multiple invokers are
87-
* registered, they wrap around each other, meaning the first added invoker will execute first.
86+
* <p>Execution order follows a First-In-First-Out (FIFO) pipeline. When multiple invokers are
87+
* registered, they wrap around each other in the order they were added. <br>
88+
* For example: {@code .invoker(A).invoker(B)} generates the pipeline {@code A -> B}.
8889
*
8990
* <p><strong>Tracing Priority:</strong> If the provided invoker is an instance of {@link
9091
* OtelJsonRcpTracing}, it is automatically promoted to the absolute head of the pipeline. This
91-
* guarantees that OpenTelemetry spans encompass all other middlewares and the final execution.
92+
* guarantees that OpenTelemetry spans encompass all other middlewares and the final execution
93+
* regardless of the order it was added.
9294
*
9395
* @param invoker The middleware interceptor to add to the pipeline.
9496
* @return This module instance for fluent configuration chaining.
@@ -99,7 +101,8 @@ public JsonRpcModule invoker(JsonRpcInvoker invoker) {
99101
this.head = otel;
100102
} else {
101103
if (this.invoker != null) {
102-
this.invoker = invoker.then(this.invoker);
104+
// Appends to the chain to ensure First-In-First-Out (A -> B)
105+
this.invoker = this.invoker.then(invoker);
103106
} else {
104107
this.invoker = invoker;
105108
}

modules/jooby-jsonrpc/src/main/java/io/jooby/jsonrpc/instrumentation/OtelJsonRcpTracing.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
* @since 4.5.0
4646
*/
4747
public class OtelJsonRcpTracing implements JsonRpcInvoker {
48-
private final OpenTelemetry otel;
49-
5048
private final Tracer tracer;
5149

5250
private SneakyThrows.@Nullable Consumer3<Context, JsonRpcRequest, Span> onStart;
@@ -59,7 +57,6 @@ public class OtelJsonRcpTracing implements JsonRpcInvoker {
5957
* @param otel The OpenTelemetry instance used to obtain the tracer.
6058
*/
6159
public OtelJsonRcpTracing(OpenTelemetry otel) {
62-
this.otel = otel;
6360
tracer = otel.getTracer("io.jooby.jsonrpc");
6461
}
6562

0 commit comments

Comments
 (0)