use of org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition in project neo4j by neo4j.
the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldStoreAnyNodeIdInRange.
@Test
public void shouldStoreAnyNodeIdInRange() throws Exception {
for (int i = 0, max = 1 << format.bitmapFormat().shift; i < max; i++) {
// given
IndexWriter indexWriter = mock(IndexWriter.class);
WritableIndexPartition partition = newIndexPartitionMock(indexWriter);
WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
// when
writer.write(labelChanges(i, labels(), labels(7)));
writer.close();
// then
Document document = new Document();
format.addRangeValuesField(document, 0);
format.addLabelAndSearchFields(document, 7, new Bitmap(1L << i));
verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document));
}
}
use of org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition in project neo4j by neo4j.
the class NodeRangeDocumentLabelScanStorageStrategyTest method newIndexPartitionMock.
private WritableIndexPartition newIndexPartitionMock(IndexWriter indexWriter, Document... documents) throws IOException {
WritableIndexPartition partition = mock(WritableIndexPartition.class);
PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
when(partition.acquireSearcher()).thenReturn(partitionSearcher);
when(partition.getIndexWriter()).thenReturn(indexWriter);
IndexSearcher searcher = mock(IndexSearcher.class);
when(partitionSearcher.getIndexSearcher()).thenReturn(searcher);
for (int i = 0; i < documents.length; i++) {
int docId = i;
doAnswer(invocation -> {
FirstHitCollector collector = (FirstHitCollector) invocation.getArguments()[1];
try {
collector.collect(docId);
} catch (CollectionTerminatedException swallow) {
}
return null;
}).when(searcher).search(eq(new TermQuery(format.rangeTerm(documents[i]))), any(FirstHitCollector.class));
when(searcher.doc(i)).thenReturn(documents[i]);
}
return partition;
}
use of org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition 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());
}
}
}
Aggregations