@@ -373,6 +373,7 @@ public void testIndexAutoCreationWorks() {
373
373
int targetId = allocateQuery (query );
374
374
375
375
enableIndexAutoCreation ();
376
+ setMinCollectionSizeToAutoCreateIndex (0 );
376
377
377
378
applyRemoteEvent (addedRemoteEvent (doc ("coll/a" , 10 , map ("matches" , true )), targetId ));
378
379
applyRemoteEvent (addedRemoteEvent (doc ("coll/b" , 10 , map ("matches" , false )), targetId ));
@@ -396,12 +397,40 @@ public void testIndexAutoCreationWorks() {
396
397
assertQueryReturned ("coll/a" , "coll/e" , "coll/f" );
397
398
}
398
399
400
+ @ Test
401
+ public void testIndexAutoCreationDoesNotWorkWhenCollectionSizeIsTooSmall () {
402
+ Query query = query ("coll" ).filter (filter ("matches" , "==" , true ));
403
+ int targetId = allocateQuery (query );
404
+
405
+ enableIndexAutoCreation ();
406
+
407
+ applyRemoteEvent (addedRemoteEvent (doc ("coll/a" , 10 , map ("matches" , true )), targetId ));
408
+ applyRemoteEvent (addedRemoteEvent (doc ("coll/b" , 10 , map ("matches" , false )), targetId ));
409
+ applyRemoteEvent (addedRemoteEvent (doc ("coll/c" , 10 , map ("matches" , false )), targetId ));
410
+ applyRemoteEvent (addedRemoteEvent (doc ("coll/d" , 10 , map ("matches" , false )), targetId ));
411
+ applyRemoteEvent (addedRemoteEvent (doc ("coll/e" , 10 , map ("matches" , true )), targetId ));
412
+
413
+ // SDK will not create indexes since collection size is too small.
414
+ executeQuery (query );
415
+ assertRemoteDocumentsRead (/* byKey= */ 0 , /* byCollection= */ 2 );
416
+ assertQueryReturned ("coll/a" , "coll/e" );
417
+
418
+ backfillIndexes ();
419
+
420
+ applyRemoteEvent (addedRemoteEvent (doc ("coll/f" , 20 , map ("matches" , true )), targetId ));
421
+
422
+ executeQuery (query );
423
+ assertRemoteDocumentsRead (/* byKey= */ 0 , /* byCollection= */ 3 );
424
+ assertQueryReturned ("coll/a" , "coll/e" , "coll/f" );
425
+ }
426
+
399
427
@ Test
400
428
public void testIndexAutoCreationWorksWhenBackfillerRunsHalfway () {
401
429
Query query = query ("coll" ).filter (filter ("matches" , "==" , true ));
402
430
int targetId = allocateQuery (query );
403
431
404
432
enableIndexAutoCreation ();
433
+ setMinCollectionSizeToAutoCreateIndex (0 );
405
434
406
435
applyRemoteEvent (addedRemoteEvent (doc ("coll/a" , 10 , map ("matches" , true )), targetId ));
407
436
applyRemoteEvent (addedRemoteEvent (doc ("coll/b" , 10 , map ("matches" , false )), targetId ));
@@ -433,6 +462,7 @@ public void testIndexCreatedByIndexAutoCreationExistsAfterTurnOffAutoCreation()
433
462
int targetId = allocateQuery (query );
434
463
435
464
enableIndexAutoCreation ();
465
+ setMinCollectionSizeToAutoCreateIndex (0 );
436
466
437
467
applyRemoteEvent (addedRemoteEvent (doc ("coll/a" , 10 , map ("matches" , true )), targetId ));
438
468
applyRemoteEvent (addedRemoteEvent (doc ("coll/b" , 10 , map ("matches" , false )), targetId ));
@@ -464,6 +494,7 @@ public void testDisableIndexAutoCreationWorks() {
464
494
int targetId1 = allocateQuery (query1 );
465
495
466
496
enableIndexAutoCreation ();
497
+ setMinCollectionSizeToAutoCreateIndex (0 );
467
498
468
499
applyRemoteEvent (addedRemoteEvent (doc ("coll/a" , 10 , map ("matches" , true )), targetId1 ));
469
500
applyRemoteEvent (addedRemoteEvent (doc ("coll/b" , 10 , map ("matches" , false )), targetId1 ));
@@ -509,6 +540,7 @@ public void testIndexAutoCreationWorksWithMutation() {
509
540
int targetId = allocateQuery (query );
510
541
511
542
enableIndexAutoCreation ();
543
+ setMinCollectionSizeToAutoCreateIndex (0 );
512
544
513
545
applyRemoteEvent (addedRemoteEvent (doc ("coll/a" , 10 , map ("matches" , true )), targetId ));
514
546
applyRemoteEvent (addedRemoteEvent (doc ("coll/b" , 10 , map ("matches" , false )), targetId ));
0 commit comments