@Test
  public void queryOnlyWhenIndexIsAvailable() throws Exception {
    setUpMockBucket(0);
    setUpMockBucket(1);

    when(indexForPR.isIndexAvailable(0)).thenReturn(true);
    when(indexForPR.isIndexAvailable(1)).thenReturn(true);

    int[] buckets = new int[] {2, 0, 1};
    InternalRegionFunctionContext ctx = Mockito.mock(InternalRegionFunctionContext.class);
    when(ctx.getLocalBucketArray((any()))).thenReturn(buckets);

    await().until(() -> {
      final Collection<IndexRepository> repositories = new HashSet<>();
      try {
        repositories.addAll(repoManager.getRepositories(ctx));
      } catch (BucketNotFoundException | LuceneIndexCreationInProgressException ignored) {
      }
      return repositories.size() == 2;
    });

    Iterator<IndexRepository> itr = repoManager.getRepositories(ctx).iterator();
    IndexRepositoryImpl repo0 = (IndexRepositoryImpl) itr.next();
    IndexRepositoryImpl repo1 = (IndexRepositoryImpl) itr.next();

    assertNotNull(repo0);
    assertNotNull(repo1);
    assertNotEquals(repo0, repo1);

    checkRepository(repo0, 0, 1);
    checkRepository(repo1, 0, 1);
  }
Test that we get the expected exception when a user bucket is not indexed yet
geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java