@Test
  public void shouldSnapshotOnlineIndexes() throws Exception {
    // GIVEN
    IndexAccessor indexAccessor = mock(IndexAccessor.class);
    IndexingService indexing =
        newIndexingServiceWithMockedDependencies(
            mock(IndexPopulator.class), indexAccessor, new DataUpdates(new NodePropertyUpdate[0]));
    int indexId = 1;
    int indexId2 = 2;
    File theFile = new File("Blah");

    IndexRule rule1 = indexRule(indexId, 2, 3, PROVIDER_DESCRIPTOR);
    IndexRule rule2 = indexRule(indexId2, 4, 5, PROVIDER_DESCRIPTOR);

    when(indexAccessor.snapshotFiles()).thenAnswer(newResourceIterator(theFile));
    when(indexProvider.getInitialState(indexId)).thenReturn(ONLINE);
    when(indexProvider.getInitialState(indexId2)).thenReturn(ONLINE);

    indexing.initIndexes(iterator(rule1, rule2));
    life.start();

    // WHEN
    ResourceIterator<File> files = indexing.snapshotStoreFiles();

    // THEN
    // We get a snapshot per online index
    assertThat(asCollection(files), equalTo(asCollection(iterator(theFile, theFile))));
  }
  @Test
  public void shouldNotSnapshotPopulatingIndexes() throws Exception {
    // GIVEN
    CountDownLatch populatorLatch = new CountDownLatch(1);
    IndexAccessor indexAccessor = mock(IndexAccessor.class);
    IndexingService indexing =
        newIndexingServiceWithMockedDependencies(
            populator, indexAccessor, new DataUpdates(new NodePropertyUpdate[0]));
    int indexId = 1;
    int indexId2 = 2;
    File theFile = new File("Blah");

    IndexRule rule1 = indexRule(indexId, 2, 3, PROVIDER_DESCRIPTOR);
    IndexRule rule2 = indexRule(indexId2, 4, 5, PROVIDER_DESCRIPTOR);

    doAnswer(waitForLatch(populatorLatch)).when(populator).create();
    when(indexAccessor.snapshotFiles()).thenAnswer(newResourceIterator(theFile));
    when(indexProvider.getInitialState(indexId)).thenReturn(POPULATING);
    when(indexProvider.getInitialState(indexId2)).thenReturn(ONLINE);

    indexing.initIndexes(iterator(rule1, rule2));
    life.start();

    // WHEN
    ResourceIterator<File> files = indexing.snapshotStoreFiles();
    populatorLatch
        .countDown(); // only now, after the snapshot, is the population job allowed to finish

    // THEN
    // We get a snapshot from the online index, but no snapshot from the populating one
    assertThat(asCollection(files), equalTo(asCollection(iterator(theFile))));
  }
  @Test
  public void shouldLogIndexStateOnStart() throws Exception {
    // given
    TestLogger logger = new TestLogger();
    SchemaIndexProvider provider = mock(SchemaIndexProvider.class);
    when(provider.getProviderDescriptor()).thenReturn(PROVIDER_DESCRIPTOR);
    SchemaIndexProviderMap providerMap = new DefaultSchemaIndexProviderMap(provider);
    TokenNameLookup mockLookup = mock(TokenNameLookup.class);
    IndexingService indexingService =
        new IndexingService(
            mock(JobScheduler.class),
            providerMap,
            mock(IndexStoreView.class),
            mockLookup,
            mock(UpdateableSchemaState.class),
            mockLogging(logger));

    IndexRule onlineIndex = indexRule(1, 1, 1, PROVIDER_DESCRIPTOR);
    IndexRule populatingIndex = indexRule(2, 1, 2, PROVIDER_DESCRIPTOR);
    IndexRule failedIndex = indexRule(3, 2, 2, PROVIDER_DESCRIPTOR);

    when(provider.getInitialState(onlineIndex.getId())).thenReturn(ONLINE);
    when(provider.getInitialState(populatingIndex.getId()))
        .thenReturn(InternalIndexState.POPULATING);
    when(provider.getInitialState(failedIndex.getId())).thenReturn(InternalIndexState.FAILED);
    indexingService.initIndexes(asList(onlineIndex, populatingIndex, failedIndex).iterator());

    when(mockLookup.labelGetName(1)).thenReturn("LabelOne");
    when(mockLookup.labelGetName(2)).thenReturn("LabelTwo");
    when(mockLookup.propertyKeyGetName(1)).thenReturn("propertyOne");
    when(mockLookup.propertyKeyGetName(2)).thenReturn("propertyTwo");

    logger.clear();

    // when
    indexingService.start();

    // then
    verify(provider).getPopulationFailure(3);
    logger.assertAtLeastOnce(
        info("IndexingService.start: index on :LabelOne(propertyOne) is ONLINE"));
    logger.assertAtLeastOnce(
        info("IndexingService.start: index on :LabelOne(propertyTwo) is POPULATING"));
    logger.assertAtLeastOnce(
        info("IndexingService.start: index on :LabelTwo(propertyTwo) is FAILED"));
  }
示例#4
0
 private IndexRule[] getIndexesNeedingPopulation() {
   List<IndexRule> indexesNeedingPopulation = new ArrayList<>();
   for (SchemaRule rule : schemaCache.schemaRules()) {
     if (rule.getKind().isIndex()) {
       IndexRule indexRule = (IndexRule) rule;
       SchemaIndexProvider provider =
           schemaIndexProviders.apply(indexRule.getProviderDescriptor());
       if (provider.getInitialState(indexRule.getId()) != InternalIndexState.FAILED) {
         indexesNeedingPopulation.add(indexRule);
       }
     }
   }
   return indexesNeedingPopulation.toArray(new IndexRule[indexesNeedingPopulation.size()]);
 }