use of org.neo4j.kernel.api.index.ValueIndexReader in project neo4j by neo4j.
the class DeferredConflictCheckingIndexUpdaterTest method shouldQueryAboutAddedAndChangedValueTuples.
@Test
void shouldQueryAboutAddedAndChangedValueTuples() throws Exception {
// given
IndexUpdater actual = mock(IndexUpdater.class);
ValueIndexReader reader = mock(ValueIndexReader.class);
doAnswer(new NodeIdsIndexReaderQueryAnswer(descriptor, 0)).when(reader).query(any(), any(), any(), any(), any());
long nodeId = 0;
List<ValueIndexEntryUpdate<IndexDescriptor>> updates = new ArrayList<>();
updates.add(add(nodeId++, descriptor, tuple(10, 11)));
updates.add(change(nodeId++, descriptor, tuple("abc", "def"), tuple("ghi", "klm")));
updates.add(remove(nodeId++, descriptor, tuple(1001L, 1002L)));
updates.add(change(nodeId++, descriptor, tuple((byte) 2, (byte) 3), tuple((byte) 4, (byte) 5)));
updates.add(add(nodeId, descriptor, tuple(5, "5")));
try (DeferredConflictCheckingIndexUpdater updater = new DeferredConflictCheckingIndexUpdater(actual, () -> reader, descriptor, NULL)) {
// when
for (ValueIndexEntryUpdate<IndexDescriptor> update : updates) {
updater.process(update);
verify(actual).process(update);
}
}
// then
for (ValueIndexEntryUpdate<IndexDescriptor> update : updates) {
if (update.updateMode() == UpdateMode.ADDED || update.updateMode() == UpdateMode.CHANGED) {
Value[] tuple = update.values();
PropertyIndexQuery[] query = new PropertyIndexQuery[tuple.length];
for (int i = 0; i < tuple.length; i++) {
query[i] = PropertyIndexQuery.exact(propertyKeyIds[i], tuple[i]);
}
verify(reader).query(any(), any(), any(), eq(query[0]), eq(query[1]));
}
}
verify(reader).close();
verifyNoMoreInteractions(reader);
}
use of org.neo4j.kernel.api.index.ValueIndexReader in project neo4j by neo4j.
the class NativeIndexAccessorTests method expectIndexOrder.
private static void expectIndexOrder(Value[] allValues, ValueGroup valueGroup, ValueIndexReader reader, IndexOrder supportedOrder, PropertyIndexQuery.RangePredicate<?> supportedQuery) throws IndexNotApplicableKernelException {
Value[] expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == valueGroup).toArray(Value[]::new);
if (supportedOrder == IndexOrder.ASCENDING) {
Arrays.sort(expectedValues, Values.COMPARATOR);
} else if (supportedOrder == IndexOrder.DESCENDING) {
Arrays.sort(expectedValues, Values.COMPARATOR.reversed());
}
SimpleEntityValueClient client = new SimpleEntityValueClient();
reader.query(NULL_CONTEXT, client, constrained(supportedOrder, true), supportedQuery);
int i = 0;
while (client.next()) {
assertEquals(expectedValues[i++], client.values[0], "values in order");
}
assertEquals(i, expectedValues.length, "found all values");
}
use of org.neo4j.kernel.api.index.ValueIndexReader in project neo4j by neo4j.
the class IndexingServiceTest method shouldStillReportInternalIndexStateAsPopulatingWhenConstraintIndexIsDonePopulating.
@Test
void shouldStillReportInternalIndexStateAsPopulatingWhenConstraintIndexIsDonePopulating() throws Exception {
// given
when(accessor.newUpdater(any(IndexUpdateMode.class), any(CursorContext.class))).thenReturn(updater);
ValueIndexReader indexReader = mock(ValueIndexReader.class);
when(accessor.newValueReader()).thenReturn(indexReader);
doAnswer(new NodeIdsIndexReaderQueryAnswer(index)).when(indexReader).query(any(), any(), any(), any());
IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData());
life.start();
// when
IndexDescriptor index = constraintIndexRule(0, labelId, propertyKeyId, PROVIDER_DESCRIPTOR);
indexingService.createIndexes(AUTH_DISABLED, index);
IndexProxy proxy = indexingService.getIndexProxy(index);
// don't wait for index to come ONLINE here since we're testing that it doesn't
verify(populator, timeout(20000)).close(eq(true), any());
try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
updater.process(add(10, "foo"));
}
// then
assertEquals(POPULATING, proxy.getState());
InOrder order = inOrder(populator, accessor, updater);
order.verify(populator).create();
order.verify(populator).close(eq(true), any());
order.verify(accessor).newUpdater(eq(IndexUpdateMode.ONLINE), any());
order.verify(updater).process(add(10, "foo"));
order.verify(updater).close();
}
use of org.neo4j.kernel.api.index.ValueIndexReader in project neo4j by neo4j.
the class IndexingServiceTest method setUp.
@BeforeEach
void setUp() throws IndexNotFoundKernelException {
when(populator.sample(any(CursorContext.class))).thenReturn(new IndexSample());
when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample());
when(storeViewFactory.createTokenIndexStoreView(any())).thenReturn(storeView);
when(storeView.newPropertyAccessor(any(CursorContext.class), any())).thenReturn(propertyAccessor);
ValueIndexReader indexReader = mock(ValueIndexReader.class);
IndexSampler indexSampler = mock(IndexSampler.class);
when(indexSampler.sampleIndex(any())).thenReturn(new IndexSample());
when(indexReader.createSampler()).thenReturn(indexSampler);
when(accessor.newValueReader()).thenReturn(indexReader);
}
use of org.neo4j.kernel.api.index.ValueIndexReader in project neo4j by neo4j.
the class NonUniqueDatabaseIndexPopulatorTest method addUpdates.
@Test
void addUpdates() throws Exception {
populator = newPopulator();
List<IndexEntryUpdate<?>> updates = Arrays.asList(add(1, labelSchemaDescriptor, "foo"), add(2, labelSchemaDescriptor, "bar"), add(42, labelSchemaDescriptor, "bar"));
populator.add(updates, NULL);
index.maybeRefreshBlocking();
try (ValueIndexReader reader = index.getIndexReader();
NodeValueIterator allEntities = new NodeValueIterator()) {
int propertyKeyId = labelSchemaDescriptor.getPropertyId();
reader.query(NULL_CONTEXT, allEntities, unconstrained(), PropertyIndexQuery.exists(propertyKeyId));
assertArrayEquals(new long[] { 1, 2, 42 }, PrimitiveLongCollections.asArray(allEntities));
}
}
Aggregations