@@ -482,52 +482,60 @@ public void testShardTargetSetsDataStreamName() {
482
482
// Create a SearchHit
483
483
SearchHit hit = new SearchHit (1 );
484
484
485
- // Create a backing index name following the pattern: .ds-<data-stream>-<yyyy.MM.dd>-<generation>
486
- String backingIndexName = ".ds-my-service-logs-2024.02.05-000001" ;
487
- String nodeId = "node1" ;
488
- int shardId = 0 ;
489
- String clusterAlias = null ;
490
-
491
- // Create SearchShardTarget with the backing index name
492
- SearchShardTarget target = new SearchShardTarget (
493
- nodeId ,
494
- new ShardId (new Index (backingIndexName , IndexMetadata .INDEX_UUID_NA_VALUE ), shardId ),
495
- clusterAlias
496
- );
497
-
498
- // Set the shard target
499
- hit .shard (target );
500
-
501
- // Verify the data-stream field is set correctly
502
- assertEquals ("my-service-logs" , hit .getDataStream ());
503
- assertEquals (backingIndexName , hit .getIndex ());
504
- assertNull (hit .getClusterAlias ());
485
+ try {
486
+ // Create a backing index name following the pattern: .ds-<data-stream>-<yyyy.MM.dd>-<generation>
487
+ String backingIndexName = ".ds-my-service-logs-2024.02.05-000001" ;
488
+ String nodeId = "node1" ;
489
+ int shardId = 0 ;
490
+ String clusterAlias = null ;
491
+
492
+ // Create SearchShardTarget with the backing index name
493
+ SearchShardTarget target = new SearchShardTarget (
494
+ nodeId ,
495
+ new ShardId (new Index (backingIndexName , IndexMetadata .INDEX_UUID_NA_VALUE ), shardId ),
496
+ clusterAlias
497
+ );
498
+
499
+ // Set the shard target
500
+ hit .shard (target );
501
+
502
+ // Verify the data-stream field is set correctly
503
+ assertEquals ("my-service-logs" , hit .getDataStream ());
504
+ assertEquals (backingIndexName , hit .getIndex ());
505
+ assertNull (hit .getClusterAlias ());
506
+ } finally {
507
+ hit .decRef ();
508
+ }
505
509
}
506
510
507
511
public void testShardTargetWithNonDataStreamIndex () {
508
512
// Create a SearchHit
509
513
SearchHit hit = new SearchHit (1 );
510
514
511
- // Create a regular index name (not a backing index)
512
- String regularIndexName = "regular-index" ;
513
- String nodeId = "node1" ;
514
- int shardId = 0 ;
515
- String clusterAlias = null ;
516
-
517
- // Create SearchShardTarget with a non-data-stream-backed index name
518
- SearchShardTarget target = new SearchShardTarget (
519
- nodeId ,
520
- new ShardId (new Index (regularIndexName , IndexMetadata .INDEX_UUID_NA_VALUE ), shardId ),
521
- clusterAlias
522
- );
523
-
524
- // Set the shard target
525
- hit .shard (target );
526
-
527
- // Verify the data-stream field is null for non-backing indices
528
- assertNull (hit .getDataStream ());
529
- assertEquals (regularIndexName , hit .getIndex ());
530
- assertNull (hit .getClusterAlias ());
515
+ try {
516
+ // Create a regular index name (not a backing index)
517
+ String regularIndexName = "regular-index" ;
518
+ String nodeId = "node1" ;
519
+ int shardId = 0 ;
520
+ String clusterAlias = null ;
521
+
522
+ // Create SearchShardTarget with a non-data-stream-backed index name
523
+ SearchShardTarget target = new SearchShardTarget (
524
+ nodeId ,
525
+ new ShardId (new Index (regularIndexName , IndexMetadata .INDEX_UUID_NA_VALUE ), shardId ),
526
+ clusterAlias
527
+ );
528
+
529
+ // Set the shard target
530
+ hit .shard (target );
531
+
532
+ // Verify the data-stream field is null for non-backing indices
533
+ assertNull (hit .getDataStream ());
534
+ assertEquals (regularIndexName , hit .getIndex ());
535
+ assertNull (hit .getClusterAlias ());
536
+ } finally {
537
+ hit .decRef ();
538
+ }
531
539
}
532
540
533
541
}
0 commit comments