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;
}
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);
}
}
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"));
}
}
}
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"));
}
}
}
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));
}
Aggregations