Skip to content

Commit e163a9b

Browse files
authored
test(firestore): Add tests for forceIndex with "primary" (#8036)
Adds tests for `forceIndex` that use the `"primary"` index. There was already a test that validates that `forceIndex` is passed to the backend.
1 parent a5e0041 commit e163a9b

1 file changed

Lines changed: 43 additions & 3 deletions

File tree

  • firebase-firestore/src/androidTest/java/com/google/firebase/firestore

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/PipelineTest.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
import com.google.firebase.firestore.pipeline.AggregateHints;
9999
import com.google.firebase.firestore.pipeline.AggregateOptions;
100100
import com.google.firebase.firestore.pipeline.AggregateStage;
101+
import com.google.firebase.firestore.pipeline.CollectionGroupOptions;
101102
import com.google.firebase.firestore.pipeline.CollectionHints;
102103
import com.google.firebase.firestore.pipeline.CollectionSourceOptions;
103104
import 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

Comments
 (0)