Search in sources :

Example 11 with IndexReader

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

the class StatementOperationsTestHelper method mockedState.

public static KernelStatement mockedState(final TransactionState txState) {
    KernelStatement state = mock(KernelStatement.class);
    Locks.Client locks = mock(Locks.Client.class);
    try {
        IndexReader indexReader = mock(IndexReader.class);
        when(indexReader.query(Matchers.isA(IndexQuery.ExactPredicate.class))).thenReturn(PrimitiveLongCollections.emptyIterator());
        StorageStatement storageStatement = mock(StorageStatement.class);
        when(storageStatement.getIndexReader(Matchers.any())).thenReturn(indexReader);
        when(state.getStoreStatement()).thenReturn(storageStatement);
    } catch (IndexNotFoundKernelException | IndexNotApplicableKernelException e) {
        throw new Error(e);
    }
    when(state.txState()).thenReturn(txState);
    when(state.hasTxStateWithChanges()).thenAnswer(invocation -> txState.hasChanges());
    when(state.locks()).thenReturn(new SimpleStatementLocks(locks));
    when(state.readOperations()).thenReturn(mock(ReadOperations.class));
    return state;
}
Also used : SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) LegacyIndexReadOperations(org.neo4j.kernel.impl.api.operations.LegacyIndexReadOperations) ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) EntityReadOperations(org.neo4j.kernel.impl.api.operations.EntityReadOperations) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException) StorageStatement(org.neo4j.storageengine.api.StorageStatement) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) Locks(org.neo4j.kernel.impl.locking.Locks) SimpleStatementLocks(org.neo4j.kernel.impl.locking.SimpleStatementLocks) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)

Example 12 with IndexReader

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

the class DirectNonUniqueIndexSampler method result.

@Override
public IndexSample result() {
    try {
        // lucene index needs to be flushed to be sure that reader will see all the data :(
        luceneIndex.flush();
        luceneIndex.maybeRefreshBlocking();
        try (IndexReader indexReader = luceneIndex.getIndexReader()) {
            IndexSampler sampler = indexReader.createSampler();
            return sampler.sampleIndex();
        } catch (IOException | IndexNotFoundKernelException e) {
            throw new RuntimeException(e);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) IOException(java.io.IOException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) NonUniqueIndexSampler(org.neo4j.kernel.impl.api.index.sampling.NonUniqueIndexSampler) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler)

Example 13 with IndexReader

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

the class MultiIndexPopulationConcurrentUpdatesIT method applyConcurrentChangesToPopulatedIndex.

@Test
public void applyConcurrentChangesToPopulatedIndex() throws Exception {
    List<NodeUpdates> updates = new ArrayList<>(2);
    updates.add(NodeUpdates.forNode(3, id(COLOR_LABEL)).changed(propertyId, "green", "pink").build());
    updates.add(NodeUpdates.forNode(5, id(CAR_LABEL)).changed(propertyId, "Ford", "SAAB").build());
    launchCustomIndexPopulation(labelsNameIdMap, propertyId, updates);
    waitAndActivateIndexes(labelsNameIdMap, propertyId);
    try (Transaction ignored = embeddedDatabase.beginTx()) {
        Integer colorLabelId = labelsNameIdMap.get(COLOR_LABEL);
        Integer carLabelId = labelsNameIdMap.get(CAR_LABEL);
        try (IndexReader indexReader = getIndexReader(propertyId, colorLabelId)) {
            assertEquals("Should be deleted by concurrent change.", 0, indexReader.countIndexedNodes(3, "green"));
        }
        try (IndexReader indexReader = getIndexReader(propertyId, colorLabelId)) {
            assertEquals("Should be updated by concurrent change.", 1, indexReader.countIndexedNodes(3, "pink"));
        }
        try (IndexReader indexReader = getIndexReader(propertyId, carLabelId)) {
            assertEquals("Should be added by concurrent change.", 1, indexReader.countIndexedNodes(5, "SAAB"));
        }
    }
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) Transaction(org.neo4j.graphdb.Transaction) ArrayList(java.util.ArrayList) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 14 with IndexReader

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

the class MultiIndexPopulationConcurrentUpdatesIT method applyConcurrentAddsToPopulatedIndex.

@Test
public void applyConcurrentAddsToPopulatedIndex() throws Throwable {
    List<NodeUpdates> updates = new ArrayList<>(2);
    updates.add(NodeUpdates.forNode(6, id(COUNTRY_LABEL)).added(propertyId, "Denmark").build());
    updates.add(NodeUpdates.forNode(7, id(CAR_LABEL)).added(propertyId, "BMW").build());
    launchCustomIndexPopulation(labelsNameIdMap, propertyId, updates);
    waitAndActivateIndexes(labelsNameIdMap, propertyId);
    try (Transaction ignored = embeddedDatabase.beginTx()) {
        Integer countryLabelId = labelsNameIdMap.get(COUNTRY_LABEL);
        Integer carLabelId = labelsNameIdMap.get(CAR_LABEL);
        try (IndexReader indexReader = getIndexReader(propertyId, countryLabelId)) {
            assertEquals("Should be added by concurrent add.", 1, indexReader.countIndexedNodes(6, "Denmark"));
        }
        try (IndexReader indexReader = getIndexReader(propertyId, carLabelId)) {
            assertEquals("Should be added by concurrent add.", 1, indexReader.countIndexedNodes(7, "BMW"));
        }
    }
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) Transaction(org.neo4j.graphdb.Transaction) ArrayList(java.util.ArrayList) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 15 with IndexReader

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

the class SimpleIndexReaderTest method prefixRangeSeekQueryReachSearcher.

@Test
public void prefixRangeSeekQueryReachSearcher() throws Exception {
    IndexReader simpleIndexReader = getUniqueSimpleReader();
    simpleIndexReader.query(IndexQuery.stringPrefix(1, "bb"));
    verify(indexSearcher).search(any(PrefixQuery.class), any(DocValuesCollector.class));
}
Also used : PrefixQuery(org.apache.lucene.search.PrefixQuery) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) 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