Search in sources :

Example 6 with PartitionedLuceneLabelScanWriter

use of org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter in project neo4j by neo4j.

the class LuceneLabelScanStoreWriterTest method shouldComplainIfNodesSuppliedOutOfRangeOrder.

@Test
public void shouldComplainIfNodesSuppliedOutOfRangeOrder() throws Exception {
    // given
    int nodeId1 = 1;
    int nodeId2 = 65;
    StubIndexPartition partition = newStubIndexPartition();
    WritableDatabaseLabelScanIndex index = prepareIndex(singletonList(partition));
    long node1Range = format.bitmapFormat().rangeOf(nodeId1);
    long node2Range = format.bitmapFormat().rangeOf(nodeId2);
    assertNotEquals(node1Range, node2Range);
    // when
    PartitionedLuceneLabelScanWriter writer = createWriter(index);
    writer.write(NodeLabelUpdate.labelChanges(nodeId2, new long[] {}, new long[] {}));
    try {
        writer.write(NodeLabelUpdate.labelChanges(nodeId1, new long[] {}, new long[] {}));
        fail("Should have thrown exception");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) Test(org.junit.Test)

Example 7 with PartitionedLuceneLabelScanWriter

use of org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter in project neo4j by neo4j.

the class LuceneLabelScanStoreWriterTest method shouldStoreDocumentWithNodeIdsInTheSameRange.

@Test
public void shouldStoreDocumentWithNodeIdsInTheSameRange() throws Exception {
    // given
    int nodeId1 = 1;
    int nodeId2 = 3;
    int label1 = 201;
    int label2 = 202;
    StubIndexPartition partition = newStubIndexPartition();
    long range = format.bitmapFormat().rangeOf(nodeId1);
    assertEquals(range, format.bitmapFormat().rangeOf(nodeId2));
    WritableDatabaseLabelScanIndex index = buildLabelScanIndex(partition);
    // when
    PartitionedLuceneLabelScanWriter writer = createWriter(index);
    writer.write(NodeLabelUpdate.labelChanges(nodeId1, new long[] {}, new long[] { label1 }));
    writer.write(NodeLabelUpdate.labelChanges(nodeId2, new long[] {}, new long[] { label2 }));
    writer.close();
    // then
    Document document = partition.documentFor(new Term(RANGE, valueOf(range)));
    assertTrue(format.bitmapFormat().hasLabel(parseLong(document.get(valueOf(label1))), nodeId1));
    assertTrue(format.bitmapFormat().hasLabel(parseLong(document.get(valueOf(label2))), nodeId2));
}
Also used : PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 8 with PartitionedLuceneLabelScanWriter

use of org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter in project neo4j by neo4j.

the class LuceneLabelScanStoreWriterTest method shouldStoreDocumentWithNodeIdsAndLabelsInIt.

@Test
public void shouldStoreDocumentWithNodeIdsAndLabelsInIt() throws Exception {
    // given
    int nodeId = 1;
    int label1 = 201;
    int label2 = 202;
    StubIndexPartition partition = newStubIndexPartition();
    WritableDatabaseLabelScanIndex index = buildLabelScanIndex(partition);
    // when
    PartitionedLuceneLabelScanWriter writer = createWriter(index);
    writer.write(NodeLabelUpdate.labelChanges(nodeId, new long[] {}, new long[] { label1, label2 }));
    writer.close();
    // then
    long range = format.bitmapFormat().rangeOf(nodeId);
    Document document = partition.documentFor(new Term(RANGE, valueOf(range)));
    assertTrue(format.bitmapFormat().hasLabel(parseLong(document.get(valueOf(label1))), nodeId));
    assertTrue(format.bitmapFormat().hasLabel(parseLong(document.get(valueOf(label2))), nodeId));
}
Also used : PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 9 with PartitionedLuceneLabelScanWriter

use of org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter in project neo4j by neo4j.

the class LuceneLabelScanStoreWriterTest method shouldUpdateExistingDocumentWithNodesInTheSameRange.

@Test
public void shouldUpdateExistingDocumentWithNodesInTheSameRange() throws Exception {
    // given
    int nodeId1 = 1;
    int nodeId2 = 3;
    int label1 = 201;
    int label2 = 202;
    StubIndexPartition partition = newStubIndexPartition();
    long range = format.bitmapFormat().rangeOf(nodeId1);
    assertEquals(range, format.bitmapFormat().rangeOf(nodeId2));
    WritableDatabaseLabelScanIndex index = buildLabelScanIndex(partition);
    // node already indexed
    PartitionedLuceneLabelScanWriter writer = createWriter(index);
    writer.write(NodeLabelUpdate.labelChanges(nodeId1, new long[] {}, new long[] { label1 }));
    writer.close();
    // when
    writer = createWriter(index);
    writer.write(NodeLabelUpdate.labelChanges(nodeId2, new long[] {}, new long[] { label2 }));
    writer.close();
    // then
    Document document = partition.documentFor(new Term(RANGE, valueOf(range)));
    assertTrue(format.bitmapFormat().hasLabel(parseLong(document.get(valueOf(label1))), nodeId1));
    assertTrue(format.bitmapFormat().hasLabel(parseLong(document.get(valueOf(label2))), nodeId2));
}
Also used : PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) Test(org.junit.Test)

Example 10 with PartitionedLuceneLabelScanWriter

use of org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter in project neo4j by neo4j.

the class LuceneLabelScanStoreWriterTest method automaticPartitionCreation.

@Test
public void automaticPartitionCreation() throws IOException {
    int nodeForPartition1 = 1;
    int nodeForPartition2 = (format.bitmapFormat().rangeSize() * 2) + 1;
    int labelNode1 = 201;
    int labelNode2 = 202;
    System.setProperty("labelScanStore.maxPartitionSize", "2");
    StubIndexPartition partition = newStubIndexPartition();
    WritableDatabaseLabelScanIndex index = buildLabelScanIndex(partition);
    PartitionedLuceneLabelScanWriter writer = createWriter(index);
    writer.write(NodeLabelUpdate.labelChanges(nodeForPartition1, new long[] {}, new long[] { labelNode1 }));
    writer.write(NodeLabelUpdate.labelChanges(nodeForPartition2, new long[] {}, new long[] { labelNode2 }));
    writer.close();
    assertEquals("We should have 2 index partitions", 2, index.getPartitions().size());
}
Also used : PartitionedLuceneLabelScanWriter(org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 PartitionedLuceneLabelScanWriter (org.neo4j.kernel.api.impl.labelscan.writer.PartitionedLuceneLabelScanWriter)12 Document (org.apache.lucene.document.Document)9 IndexWriter (org.apache.lucene.index.IndexWriter)6 WritableIndexPartition (org.neo4j.kernel.api.impl.index.partition.WritableIndexPartition)6 WritableDatabaseLabelScanIndex (org.neo4j.kernel.api.impl.labelscan.WritableDatabaseLabelScanIndex)6 LabelScanWriter (org.neo4j.kernel.api.labelscan.LabelScanWriter)6 Term (org.apache.lucene.index.Term)4 Bitmap (org.neo4j.kernel.api.impl.labelscan.bitmaps.Bitmap)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 TermQuery (org.apache.lucene.search.TermQuery)1 PartitionSearcher (org.neo4j.kernel.api.impl.index.partition.PartitionSearcher)1