Search in sources :

Example 1 with SchemaIndex

use of org.neo4j.kernel.api.impl.schema.SchemaIndex in project neo4j by neo4j.

the class UniqueDatabaseIndexPopulatingUpdaterTest method closeVerifiesUniquenessOfAddedAndChangedValues.

@Test
public void closeVerifiesUniquenessOfAddedAndChangedValues() throws Exception {
    SchemaIndex index = mock(SchemaIndex.class);
    UniqueLuceneIndexPopulatingUpdater updater = newUpdater(index);
    updater.process(add(1, descriptor, "added1"));
    updater.process(add(2, descriptor, "added2"));
    updater.process(change(3, descriptor, "before1", "after1"));
    updater.process(change(4, descriptor, "before2", "after2"));
    updater.process(remove(5, descriptor, "removed1"));
    verifyZeroInteractions(index);
    updater.close();
    List<Object> toBeVerified = Arrays.asList("added1", "added2", "after1", "after2");
    verify(index).verifyUniqueness(any(), eq(descriptor.getPropertyIds()), eq(toBeVerified));
}
Also used : SchemaIndex(org.neo4j.kernel.api.impl.schema.SchemaIndex) Test(org.junit.Test)

Example 2 with SchemaIndex

use of org.neo4j.kernel.api.impl.schema.SchemaIndex in project neo4j by neo4j.

the class LuceneSchemaIndexPopulationIT method partitionedIndexPopulation.

@Test
public void partitionedIndexPopulation() throws Exception {
    try (SchemaIndex uniqueIndex = LuceneSchemaIndexBuilder.create(descriptor).withFileSystem(fileSystemRule.get()).withIndexRootFolder(testDir.directory("partitionIndex" + affectedNodes)).withIndexIdentifier("uniqueIndex" + affectedNodes).build()) {
        uniqueIndex.open();
        // index is empty and not yet exist
        assertEquals(0, uniqueIndex.allDocumentsReader().maxCount());
        assertFalse(uniqueIndex.exists());
        try (LuceneIndexAccessor indexAccessor = new LuceneIndexAccessor(uniqueIndex, descriptor)) {
            generateUpdates(indexAccessor, affectedNodes);
            indexAccessor.force();
            // now index is online and should contain updates data
            assertTrue(uniqueIndex.isOnline());
            try (IndexReader indexReader = indexAccessor.newReader()) {
                long[] nodes = PrimitiveLongCollections.asArray(indexReader.query(IndexQuery.exists(1)));
                assertEquals(affectedNodes, nodes.length);
                IndexSampler indexSampler = indexReader.createSampler();
                IndexSample sample = indexSampler.sampleIndex();
                assertEquals(affectedNodes, sample.indexSize());
                assertEquals(affectedNodes, sample.uniqueValues());
                assertEquals(affectedNodes, sample.sampleSize());
            }
        }
    }
}
Also used : LuceneIndexAccessor(org.neo4j.kernel.api.impl.schema.LuceneIndexAccessor) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) SchemaIndex(org.neo4j.kernel.api.impl.schema.SchemaIndex) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Test(org.junit.Test)

Example 3 with SchemaIndex

use of org.neo4j.kernel.api.impl.schema.SchemaIndex in project neo4j by neo4j.

the class UniqueDatabaseIndexPopulatingUpdaterTest method closeVerifiesUniquenessOfChangedValues.

@Test
public void closeVerifiesUniquenessOfChangedValues() throws Exception {
    SchemaIndex index = mock(SchemaIndex.class);
    UniqueLuceneIndexPopulatingUpdater updater = newUpdater(index);
    updater.process(change(1, descriptor, "foo1", "foo2"));
    updater.process(change(1, descriptor, "bar1", "bar2"));
    updater.process(change(1, descriptor, "baz1", "baz2"));
    verifyZeroInteractions(index);
    updater.close();
    verify(index).verifyUniqueness(any(), eq(descriptor.getPropertyIds()), eq(Arrays.asList("foo2", "bar2", "baz2")));
}
Also used : SchemaIndex(org.neo4j.kernel.api.impl.schema.SchemaIndex) Test(org.junit.Test)

Example 4 with SchemaIndex

use of org.neo4j.kernel.api.impl.schema.SchemaIndex in project neo4j by neo4j.

the class UniqueDatabaseIndexPopulatingUpdaterTest method closeVerifiesUniquenessOfAddedValues.

@Test
public void closeVerifiesUniquenessOfAddedValues() throws Exception {
    SchemaIndex index = mock(SchemaIndex.class);
    UniqueLuceneIndexPopulatingUpdater updater = newUpdater(index);
    updater.process(add(1, descriptor, "foo"));
    updater.process(add(1, descriptor, "bar"));
    updater.process(add(1, descriptor, "baz"));
    verifyZeroInteractions(index);
    updater.close();
    verify(index).verifyUniqueness(any(), eq(descriptor.getPropertyIds()), eq(Arrays.asList("foo", "bar", "baz")));
}
Also used : SchemaIndex(org.neo4j.kernel.api.impl.schema.SchemaIndex) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 SchemaIndex (org.neo4j.kernel.api.impl.schema.SchemaIndex)4 LuceneIndexAccessor (org.neo4j.kernel.api.impl.schema.LuceneIndexAccessor)1 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)1 IndexSample (org.neo4j.storageengine.api.schema.IndexSample)1 IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)1