@@ -384,6 +384,18 @@ public override IndexMetricsParserTestOutput ExecuteTest(IndexMetricsParserTestI
384
384
385
385
// Make sure ODE and non-ODE is consistent
386
386
Assert . AreEqual ( indexMetricsNonODE , indexMetricsODE ) ;
387
+
388
+ // ----------------------------
389
+ // Test stream API
390
+ // ----------------------------
391
+ // Execute without ODE
392
+ string indexMetricsNonODEStreaming = RunStreamAPITest ( input . Query , enableOptimisticDirectExecution : false ) ;
393
+
394
+ // Execute with ODE
395
+ string indexMetricsODEStreaming = RunStreamAPITest ( input . Query , enableOptimisticDirectExecution : true ) ;
396
+
397
+ // Make sure ODE and non-ODE is consistent
398
+ Assert . AreEqual ( indexMetricsNonODEStreaming , indexMetricsODEStreaming ) ;
387
399
388
400
return new IndexMetricsParserTestOutput ( indexMetricsNonODE ) ;
389
401
}
@@ -403,7 +415,42 @@ private static string RunTest(string query, bool enableOptimisticDirectExecution
403
415
{
404
416
FeedResponse < CosmosElement > page = itemQuery . ReadNextAsync ( ) . Result ;
405
417
Assert . IsTrue ( page . Headers . AllKeys ( ) . Length > 1 ) ;
418
+ if ( roundTripCount > 0 )
419
+ {
420
+ if ( page . IndexMetrics != null )
421
+ {
422
+ Assert . Fail ( "Expected only Index Metrics on first round trip. Current round trip %n" , roundTripCount ) ;
423
+ }
424
+ }
425
+ else
426
+ {
427
+ Assert . IsNotNull ( page . Headers . Get ( HttpConstants . HttpHeaders . IndexUtilization ) , "Expected index utilization headers for query" ) ;
428
+ Assert . IsNotNull ( page . IndexMetrics , "Expected index metrics response for query" ) ;
429
+
430
+ indexMetrics = page . IndexMetrics ;
431
+ }
432
+
433
+ roundTripCount ++ ;
434
+ }
435
+
436
+ return indexMetrics ;
437
+ }
438
+
439
+ private static string RunStreamAPITest ( string query , bool enableOptimisticDirectExecution )
440
+ {
441
+ QueryRequestOptions requestOptions = new QueryRequestOptions ( ) { PopulateIndexMetrics = true , EnableOptimisticDirectExecution = enableOptimisticDirectExecution } ;
406
442
443
+ using FeedIterator itemQuery = testContainer . GetItemQueryStreamIterator (
444
+ queryText : query ,
445
+ requestOptions : requestOptions ) ;
446
+
447
+ // Index Metrics is returned fully on the first page so no need to worry about result set
448
+ int roundTripCount = 0 ;
449
+ string indexMetrics = null ;
450
+ while ( itemQuery . HasMoreResults )
451
+ {
452
+ ResponseMessage page = itemQuery . ReadNextAsync ( ) . Result ;
453
+ Assert . IsTrue ( page . Headers . AllKeys ( ) . Length > 1 ) ;
407
454
if ( roundTripCount > 0 )
408
455
{
409
456
if ( page . IndexMetrics != null )
0 commit comments