Skip to content

Commit c8f7870

Browse files
committed
Get server tests working with Jakarta
Use quarkus-resteasy-dependencies for now
1 parent 8d64abf commit c8f7870

File tree

4 files changed

+110
-2
lines changed

4 files changed

+110
-2
lines changed

sdk-jakarta/pom.xml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,27 @@
2222
<artifactId>a2a-java-sdk-core</artifactId>
2323
<version>${project.version}</version>
2424
</dependency>
25+
<dependency>
26+
<groupId>${project.groupId}</groupId>
27+
<artifactId>a2a-java-sdk-tests-server-common</artifactId>
28+
<version>${project.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>${project.groupId}</groupId>
32+
<artifactId>a2a-java-sdk-tests-server-common</artifactId>
33+
<type>test-jar</type>
34+
<scope>test</scope>
35+
<version>${project.version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.fasterxml.jackson.core</groupId>
39+
<artifactId>jackson-databind</artifactId>
40+
<scope>provided</scope>
41+
</dependency>
2542
<dependency>
2643
<groupId>jakarta.enterprise</groupId>
2744
<artifactId>jakarta.enterprise.cdi-api</artifactId>
45+
<scope>provided</scope>
2846
</dependency>
2947
<dependency>
3048
<groupId>jakarta.json</groupId>
@@ -36,5 +54,40 @@
3654
<artifactId>jakarta.ws.rs-api</artifactId>
3755
<scope>provided</scope>
3856
</dependency>
57+
<dependency>
58+
<groupId>com.fasterxml.jackson.datatype</groupId>
59+
<artifactId>jackson-datatype-jsr310</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>io.quarkus</groupId>
64+
<artifactId>quarkus-junit5</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>io.quarkus</groupId>
69+
<artifactId>quarkus-resteasy-jackson</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>io.quarkus</groupId>
74+
<artifactId>quarkus-resteasy-client-jackson</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
<dependency>
78+
<groupId>org.jboss.resteasy</groupId>
79+
<artifactId>resteasy-client</artifactId>
80+
<scope>test</scope>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.junit.jupiter</groupId>
84+
<artifactId>junit-jupiter-api</artifactId>
85+
<scope>test</scope>
86+
</dependency>
87+
<dependency>
88+
<groupId>io.rest-assured</groupId>
89+
<artifactId>rest-assured</artifactId>
90+
<scope>test</scope>
91+
</dependency>
3992
</dependencies>
4093
</project>

sdk-jakarta/src/main/java/io/a2a/server/apps/jakarta/A2AServerResource.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.a2a.server.apps.jakarta;
22

3+
import java.util.concurrent.Executor;
4+
import java.util.concurrent.Executors;
35
import java.util.concurrent.Flow;
46

57
import jakarta.enterprise.inject.Instance;
@@ -56,6 +58,12 @@ public class A2AServerResource {
5658
@ExtendedAgentCard
5759
Instance<AgentCard> extendedAgentCard;
5860

61+
// Hook so testing can wait until the async Subscription is subscribed.
62+
private static volatile Runnable streamingIsSubscribedRunnable;
63+
64+
65+
private final Executor executor = Executors.newCachedThreadPool();
66+
5967
/**
6068
* Handles incoming POST requests to the main A2A endpoint. Dispatches the
6169
* request to the appropriate JSON-RPC handler method and returns the response.
@@ -78,7 +86,9 @@ public JSONRPCResponse<?> handleNonStreamingRequests(NonStreamingJSONRPCRequest<
7886
@Consumes(MediaType.APPLICATION_JSON)
7987
@Produces(MediaType.SERVER_SENT_EVENTS)
8088
public void handleStreamingRequests(StreamingJSONRPCRequest<?> request, @Context SseEventSink sseEventSink, @Context Sse sse) {
81-
processStreamingRequest(request, sseEventSink, sse);
89+
System.out.println("=====> Streaming");
90+
executor.execute(() -> processStreamingRequest(request, sseEventSink, sse));
91+
System.out.println("=====> Streaming - done");
8292
}
8393

8494
/**
@@ -156,10 +166,17 @@ private void handleStreamingResponse(Flow.Publisher<? extends JSONRPCResponse<?>
156166
public void onSubscribe(Flow.Subscription subscription) {
157167
this.subscription = subscription;
158168
subscription.request(Long.MAX_VALUE);
169+
System.out.println("SUBSCRIBING!");
170+
// Notify tests that we are subscribed
171+
Runnable runnable = streamingIsSubscribedRunnable;
172+
if (runnable != null) {
173+
runnable.run();
174+
}
159175
}
160176

161177
@Override
162178
public void onNext(JSONRPCResponse<?> item) {
179+
163180
sseEventSink.send(sse.newEventBuilder()
164181
.mediaType(MediaType.APPLICATION_JSON_TYPE)
165182
.data(item)
@@ -183,6 +200,10 @@ private JSONRPCResponse<?> generateErrorResponse(JSONRPCRequest<?> request, JSON
183200
return new JSONRPCErrorResponse(request.getId(), error);
184201
}
185202

203+
static void setStreamingIsSubscribedRunnable(Runnable streamingIsSubscribedRunnable) {
204+
A2AServerResource.streamingIsSubscribedRunnable = streamingIsSubscribedRunnable;
205+
}
206+
186207
@Provider
187208
public class JsonParseExceptionMapper implements ExceptionMapper<JsonParseException> {
188209

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.a2a.server.apps.jakarta;
2+
3+
import jakarta.inject.Inject;
4+
5+
import io.a2a.server.apps.common.AbstractA2AServerTest;
6+
import io.a2a.server.events.InMemoryQueueManager;
7+
import io.a2a.server.tasks.TaskStore;
8+
import io.quarkus.test.junit.QuarkusTest;
9+
import org.junit.jupiter.api.Disabled;
10+
import org.junit.jupiter.api.Test;
11+
12+
@QuarkusTest
13+
public class JakartaA2AServerTest extends AbstractA2AServerTest {
14+
@Inject
15+
TaskStore taskStore;
16+
17+
@Inject
18+
InMemoryQueueManager queueManager;
19+
20+
@Override
21+
protected TaskStore getTaskStore() {
22+
return taskStore;
23+
}
24+
25+
@Override
26+
protected InMemoryQueueManager getQueueManager() {
27+
return queueManager;
28+
}
29+
30+
@Override
31+
protected void setStreamingSubscribedRunnable(Runnable runnable) {
32+
A2AServerResource.setStreamingIsSubscribedRunnable(runnable);
33+
}
34+
}

sdk-quarkus/src/main/java/io/a2a/server/apps/quarkus/A2AServerRoutes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class A2AServerRoutes {
6868
@ExtendedAgentCard
6969
Instance<AgentCard> extendedAgentCard;
7070

71-
// Hook so testing can wait until the MultiSseSupport is subscribes.
71+
// Hook so testing can wait until the MultiSseSupport is subscribed.
7272
private static volatile Runnable streamingMultiSseSupportSubscribedRunnable;
7373

7474
private final Executor executor = Executors.newCachedThreadPool();

0 commit comments

Comments
 (0)