9898import com .google .firebase .firestore .pipeline .AggregateHints ;
9999import com .google .firebase .firestore .pipeline .AggregateOptions ;
100100import com .google .firebase .firestore .pipeline .AggregateStage ;
101+ import com .google .firebase .firestore .pipeline .CollectionGroupOptions ;
101102import com .google .firebase .firestore .pipeline .CollectionHints ;
102103import com .google .firebase .firestore .pipeline .CollectionSourceOptions ;
103104import com .google .firebase .firestore .pipeline .Expression ;
@@ -4106,9 +4107,6 @@ public void testOptions() {
41064107 assumeFalse (
41074108 "Certain options are not supported against the emulator yet." , isRunningAgainstEmulator ());
41084109
4109- Pipeline .ExecuteOptions opts =
4110- new Pipeline .ExecuteOptions ().withIndexMode (Pipeline .ExecuteOptions .IndexMode .RECOMMENDED );
4111-
41124110 double [] vector = {1.0 , 2.0 , 3.0 };
41134111
41144112 Pipeline pipeline =
@@ -4131,15 +4129,57 @@ public void testOptions() {
41314129 new AggregateOptions ()
41324130 .withHints (new AggregateHints ().withForceStreamableEnabled ()));
41334131
4132+ // Should throw an error because there is no index named "abcdef".
4133+ // The error validates that the backend did attempt to use the index with the name specified
4134+ // in the forceIndex option.
41344135 RuntimeException exception =
41354136 assertThrows (
41364137 RuntimeException .class ,
41374138 () -> {
41384139 waitFor (pipeline .execute ());
41394140 });
4141+
41404142 assertThat (exception .getMessage ()).contains ("Invalid index" );
41414143 }
41424144
4145+ @ Test
4146+ public void testCollectionForceIndex () {
4147+ assumeFalse (
4148+ "Certain options are not supported against the emulator yet." , isRunningAgainstEmulator ());
4149+
4150+ Task <Pipeline .Snapshot > execute =
4151+ firestore
4152+ .pipeline ()
4153+ .collection (
4154+ randomCol ,
4155+ new CollectionSourceOptions ()
4156+ .withHints (new CollectionHints ().withForceIndex ("primary" )))
4157+ .limit (1 )
4158+ .execute ();
4159+
4160+ List <PipelineResult > results = waitFor (execute ).getResults ();
4161+ assertThat (results ).hasSize (1 );
4162+ }
4163+
4164+ @ Test
4165+ public void testCollectionGroupForceIndex () {
4166+ assumeFalse (
4167+ "Certain options are not supported against the emulator yet." , isRunningAgainstEmulator ());
4168+
4169+ Task <Pipeline .Snapshot > execute =
4170+ firestore
4171+ .pipeline ()
4172+ .collectionGroup (
4173+ randomCol .getId (),
4174+ new CollectionGroupOptions ()
4175+ .withHints (new CollectionHints ().withForceIndex ("primary" )))
4176+ .limit (1 )
4177+ .execute ();
4178+
4179+ List <PipelineResult > results = waitFor (execute ).getResults ();
4180+ assertThat (results ).hasSize (1 );
4181+ }
4182+
41434183 @ Test
41444184 public void disallowDuplicateAliasesInAggregate () {
41454185 IllegalArgumentException exception =
0 commit comments