Search in sources :

Example 41 with IndexReader

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

the class SimpleIndexReaderTest method seekQueryReachSearcher.

@Test
public void seekQueryReachSearcher() throws Exception {
    IndexReader simpleIndexReader = getUniqueSimpleReader();
    simpleIndexReader.query(IndexQuery.exact(1, "test"));
    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 42 with IndexReader

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

the class SimpleIndexReaderTest method countIndexedNodesReachSearcher.

@Test
public void countIndexedNodesReachSearcher() throws IOException {
    IndexReader simpleIndexReader = getUniqueSimpleReader();
    simpleIndexReader.countIndexedNodes(2, "testValue");
    verify(indexSearcher).search(any(BooleanQuery.class), any(DocValuesCollector.class));
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 43 with IndexReader

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

the class NonUniqueDatabaseIndexPopulatorTest method addUpdates.

@Test
public void addUpdates() throws Exception {
    populator = newPopulator();
    List<IndexEntryUpdate> updates = Arrays.asList(IndexEntryUpdate.add(1, labelSchemaDescriptor, "foo"), IndexEntryUpdate.add(2, labelSchemaDescriptor, "bar"), IndexEntryUpdate.add(42, labelSchemaDescriptor, "bar"));
    populator.add(updates);
    index.maybeRefreshBlocking();
    try (IndexReader reader = index.getIndexReader()) {
        int propertyKeyId = labelSchemaDescriptor.getPropertyId();
        PrimitiveLongIterator allEntities = reader.query(IndexQuery.exists(propertyKeyId));
        assertArrayEquals(new long[] { 1, 2, 42 }, PrimitiveLongCollections.asArray(allEntities));
    }
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 44 with IndexReader

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

the class MultiIndexPopulationConcurrentUpdatesIT method applyConcurrentDeletesToPopulatedIndex.

@Test
public void applyConcurrentDeletesToPopulatedIndex() throws Throwable {
    List<NodeUpdates> updates = new ArrayList<>(2);
    updates.add(NodeUpdates.forNode(0, id(COUNTRY_LABEL)).removed(propertyId, "Sweden").build());
    updates.add(NodeUpdates.forNode(3, id(COLOR_LABEL)).removed(propertyId, "green").build());
    launchCustomIndexPopulation(labelsNameIdMap, propertyId, updates);
    waitAndActivateIndexes(labelsNameIdMap, propertyId);
    try (Transaction ignored = embeddedDatabase.beginTx()) {
        Integer countryLabelId = labelsNameIdMap.get(COUNTRY_LABEL);
        Integer colorLabelId = labelsNameIdMap.get(COLOR_LABEL);
        try (IndexReader indexReader = getIndexReader(propertyId, countryLabelId)) {
            assertEquals("Should be removed by concurrent remove.", 0, indexReader.countIndexedNodes(0, "Sweden"));
        }
        try (IndexReader indexReader = getIndexReader(propertyId, colorLabelId)) {
            assertEquals("Should be removed by concurrent remove.", 0, indexReader.countIndexedNodes(3, "green"));
        }
    }
}
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 45 with IndexReader

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

the class IndexQueryTransactionStateTest method before.

@Before
public void before() throws Exception {
    TransactionState txState = new TxState();
    state = StatementOperationsTestHelper.mockedState(txState);
    store = mock(StoreReadLayer.class);
    when(store.indexGetState(newIndexDescriptor)).thenReturn(InternalIndexState.ONLINE);
    when(store.indexesGetForLabel(labelId)).then(answerAsIteratorFrom(indexes));
    when(store.indexesGetAll()).then(answerAsIteratorFrom(indexes));
    when(store.constraintsGetForLabel(labelId)).thenReturn(Collections.emptyIterator());
    when(store.indexGetForLabelAndPropertyKey(newIndexDescriptor.schema())).thenReturn(newIndexDescriptor);
    statement = mock(StoreStatement.class);
    when(state.getStoreStatement()).thenReturn(statement);
    indexReader = mock(IndexReader.class);
    when(statement.getIndexReader(newIndexDescriptor)).thenReturn(indexReader);
    when(statement.getFreshIndexReader(newIndexDescriptor)).thenReturn(indexReader);
    StateHandlingStatementOperations stateHandlingOperations = new StateHandlingStatementOperations(store, new InternalAutoIndexing(Config.empty(), null), mock(ConstraintIndexCreator.class), mock(LegacyIndexStore.class));
    txContext = new ConstraintEnforcingEntityOperations(new StandardConstraintSemantics(), stateHandlingOperations, stateHandlingOperations, stateHandlingOperations, stateHandlingOperations);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) LegacyIndexStore(org.neo4j.kernel.impl.index.LegacyIndexStore) StoreStatement(org.neo4j.kernel.impl.api.store.StoreStatement) InternalAutoIndexing(org.neo4j.kernel.impl.api.legacyindex.InternalAutoIndexing) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) ConstraintEnforcingEntityOperations(org.neo4j.kernel.impl.api.ConstraintEnforcingEntityOperations) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) Before(org.junit.Before)

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