@@ -392,4 +392,51 @@ public void testTraceWithNoOpState() throws Exception {
392
392
assertEquals (status .getSearchStorage ().getWriteStatus (), TraceWriteStatus .NO_OP );
393
393
assertTrue (status .isSuccess ());
394
394
}
395
+
396
+ @ Test
397
+ public void testTraceHistoricStateSearchPropagation () throws Exception {
398
+ // This test verifies that when primary storage has HISTORIC_STATE,
399
+ // the search storage is also set to HISTORIC_STATE based on this line:
400
+ // finalResponse.put(aspectName, TraceStorageStatus.ok(TraceWriteStatus.HISTORIC_STATE));
401
+
402
+ // Arrange - create request with one URN and one aspect
403
+ Map <Urn , List <String >> aspectNames =
404
+ Collections .singletonMap (TEST_URN , Collections .singletonList (ASPECT_NAME ));
405
+
406
+ // Create a primary storage response with HISTORIC_STATE
407
+ Map <String , TraceStorageStatus > primaryStatus = new LinkedHashMap <>();
408
+ primaryStatus .put (ASPECT_NAME , TraceStorageStatus .ok (TraceWriteStatus .HISTORIC_STATE ));
409
+
410
+ // Mock entityService to return empty to skip that branch
411
+ when (entityService .getEntitiesV2 (any (), anyString (), anySet (), anySet (), anyBoolean ()))
412
+ .thenReturn (Collections .emptyMap ());
413
+
414
+ // Mock mcpTraceReader to return our primary status with HISTORIC_STATE
415
+ when (mcpTraceReader .tracePendingStatuses (any (), eq (TEST_TRACE_ID ), any (), anyBoolean ()))
416
+ .thenReturn (Collections .singletonMap (TEST_URN , primaryStatus ));
417
+
418
+ // Mock systemMetadataService to return empty list to ensure
419
+ // we don't get a pre-existing search status
420
+ when (systemMetadataService .findAspectsByUrn (eq (TEST_URN ), anyList (), eq (true )))
421
+ .thenReturn (Collections .emptyList ());
422
+
423
+ // Act
424
+ Map <Urn , Map <String , TraceStatus >> result =
425
+ traceService .trace (operationContext , TEST_TRACE_ID , aspectNames , false , false );
426
+
427
+ // Assert
428
+ assertNotNull (result );
429
+ assertTrue (result .containsKey (TEST_URN ));
430
+ Map <String , TraceStatus > urnStatus = result .get (TEST_URN );
431
+ assertTrue (urnStatus .containsKey (ASPECT_NAME ));
432
+
433
+ // The key assertion - if primary is HISTORIC_STATE, search should also be HISTORIC_STATE
434
+ TraceStatus status = urnStatus .get (ASPECT_NAME );
435
+ assertEquals (status .getPrimaryStorage ().getWriteStatus (), TraceWriteStatus .HISTORIC_STATE );
436
+ assertEquals (
437
+ status .getSearchStorage ().getWriteStatus (),
438
+ TraceWriteStatus .HISTORIC_STATE ,
439
+ "When primary storage is HISTORIC_STATE, search storage should also be HISTORIC_STATE" );
440
+ assertTrue (status .isSuccess ());
441
+ }
395
442
}
0 commit comments