Search in sources :

Example 56 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class BatchingMultipleIndexPopulatorTest method populateFromQueuePopulatesWhenThresholdReached.

@Test
void populateFromQueuePopulatesWhenThresholdReached() throws Exception {
    FullScanStoreView storeView = new FullScanStoreView(LockService.NO_LOCK_SERVICE, () -> mock(StorageReader.class), Config.defaults(), jobScheduler);
    MultipleIndexPopulator batchingPopulator = new MultipleIndexPopulator(storeView, NullLogProvider.getInstance(), EntityType.NODE, mock(SchemaState.class), new CallingThreadJobScheduler(), tokens, NULL, INSTANCE, "", AUTH_DISABLED, Config.defaults(GraphDatabaseInternalSettings.index_population_queue_threshold, 2));
    IndexPopulator populator1 = addPopulator(batchingPopulator, index1);
    IndexUpdater updater1 = mock(IndexUpdater.class);
    when(populator1.newPopulatingUpdater(any(), any())).thenReturn(updater1);
    IndexPopulator populator2 = addPopulator(batchingPopulator, index42);
    IndexUpdater updater2 = mock(IndexUpdater.class);
    when(populator2.newPopulatingUpdater(any(), any())).thenReturn(updater2);
    batchingPopulator.createStoreScan(NULL);
    IndexEntryUpdate<?> update1 = add(1, index1.schema(), "foo");
    IndexEntryUpdate<?> update2 = add(2, index42.schema(), "bar");
    IndexEntryUpdate<?> update3 = add(3, index1.schema(), "baz");
    batchingPopulator.queueConcurrentUpdate(update1);
    batchingPopulator.queueConcurrentUpdate(update2);
    batchingPopulator.queueConcurrentUpdate(update3);
    batchingPopulator.applyExternalUpdates(42);
    verify(updater1).process(update1);
    verify(updater1).process(update3);
    verify(updater2).process(update2);
}
Also used : StorageReader(org.neo4j.storageengine.api.StorageReader) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) FullScanStoreView(org.neo4j.kernel.impl.transaction.state.storeview.FullScanStoreView) SchemaState(org.neo4j.internal.schema.SchemaState) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) CallingThreadJobScheduler(org.neo4j.test.scheduler.CallingThreadJobScheduler) Test(org.junit.jupiter.api.Test)

Example 57 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class ContractCheckingIndexProxyTest method shouldNotUpdateBeforeCreate.

@Test
void shouldNotUpdateBeforeCreate() {
    // GIVEN
    IndexProxy inner = mockIndexProxy();
    IndexProxy outer = newContractCheckingIndexProxy(inner);
    // WHEN
    assertThrows(IllegalStateException.class, () -> {
        try (IndexUpdater updater = outer.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
            updater.process((ValueIndexEntryUpdate<?>) null);
        }
    });
}
Also used : SchemaIndexTestHelper.mockIndexProxy(org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 58 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class ContractCheckingIndexProxyTest method shouldNotUpdateAfterClose.

@Test
void shouldNotUpdateAfterClose() throws Exception {
    // GIVEN
    IndexProxy inner = mockIndexProxy();
    IndexProxy outer = newContractCheckingIndexProxy(inner);
    // WHEN
    outer.start();
    outer.close(NULL);
    assertThrows(IllegalStateException.class, () -> {
        try (IndexUpdater updater = outer.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
            updater.process((ValueIndexEntryUpdate<?>) null);
        }
    });
}
Also used : SchemaIndexTestHelper.mockIndexProxy(org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 59 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class ContractCheckingIndexProxyTest method closeWaitForUpdateToFinish.

@Test
void closeWaitForUpdateToFinish() throws InterruptedException {
    // GIVEN
    CountDownLatch latch = new CountDownLatch(1);
    final IndexProxy inner = new IndexProxyAdapter() {

        @Override
        public IndexUpdater newUpdater(IndexUpdateMode mode, CursorContext cursorContext) {
            return super.newUpdater(mode, cursorContext);
        }
    };
    final IndexProxy outer = newContractCheckingIndexProxy(inner);
    Thread actionThread = createActionThread(() -> outer.close(NULL));
    outer.start();
    // WHEN
    Thread updaterThread = runInSeparateThread(() -> {
        try (IndexUpdater updater = outer.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
            updater.process((ValueIndexEntryUpdate<?>) null);
            try {
                actionThread.start();
                latch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        } catch (IndexEntryConflictException e) {
            throw new RuntimeException(e);
        }
    });
    ThreadTestUtils.awaitThreadState(actionThread, TEST_TIMEOUT, Thread.State.TIMED_WAITING);
    latch.countDown();
    updaterThread.join();
    actionThread.join();
}
Also used : SchemaIndexTestHelper.mockIndexProxy(org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountDownLatch(java.util.concurrent.CountDownLatch) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 60 with IndexUpdater

use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.

the class BatchingMultipleIndexPopulatorTest method populateFromQueueDoesNothingIfThresholdNotReached.

@Test
void populateFromQueueDoesNothingIfThresholdNotReached() throws Exception {
    MultipleIndexPopulator batchingPopulator = new MultipleIndexPopulator(mock(IndexStoreView.class), NullLogProvider.getInstance(), EntityType.NODE, mock(SchemaState.class), new CallingThreadJobScheduler(), tokens, NULL, INSTANCE, "", AUTH_DISABLED, Config.defaults(GraphDatabaseInternalSettings.index_population_queue_threshold, 5));
    IndexPopulator populator = addPopulator(batchingPopulator, index1);
    IndexUpdater updater = mock(IndexUpdater.class);
    when(populator.newPopulatingUpdater(any(), any())).thenReturn(updater);
    IndexEntryUpdate<?> update1 = add(1, index1.schema(), "foo");
    IndexEntryUpdate<?> update2 = add(2, index1.schema(), "bar");
    batchingPopulator.queueConcurrentUpdate(update1);
    batchingPopulator.queueConcurrentUpdate(update2);
    assertThat(batchingPopulator.needToApplyExternalUpdates()).isFalse();
    verify(updater, never()).process(any(ValueIndexEntryUpdate.class));
    verify(populator, never()).newPopulatingUpdater(any(), any());
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) SchemaState(org.neo4j.internal.schema.SchemaState) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) CallingThreadJobScheduler(org.neo4j.test.scheduler.CallingThreadJobScheduler) Test(org.junit.jupiter.api.Test)

Aggregations

IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)94 Test (org.junit.jupiter.api.Test)61 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)22 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)13 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)9 Value (org.neo4j.values.storable.Value)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)7 CursorContext (org.neo4j.io.pagecache.context.CursorContext)7 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)6 SwallowingIndexUpdater (org.neo4j.kernel.impl.api.index.SwallowingIndexUpdater)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Transaction (org.neo4j.graphdb.Transaction)4 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)4 SchemaIndexTestHelper.mockIndexProxy (org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy)4 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)4 HashMap (java.util.HashMap)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3