use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByStringWithIndexQuery.
@Test
public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByStringWithIndexQuery() throws Exception {
// Given
TransactionState txState = mock(TransactionState.class);
KernelStatement statement = mock(KernelStatement.class);
when(statement.hasTxStateWithChanges()).thenReturn(true);
when(statement.txState()).thenReturn(txState);
when(txState.indexUpdatesForRangeSeekByString(index, "Anne", true, "Bill", false)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
IndexReader indexReader = addMockedIndexReader(statement);
IndexQuery.StringRangePredicate rangePredicate = IndexQuery.range(index.schema().getPropertyId(), "Anne", true, "Bill", false);
when(indexReader.query(rangePredicate)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
// When
PrimitiveLongIterator results = context.indexQuery(statement, index, rangePredicate);
// Then
assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekByContainsWithIndexQuery.
@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekByContainsWithIndexQuery() throws Exception {
// Given
TransactionState txState = mock(TransactionState.class);
KernelStatement statement = mock(KernelStatement.class);
when(statement.hasTxStateWithChanges()).thenReturn(true);
when(statement.txState()).thenReturn(txState);
when(txState.indexUpdatesForScan(index)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
IndexReader indexReader = addMockedIndexReader(statement);
IndexQuery.StringContainsPredicate indexQuery = IndexQuery.stringContains(index.schema().getPropertyId(), "contains");
when(indexReader.query(indexQuery)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
// When
PrimitiveLongIterator results = context.indexQuery(statement, index, indexQuery);
// Then
assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class SimpleIndexPopulatorCompatibility method shouldApplyUpdatesIdempotently.
@Test
public void shouldApplyUpdatesIdempotently() throws Exception {
// GIVEN
IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.empty());
IndexPopulator populator = indexProvider.getPopulator(17, descriptor, indexSamplingConfig);
populator.create();
populator.configureSampling(true);
long nodeId = 1;
final String propertyValue = "value1";
PropertyAccessor propertyAccessor = (nodeId1, propertyKeyId) -> Property.stringProperty(propertyKeyId, propertyValue);
// this update (using add())...
populator.add(singletonList(IndexEntryUpdate.add(nodeId, descriptor.schema(), propertyValue)));
// ...is the same as this update (using update())
try (IndexUpdater updater = populator.newPopulatingUpdater(propertyAccessor)) {
updater.process(add(nodeId, descriptor.schema(), propertyValue));
}
populator.close(true);
// then
IndexAccessor accessor = indexProvider.getOnlineAccessor(17, descriptor, indexSamplingConfig);
try (IndexReader reader = accessor.newReader()) {
int propertyKeyId = descriptor.schema().getPropertyId();
PrimitiveLongIterator nodes = reader.query(IndexQuery.exact(propertyKeyId, propertyValue));
assertEquals(asSet(1L), PrimitiveLongCollections.toSet(nodes));
}
accessor.close();
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class IndexAccessorCompatibility method metaGet.
private List<Long> metaGet(ReaderInteraction interaction) throws Exception {
try (IndexReader reader = accessor.newReader()) {
List<Long> list = new LinkedList<>();
for (PrimitiveLongIterator iterator = interaction.results(reader); iterator.hasNext(); ) {
list.add(iterator.next());
}
Collections.sort(list);
return list;
}
}
use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.
the class PropertyAndNodeIndexedCheck method checkIndexToLabels.
private void checkIndexToLabels(NodeRecord record, CheckerEngine<NodeRecord, ConsistencyReport.NodeConsistencyReport> engine, RecordAccess records, Collection<PropertyRecord> propertyRecs) {
Set<Long> labels = NodeLabelReader.getListOfLabels(record, records, engine);
List<PropertyBlock> properties = null;
for (IndexRule indexRule : indexes.rules()) {
long labelId = indexRule.schema().getLabelId();
if (!labels.contains(labelId)) {
continue;
}
if (properties == null) {
properties = propertyReader.propertyBlocks(propertyRecs);
}
// assuming 1 property always
int propertyId = indexRule.schema().getPropertyId();
PropertyBlock property = propertyWithKey(properties, propertyId);
if (property == null) {
continue;
}
try (IndexReader reader = indexes.accessorFor(indexRule).newReader()) {
Object propertyValue = propertyReader.propertyValue(property).value();
long nodeId = record.getId();
if (indexRule.canSupportUniqueConstraint()) {
verifyNodeCorrectlyIndexedUniquely(nodeId, property.getKeyIndexId(), propertyValue, engine, indexRule, reader);
} else {
verifyNodeCorrectlyIndexed(nodeId, propertyValue, engine, indexRule, reader);
}
}
}
}
Aggregations