use of org.neo4j.storageengine.api.schema.IndexSample in project neo4j by neo4j.
the class IndexRecoveryIT method shouldBeAbleToRecoverAndUpdateOnlineIndex.
@Test
public void shouldBeAbleToRecoverAndUpdateOnlineIndex() throws Exception {
// Given
startDb();
IndexPopulator populator = mock(IndexPopulator.class);
when(mockedIndexProvider.getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(populator);
when(populator.sampleResult()).thenReturn(new IndexSample());
IndexAccessor mockedAccessor = mock(IndexAccessor.class);
when(mockedAccessor.newUpdater(any(IndexUpdateMode.class))).thenReturn(SwallowingIndexUpdater.INSTANCE);
when(mockedIndexProvider.getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(mockedAccessor);
createIndexAndAwaitPopulation(myLabel);
// rotate logs
rotateLogsAndCheckPoint();
// make updates
Set<IndexEntryUpdate> expectedUpdates = createSomeBananas(myLabel);
// And Given
killDb();
when(mockedIndexProvider.getInitialState(anyLong(), any(NewIndexDescriptor.class))).thenReturn(InternalIndexState.ONLINE);
GatheringIndexWriter writer = new GatheringIndexWriter();
when(mockedIndexProvider.getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(writer);
// When
startDb();
// Then
assertThat(getIndexes(db, myLabel), inTx(db, hasSize(1)));
assertThat(getIndexes(db, myLabel), inTx(db, haveState(db, Schema.IndexState.ONLINE)));
verify(mockedIndexProvider, times(1)).getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
// once when we create the index, and once when we restart the db
int onlineAccessorInvocationCount = 2;
verify(mockedIndexProvider, times(onlineAccessorInvocationCount)).getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
assertEquals(expectedUpdates, writer.batchedUpdates);
for (IndexEntryUpdate update : writer.batchedUpdates) {
assertTrue(writer.recoveredNodes.contains(update.getEntityId()));
}
}
use of org.neo4j.storageengine.api.schema.IndexSample in project neo4j by neo4j.
the class UniqueDatabaseIndexSamplerTest method uniqueSamplingUseDocumentsNumber.
@Test
public void uniqueSamplingUseDocumentsNumber() throws IndexNotFoundKernelException {
when(indexSearcher.getIndexReader().numDocs()).thenReturn(17);
UniqueLuceneIndexSampler sampler = new UniqueLuceneIndexSampler(indexSearcher, taskControl.newInstance());
IndexSample sample = sampler.sampleIndex();
assertEquals(17, sample.indexSize());
}
use of org.neo4j.storageengine.api.schema.IndexSample in project neo4j by neo4j.
the class NonUniqueDatabaseIndexSamplerTest method samplingOfLargeNumericValues.
@Test
public void samplingOfLargeNumericValues() throws Exception {
try (RAMDirectory dir = new RAMDirectory();
WritableIndexPartition indexPartition = new WritableIndexPartition(new File("testPartition"), dir, IndexWriterConfigs.standard())) {
insertDocument(indexPartition, 1, Long.MAX_VALUE);
insertDocument(indexPartition, 2, Integer.MAX_VALUE);
indexPartition.maybeRefreshBlocking();
try (PartitionSearcher searcher = indexPartition.acquireSearcher()) {
NonUniqueLuceneIndexSampler sampler = new NonUniqueLuceneIndexSampler(searcher.getIndexSearcher(), taskControl.newInstance(), new IndexSamplingConfig(Config.empty()));
assertEquals(new IndexSample(2, 2, 2), sampler.sampleIndex());
}
}
}
use of org.neo4j.storageengine.api.schema.IndexSample in project neo4j by neo4j.
the class NonUniqueDatabaseIndexPopulatorTest method sampleIncludedUpdates.
@Test
public void sampleIncludedUpdates() throws Exception {
populator = newPopulator();
List<IndexEntryUpdate> updates = Arrays.asList(IndexEntryUpdate.add(1, labelSchemaDescriptor, "aaa"), IndexEntryUpdate.add(2, labelSchemaDescriptor, "bbb"), IndexEntryUpdate.add(3, labelSchemaDescriptor, "ccc"));
updates.forEach(populator::includeSample);
IndexSample sample = populator.sampleResult();
assertEquals(new IndexSample(3, 3, 3), sample);
}
use of org.neo4j.storageengine.api.schema.IndexSample in project neo4j by neo4j.
the class NonUniqueDatabaseIndexPopulatorTest method sampleEmptyIndex.
@Test
public void sampleEmptyIndex() throws IOException {
populator = newPopulator();
IndexSample sample = populator.sampleResult();
assertEquals(new IndexSample(), sample);
}
Aggregations