Search in sources :

Example 36 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method shouldStopSamplingWhenIndexIsDropped.

@Test
public void shouldStopSamplingWhenIndexIsDropped() throws Exception {
    // given
    updateAndCommit(asList(add(nodeId, value), add(nodeId2, value2)));
    // when
    // needs to be acquired before drop() is called
    IndexReader indexReader = accessor.newReader();
    IndexSampler indexSampler = indexReader.createSampler();
    Future<Void> drop = threading.executeAndAwait((IOFunction<Void, Void>) nothing -> {
        accessor.drop();
        return nothing;
    }, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 3, SECONDS);
    try (IndexReader reader = indexReader) /* do not inline! */
    {
        indexSampler.sampleIndex();
        fail("expected exception");
    } catch (IndexNotFoundKernelException e) {
        assertEquals("Index dropped while sampling.", e.getMessage());
    } finally {
        drop.get();
    }
}
Also used : DirectoryFactory(org.neo4j.kernel.api.impl.index.storage.DirectoryFactory) Arrays(java.util.Arrays) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) RunWith(org.junit.runner.RunWith) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TaskCoordinator(org.neo4j.helpers.TaskCoordinator) Assert.assertThat(org.junit.Assert.assertThat) Future(java.util.concurrent.Future) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) IndexQuery.exact(org.neo4j.kernel.api.schema_new.IndexQuery.exact) Assert.fail(org.junit.Assert.fail) IndexUpdateMode(org.neo4j.kernel.impl.api.index.IndexUpdateMode) ClassRule(org.junit.ClassRule) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) Collection(java.util.Collection) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) Test(org.junit.Test) IOException(java.io.IOException) IndexQuery.range(org.neo4j.kernel.api.schema_new.IndexQuery.range) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IOFunction(org.neo4j.function.IOFunction) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) File(java.io.File) List(java.util.List) Rule(org.junit.Rule) ThreadingRule(org.neo4j.test.rule.concurrent.ThreadingRule) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Iterators.emptySetOf(org.neo4j.helpers.collection.Iterators.emptySetOf) ThreadingRule.waitingWhileIn(org.neo4j.test.rule.concurrent.ThreadingRule.waitingWhileIn) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) TaskCoordinator(org.neo4j.helpers.TaskCoordinator) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Test(org.junit.Test)

Example 37 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method indexReaderShouldHonorRepeatableReads.

@Test
public void indexReaderShouldHonorRepeatableReads() throws Exception {
    // GIVEN
    updateAndCommit(asList(add(nodeId, value)));
    IndexReader reader = accessor.newReader();
    // WHEN
    updateAndCommit(asList(remove(nodeId, value)));
    // THEN
    assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(reader.query(exact(PROP_ID, value))));
    reader.close();
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 38 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class SimpleIndexReaderTest method stringRangeSeekQueryReachSearcher.

@Test
public void stringRangeSeekQueryReachSearcher() throws Exception {
    IndexReader simpleIndexReader = getUniqueSimpleReader();
    simpleIndexReader.query(range(1, "a", false, "b", true));
    verify(indexSearcher).search(any(TermQuery.class), any(DocValuesCollector.class));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 39 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class SimpleIndexReaderTest method numberRangeSeekQueryReachSearcher.

@Test
public void numberRangeSeekQueryReachSearcher() throws Exception {
    IndexReader simpleIndexReader = getUniqueSimpleReader();
    simpleIndexReader.query(range(1, 7, true, 8, true));
    verify(indexSearcher).search(any(NumericRangeQuery.class), any(DocValuesCollector.class));
}
Also used : NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 40 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class SimpleIndexReaderTest method releaseSearcherOnClose.

@Test
public void releaseSearcherOnClose() throws IOException {
    IndexReader simpleIndexReader = getUniqueSimpleReader();
    simpleIndexReader.close();
    verify(partitionSearcher).close();
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Aggregations

IndexReader (org.neo4j.storageengine.api.schema.IndexReader)50 Test (org.junit.Test)38 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)19 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)11 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)10 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)10 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)9 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)9 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)6 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)5 IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TermQuery (org.apache.lucene.search.TermQuery)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.fail (org.junit.Assert.fail)2 Before (org.junit.Before)2