@@ -53,6 +53,7 @@ public class ZipkinServiceTest {
53
53
@ Mock private AstraQueryServiceBase searcher ;
54
54
private ZipkinService zipkinService ;
55
55
private AstraSearch .SearchResult mockSearchResult ;
56
+ private AstraSearch .SearchResult mockEmptySearchResult ;
56
57
private BlobStore mockBlobStore ;
57
58
58
59
private static final int defaultMaxSpans = 2000 ;
@@ -91,6 +92,14 @@ public void setup() throws IOException {
91
92
AstraSearch .SearchResult .Builder builder = AstraSearch .SearchResult .newBuilder ();
92
93
JsonFormat .parser ().merge (jsonString , builder );
93
94
mockSearchResult = builder .build ();
95
+
96
+ // Build mockEmptySearchResult
97
+ objectMapper = new ObjectMapper ();
98
+ jsonNode = objectMapper .readTree (Resources .getResource ("zipkinApi/empty_search_result.json" ));
99
+ jsonString = objectMapper .writeValueAsString (jsonNode );
100
+ builder = AstraSearch .SearchResult .newBuilder ();
101
+ JsonFormat .parser ().merge (jsonString , builder );
102
+ mockEmptySearchResult = builder .build ();
94
103
}
95
104
96
105
@ Test
@@ -232,7 +241,8 @@ public void testGetTraceByTraceId_respectUserRequest_upload_after_search() throw
232
241
}
233
242
234
243
@ Test
235
- public void testGetTraceByTraceId_respectUserRequest_skip_search () throws Exception {
244
+ public void testGetTraceByTraceId_respectUserRequest_no_upload_after_search_empty_search_result ()
245
+ throws Exception {
236
246
try (MockedStatic <Tracing > mockedTracing = mockStatic (Tracing .class )) {
237
247
// Mocking Tracing and Span
238
248
Tracer mockTracer = mock (Tracer .class );
@@ -243,6 +253,51 @@ public void testGetTraceByTraceId_respectUserRequest_skip_search() throws Except
243
253
244
254
String traceId = "test_trace_4" ;
245
255
String traceFilePath = String .format ("%s/%s/traceData.json.gz" , TRACE_CACHE_PREFIX , traceId );
256
+ when (searcher .doSearch (any ())).thenReturn (mockEmptySearchResult );
257
+
258
+ boolean userRequest = true ;
259
+
260
+ HttpResponse response =
261
+ zipkinService .getTraceByTraceId (
262
+ traceId ,
263
+ Optional .empty (),
264
+ Optional .empty (),
265
+ Optional .empty (),
266
+ Optional .of (userRequest ),
267
+ Optional .empty ());
268
+
269
+ verify (searcher )
270
+ .doSearch (
271
+ Mockito .argThat (
272
+ request -> request .getQuery ().contains ("\" trace_id\" :\" " + traceId + "\" " )));
273
+
274
+ verify (mockBlobStore , never ()).uploadData (anyString (), anyString (), eq (true ));
275
+ verify (mockBlobStore , never ()).copyFile (anyString (), eq (traceFilePath ));
276
+ verify (mockBlobStore , never ()).delete (anyString ());
277
+
278
+ assertNotNull (response , "Response should not be null" );
279
+ response
280
+ .aggregate ()
281
+ .thenAccept (
282
+ aggregatedResponse -> {
283
+ assertEquals (HttpStatus .OK , aggregatedResponse .status ());
284
+ assertEquals (mockSearchResult .toString (), aggregatedResponse .contentUtf8 ());
285
+ });
286
+ }
287
+ }
288
+
289
+ @ Test
290
+ public void testGetTraceByTraceId_respectUserRequest_skip_search () throws Exception {
291
+ try (MockedStatic <Tracing > mockedTracing = mockStatic (Tracing .class )) {
292
+ // Mocking Tracing and Span
293
+ Tracer mockTracer = mock (Tracer .class );
294
+ Span mockSpan = mock (Span .class );
295
+
296
+ mockedTracing .when (Tracing ::currentTracer ).thenReturn (mockTracer );
297
+ when (mockTracer .currentSpan ()).thenReturn (mockSpan );
298
+
299
+ String traceId = "test_trace_5" ;
300
+ String traceFilePath = String .format ("%s/%s/traceData.json.gz" , TRACE_CACHE_PREFIX , traceId );
246
301
247
302
Path filePath = Paths .get (Resources .getResource ("zipkinApi/traceData.json" ).toURI ());
248
303
@@ -286,7 +341,7 @@ public void testGetTraceByTraceId_respectUserRequest_respectDataFreshness_perfor
286
341
mockedTracing .when (Tracing ::currentTracer ).thenReturn (mockTracer );
287
342
when (mockTracer .currentSpan ()).thenReturn (mockSpan );
288
343
289
- String traceId = "test_trace_5 " ;
344
+ String traceId = "test_trace_6 " ;
290
345
String traceFilePath = String .format ("%s/%s/traceData.json.gz" , TRACE_CACHE_PREFIX , traceId );
291
346
292
347
boolean userRequest = true ;
@@ -344,7 +399,7 @@ public void testGetTraceByTraceId_respectUserRequest_respectDataFreshness_perfor
344
399
mockedTracing .when (Tracing ::currentTracer ).thenReturn (mockTracer );
345
400
when (mockTracer .currentSpan ()).thenReturn (mockSpan );
346
401
347
- String traceId = "test_trace_6 " ;
402
+ String traceId = "test_trace_7 " ;
348
403
String traceFilePath = String .format ("%s/%s/traceData.json.gz" , TRACE_CACHE_PREFIX , traceId );
349
404
boolean userRequest = true ;
350
405
long dataFreshnessInSeconds = 100 ;
0 commit comments