Search in sources :

Example 1 with ValueIndexReader

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);
}
Also used : ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) Value(org.neo4j.values.storable.Value) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) Test(org.junit.jupiter.api.Test)

Example 2 with ValueIndexReader

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");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IndexOrder(org.neo4j.internal.schema.IndexOrder) Arrays(java.util.Arrays) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Iterators.filter(org.neo4j.internal.helpers.collection.Iterators.filter) NULL_CONTEXT(org.neo4j.internal.kernel.api.QueryContext.NULL_CONTEXT) Value(org.neo4j.values.storable.Value) RandomValues(org.neo4j.values.storable.RandomValues) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) IndexEntryUpdate.remove(org.neo4j.storageengine.api.IndexEntryUpdate.remove) Predicates.alwaysTrue(org.neo4j.function.Predicates.alwaysTrue) EMPTY_LONG_ARRAY(org.neo4j.collection.PrimitiveLongCollections.EMPTY_LONG_ARRAY) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) TestDirectory(org.neo4j.test.rule.TestDirectory) Collectors(java.util.stream.Collectors) PointValue(org.neo4j.values.storable.PointValue) String.format(java.lang.String.format) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) Test(org.junit.jupiter.api.Test) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexQueryConstraints.unconstrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.unconstrained) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) ValueCreatorUtil.countUniqueValues(org.neo4j.kernel.impl.index.schema.ValueCreatorUtil.countUniqueValues) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) IndexCapability(org.neo4j.internal.schema.IndexCapability) IndexDirectoryStructure.directoriesByProvider(org.neo4j.kernel.api.index.IndexDirectoryStructure.directoriesByProvider) Iterables.asUniqueSet(org.neo4j.internal.helpers.collection.Iterables.asUniqueSet) IndexQueryConstraints.unorderedValues(org.neo4j.internal.kernel.api.IndexQueryConstraints.unorderedValues) IndexEntryUpdate.change(org.neo4j.storageengine.api.IndexEntryUpdate.change) Predicates.in(org.neo4j.function.Predicates.in) ArrayList(java.util.ArrayList) Values(org.neo4j.values.storable.Values) HashSet(java.util.HashSet) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IndexSample(org.neo4j.kernel.api.index.IndexSample) Iterator(java.util.Iterator) ValueType(org.neo4j.values.storable.ValueType) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) IndexQueryConstraints.constrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.constrained) PrimitiveLongCollections(org.neo4j.collection.PrimitiveLongCollections) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) LongIterator(org.eclipse.collections.api.iterator.LongIterator) IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) Values.of(org.neo4j.values.storable.Values.of) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) ValueGroup(org.neo4j.values.storable.ValueGroup) Collections(java.util.Collections) ONLINE(org.neo4j.kernel.impl.api.index.IndexUpdateMode.ONLINE) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient)

Example 3 with ValueIndexReader

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();
}
Also used : NodeIdsIndexReaderQueryAnswer(org.neo4j.kernel.impl.index.schema.NodeIdsIndexReaderQueryAnswer) InOrder(org.mockito.InOrder) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 4 with ValueIndexReader

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);
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) CursorContext(org.neo4j.io.pagecache.context.CursorContext) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with ValueIndexReader

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));
    }
}
Also used : NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) Test(org.junit.jupiter.api.Test)

Aggregations

ValueIndexReader (org.neo4j.kernel.api.index.ValueIndexReader)7 Test (org.junit.jupiter.api.Test)5 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)4 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)3 ArrayList (java.util.ArrayList)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)2 CursorContext (org.neo4j.io.pagecache.context.CursorContext)2 IndexSample (org.neo4j.kernel.api.index.IndexSample)2 IndexSampler (org.neo4j.kernel.api.index.IndexSampler)2 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)2 Value (org.neo4j.values.storable.Value)2 String.format (java.lang.String.format)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1