1818import io .opentelemetry .context .Scope ;
1919import io .opentelemetry .sdk .testing .exporter .InMemorySpanExporter ;
2020import io .opentelemetry .sdk .trace .data .SpanData ;
21- import io .quarkus .vertx .web .Body ;
22- import io .quarkus .vertx .web .Param ;
23- import io .quarkus .vertx .web .Route ;
21+ import io .vertx .ext .web .Router ;
2422import io .vertx .ext .web .RoutingContext ;
23+ import io .vertx .ext .web .handler .BodyHandler ;
2524import jakarta .enterprise .context .ApplicationScoped ;
25+ import jakarta .enterprise .event .Observes ;
2626import jakarta .enterprise .inject .Produces ;
2727import jakarta .inject .Inject ;
2828import jakarta .inject .Singleton ;
@@ -48,8 +48,47 @@ public class A2ATestRoutes {
4848 @ Inject
4949 Tracer tracer ;
5050
51- @ Route (path = "/test/task" , methods = {Route .HttpMethod .POST }, consumes = {APPLICATION_JSON }, type = Route .HandlerType .BLOCKING )
52- public void saveTask (@ Body String body , RoutingContext rc ) {
51+ void setupRoutes (@ Observes Router router ) {
52+ router .post ("/test/task" )
53+ .consumes (APPLICATION_JSON )
54+ .blockingHandler (ctx -> saveTask (ctx .body ().asString (), ctx ));
55+
56+ router .get ("/test/task/:taskId" )
57+ .produces (APPLICATION_JSON )
58+ .blockingHandler (ctx -> getTask (ctx .pathParam ("taskId" ), ctx ));
59+
60+ router .delete ("/test/task/:taskId" )
61+ .blockingHandler (ctx -> deleteTask (ctx .pathParam ("taskId" ), ctx ));
62+
63+ router .post ("/test/queue/ensure/:taskId" )
64+ .handler (ctx -> ensureTaskQueue (ctx .pathParam ("taskId" ), ctx ));
65+
66+ router .post ("/test/queue/enqueueTaskStatusUpdateEvent/:taskId" )
67+ .handler (BodyHandler .create ())
68+ .handler (ctx -> enqueueTaskStatusUpdateEvent (ctx .pathParam ("taskId" ), ctx .body ().asString (), ctx ));
69+
70+ router .post ("/test/queue/enqueueTaskArtifactUpdateEvent/:taskId" )
71+ .handler (BodyHandler .create ())
72+ .handler (ctx -> enqueueTaskArtifactUpdateEvent (ctx .pathParam ("taskId" ), ctx .body ().asString (), ctx ));
73+
74+ router .get ("/test/queue/childCount/:taskId" )
75+ .produces (TEXT_PLAIN )
76+ .handler (ctx -> getChildQueueCount (ctx .pathParam ("taskId" ), ctx ));
77+
78+ router .get ("/hello" )
79+ .produces (TEXT_PLAIN )
80+ .handler (ctx -> hello (ctx ));
81+
82+ router .get ("/export" )
83+ .produces (APPLICATION_JSON )
84+ .handler (ctx -> exportSpans (ctx ));
85+
86+ router .get ("/reset" )
87+ .produces (TEXT_PLAIN )
88+ .handler (ctx -> reset (ctx ));
89+ }
90+
91+ public void saveTask (String body , RoutingContext rc ) {
5392 try {
5493 Task task = JsonUtil .fromJson (body , Task .class );
5594 testUtilsBean .saveTask (task );
@@ -61,8 +100,7 @@ public void saveTask(@Body String body, RoutingContext rc) {
61100 }
62101 }
63102
64- @ Route (path = "/test/task/:taskId" , methods = {Route .HttpMethod .GET }, produces = {APPLICATION_JSON }, type = Route .HandlerType .BLOCKING )
65- public void getTask (@ Param String taskId , RoutingContext rc ) {
103+ public void getTask (String taskId , RoutingContext rc ) {
66104 try {
67105 Task task = testUtilsBean .getTask (taskId );
68106 if (task == null ) {
@@ -81,8 +119,7 @@ public void getTask(@Param String taskId, RoutingContext rc) {
81119 }
82120 }
83121
84- @ Route (path = "/test/task/:taskId" , methods = {Route .HttpMethod .DELETE }, type = Route .HandlerType .BLOCKING )
85- public void deleteTask (@ Param String taskId , RoutingContext rc ) {
122+ public void deleteTask (String taskId , RoutingContext rc ) {
86123 try {
87124 Task task = testUtilsBean .getTask (taskId );
88125 if (task == null ) {
@@ -100,8 +137,7 @@ public void deleteTask(@Param String taskId, RoutingContext rc) {
100137 }
101138 }
102139
103- @ Route (path = "/test/queue/ensure/:taskId" , methods = {Route .HttpMethod .POST })
104- public void ensureTaskQueue (@ Param String taskId , RoutingContext rc ) {
140+ public void ensureTaskQueue (String taskId , RoutingContext rc ) {
105141 try {
106142 testUtilsBean .ensureQueue (taskId );
107143 rc .response ()
@@ -112,8 +148,7 @@ public void ensureTaskQueue(@Param String taskId, RoutingContext rc) {
112148 }
113149 }
114150
115- @ Route (path = "/test/queue/enqueueTaskStatusUpdateEvent/:taskId" , methods = {Route .HttpMethod .POST })
116- public void enqueueTaskStatusUpdateEvent (@ Param String taskId , @ Body String body , RoutingContext rc ) {
151+ public void enqueueTaskStatusUpdateEvent (String taskId , String body , RoutingContext rc ) {
117152 try {
118153 TaskStatusUpdateEvent event = JsonUtil .fromJson (body , TaskStatusUpdateEvent .class );
119154 testUtilsBean .enqueueEvent (taskId , event );
@@ -125,8 +160,7 @@ public void enqueueTaskStatusUpdateEvent(@Param String taskId, @Body String body
125160 }
126161 }
127162
128- @ Route (path = "/test/queue/enqueueTaskArtifactUpdateEvent/:taskId" , methods = {Route .HttpMethod .POST })
129- public void enqueueTaskArtifactUpdateEvent (@ Param String taskId , @ Body String body , RoutingContext rc ) {
163+ public void enqueueTaskArtifactUpdateEvent (String taskId , String body , RoutingContext rc ) {
130164 try {
131165 TaskArtifactUpdateEvent event = JsonUtil .fromJson (body , TaskArtifactUpdateEvent .class );
132166 testUtilsBean .enqueueEvent (taskId , event );
@@ -138,15 +172,13 @@ public void enqueueTaskArtifactUpdateEvent(@Param String taskId, @Body String bo
138172 }
139173 }
140174
141- @ Route (path = "/test/queue/childCount/:taskId" , methods = {Route .HttpMethod .GET }, produces = {TEXT_PLAIN })
142- public void getChildQueueCount (@ Param String taskId , RoutingContext rc ) {
175+ public void getChildQueueCount (String taskId , RoutingContext rc ) {
143176 int count = testUtilsBean .getChildQueueCount (taskId );
144177 rc .response ()
145178 .setStatusCode (200 )
146179 .end (String .valueOf (count ));
147180 }
148181
149- @ Route (path = "/hello" , methods = {Route .HttpMethod .GET }, produces = {TEXT_PLAIN })
150182 public void hello (RoutingContext rc ) {
151183 Span span = tracer .spanBuilder ("hello" ).startSpan ();
152184 try (Scope scope = span .makeCurrent ()) {
@@ -159,8 +191,7 @@ public void hello(RoutingContext rc) {
159191 }
160192 }
161193
162- @ Route (path = "/export" , methods = {Route .HttpMethod .GET }, produces = {APPLICATION_JSON })
163- public void exportSpans (@ Param String taskId , RoutingContext rc ) {
194+ public void exportSpans (RoutingContext rc ) {
164195 List <SpanData > spans = inMemorySpanExporter .getFinishedSpanItems ()
165196 .stream ()
166197 .filter (sd -> !sd .getName ().contains ("export" ) && !sd .getName ().contains ("reset" ))
@@ -202,8 +233,7 @@ private JsonElement serialize(List<SpanData> spanDatas) {
202233 return spans ;
203234 }
204235
205- @ Route (path = "/reset" , methods = {Route .HttpMethod .GET }, produces = {TEXT_PLAIN })
206- public void reset (@ Param String taskId , RoutingContext rc ) {
236+ public void reset (RoutingContext rc ) {
207237 inMemorySpanExporter .reset ();
208238 rc .response ().setStatusCode (200 ).end ();
209239 }
0 commit comments