|
22 | 22 | import static com.google.common.truth.Truth.assertThat;
|
23 | 23 | import static java.util.Collections.singletonMap;
|
24 | 24 | import static org.junit.Assert.assertThrows;
|
| 25 | +import static org.junit.Assume.assumeFalse; |
25 | 26 | import static org.junit.Assume.assumeTrue;
|
26 | 27 |
|
27 | 28 | import com.google.api.core.ApiFuture;
|
@@ -369,6 +370,29 @@ public void aggregateQueryInATransactionShouldRespectReadTime() throws Exception
|
369 | 370 | assertThat(transactionCount).isEqualTo(5);
|
370 | 371 | }
|
371 | 372 |
|
| 373 | + @Test |
| 374 | + public void countQueryShouldFailWithMessageWithConsoleLinkIfMissingIndex() { |
| 375 | + assumeFalse( |
| 376 | + "Skip this test when running against the Firestore emulator because the Firestore emulator " |
| 377 | + + "does not use indexes and never fails with a 'missing index' error", |
| 378 | + isRunningAgainstFirestoreEmulator(firestore)); |
| 379 | + |
| 380 | + CollectionReference collection = createEmptyCollection(); |
| 381 | + Query compositeIndexQuery = collection.whereEqualTo("field1", 42).whereLessThan("field2", 99); |
| 382 | + AggregateQuery compositeIndexCountQuery = compositeIndexQuery.count(); |
| 383 | + ApiFuture<AggregateQuerySnapshot> future = compositeIndexCountQuery.get(); |
| 384 | + |
| 385 | + ExecutionException executionException = assertThrows(ExecutionException.class, future::get); |
| 386 | + |
| 387 | + Throwable throwable = executionException.getCause(); |
| 388 | + assertThat(throwable).hasMessageThat().ignoringCase().contains("index"); |
| 389 | + // TODO(b/316359394) Remove this check for the default databases once cl/582465034 is rolled out |
| 390 | + // to production. |
| 391 | + if (collection.getFirestore().getOptions().getDatabaseId().equals("(default)")) { |
| 392 | + assertThat(throwable).hasMessageThat().contains("https://console.firebase.google.com"); |
| 393 | + } |
| 394 | + } |
| 395 | + |
372 | 396 | private CollectionReference createEmptyCollection() {
|
373 | 397 | String collectionPath = "java-" + testName.getMethodName() + "-" + autoId();
|
374 | 398 | return firestore.collection(collectionPath);
|
|
0 commit comments