@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 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)))); }