Search in sources :

Example 1 with WritableIndexPartition

use of org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldUpdateDocumentsForReLabeledNodes.

@Test
public void shouldUpdateDocumentsForReLabeledNodes() throws Exception {
    // given
    Document givenDoc = new Document();
    format.addRangeValuesField(givenDoc, 0);
    format.addLabelFields(givenDoc, "7", 0x70L);
    WritableDatabaseLabelScanIndex index = mock(WritableDatabaseLabelScanIndex.class);
    IndexWriter indexWriter = mock(IndexWriter.class);
    WritableIndexPartition partition = newIndexPartitionMock(indexWriter, givenDoc);
    when(index.getPartitions()).thenReturn(Collections.singletonList(partition));
    LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
    // when
    writer.write(labelChanges(0, labels(), labels(7, 8)));
    writer.close();
    // then
    Document thenDoc = new Document();
    format.addRangeValuesField(thenDoc, 0);
    format.addLabelFields(thenDoc, "7", 0x71L);
    format.addLabelAndSearchFields(thenDoc, 8, new Bitmap(0x01L));
    verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(thenDoc));
}
Also used : Bitmap(org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap) WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) Document(org.apache.lucene.document.Document) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Example 2 with WritableIndexPartition

use of org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldUpdateDocumentToReflectLabelsAfterRegardlessOfPreviousContent.

@Test
public void shouldUpdateDocumentToReflectLabelsAfterRegardlessOfPreviousContent() throws Exception {
    // given
    IndexWriter indexWriter = mock(IndexWriter.class);
    Document doc = document(format.rangeField(0), format.labelField(6, 0x1), format.labelField(7, 0x1));
    WritableIndexPartition partition = newIndexPartitionMock(indexWriter, doc);
    WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
    LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
    // when
    writer.write(labelChanges(0, labels(7), labels(7, 8)));
    writer.close();
    // then
    verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document(format.rangeField(0), format.labelField(7, 0x01), format.labelField(8, 0x01), format.labelSearchField(7), format.labelSearchField(8))));
}
Also used : WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) Document(org.apache.lucene.document.Document) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Example 3 with WritableIndexPartition

use of org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldDeleteEmptyDocuments.

@Test
public void shouldDeleteEmptyDocuments() throws Exception {
    // given
    IndexWriter indexWriter = mock(IndexWriter.class);
    Document doc = document(format.rangeField(0), format.labelField(7, 0x1));
    WritableIndexPartition partition = newIndexPartitionMock(indexWriter, doc);
    WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
    LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
    // when
    writer.write(labelChanges(0, labels(7), labels()));
    writer.close();
    // then
    verify(indexWriter).deleteDocuments(format.rangeTerm(0));
}
Also used : WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) Document(org.apache.lucene.document.Document) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Example 4 with WritableIndexPartition

use of org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldCreateNewDocumentsForNewlyLabeledNodes.

@Test
public void shouldCreateNewDocumentsForNewlyLabeledNodes() throws Exception {
    // given
    WritableIndexPartition partition = mock(WritableIndexPartition.class);
    WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
    PartitionSearcher partitionSearcher = mock(PartitionSearcher.class);
    when(partition.acquireSearcher()).thenReturn(partitionSearcher);
    IndexWriter indexWriter = mock(IndexWriter.class);
    when(partition.getIndexWriter()).thenReturn(indexWriter);
    IndexSearcher searcher = mock(IndexSearcher.class);
    when(partitionSearcher.getIndexSearcher()).thenReturn(searcher);
    when(searcher.search(new TermQuery(format.rangeTerm(0)), 1)).thenReturn(emptyTopDocs());
    when(searcher.search(new TermQuery(format.rangeTerm(1)), 1)).thenReturn(null);
    LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
    // when
    writer.write(labelChanges(0, labels(), labels(6, 7)));
    writer.write(labelChanges(1, labels(), labels(6, 8)));
    writer.write(labelChanges(1 << format.bitmapFormat().shift, labels(), labels(7)));
    writer.close();
    // then
    verify(partition, times(2)).acquireSearcher();
    verify(partitionSearcher, times(2)).getIndexSearcher();
    verify(partition, times(2)).getIndexWriter();
    verify(partitionSearcher, times(2)).close();
    verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document(format.rangeField(0), format.labelField(6, 0x3), format.labelField(7, 0x1), format.labelField(8, 0x2), format.labelSearchField(8))));
    verify(indexWriter).updateDocument(eq(format.rangeTerm(1)), match(document(format.rangeField(1), format.labelField(7, 0x1), format.labelSearchField(7))));
    verify(index).maybeRefreshBlocking();
    verifyNoMoreInteractions(partition);
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) TermQuery(org.apache.lucene.search.TermQuery) WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) PartitionSearcher(org.neo4j.kernel.api.impl.index.partition.PartitionSearcher) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Example 5 with WritableIndexPartition

use of org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition in project neo4j by neo4j.

the class NodeRangeDocumentLabelScanStorageStrategyTest method shouldRemoveLabelFieldsThatDoesNotRepresentAnyNodes.

@Test
public void shouldRemoveLabelFieldsThatDoesNotRepresentAnyNodes() throws Exception {
    // given
    IndexWriter indexWriter = mock(IndexWriter.class);
    Document doc = document(format.rangeField(0), format.labelField(7, 0x1), format.labelField(8, 0x1));
    WritableIndexPartition partition = newIndexPartitionMock(indexWriter, doc);
    WritableDatabaseLabelScanIndex index = buildLuceneIndex(partition);
    LabelScanWriter writer = new PartitionedLuceneLabelScanWriter(index, format);
    // when
    writer.write(labelChanges(0, labels(7, 8), labels(8)));
    writer.close();
    // then
    verify(indexWriter).updateDocument(eq(format.rangeTerm(0)), match(document(format.rangeField(0), format.labelField(8, 0x01), format.labelSearchField(8))));
}
Also used : WritableDatabaseLabelScanIndex(org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex) IndexWriter(org.apache.lucene.index.IndexWriter) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) WritableIndexPartition(org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition) Document(org.apache.lucene.document.Document) PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) LabelScanWriter(org.neo4j.kernel.api.labelscan.LabelScanWriter) Test(org.junit.Test)

Aggregations

WritableIndexPartition (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition)8 Test (org.junit.Test)7 IndexWriter (org.apache.lucene.index.IndexWriter)6 WritableDatabaseLabelScanIndex (org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex)6 PartitionedLuceneLabelScanWriter (org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter)6 LabelScanWriter (org.neo4j.kernel.api.labelscan.LabelScanWriter)6 Document (org.apache.lucene.document.Document)5 PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 TermQuery (org.apache.lucene.search.TermQuery)2 Bitmap (org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap)2 File (java.io.File)1 CollectionTerminatedException (org.apache.lucene.search.CollectionTerminatedException)1 RAMDirectory (org.apache.lucene.store.RAMDirectory)1 FirstHitCollector (org.neo4j.kernel.api.impl.index.collector.FirstHitCollector)1 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)1 IndexSample (org.neo4j.storageengine.api.schema.IndexSample)1