Search in sources :

Example 1 with CallingThreadJobScheduler

use of org.neo4j.test.scheduler.CallingThreadJobScheduler 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 2 with CallingThreadJobScheduler

use of org.neo4j.test.scheduler.CallingThreadJobScheduler in project neo4j by neo4j.

the class BatchingMultipleIndexPopulatorTest method pendingBatchesFlushedAfterStoreScan.

@Test
void pendingBatchesFlushedAfterStoreScan() throws Exception {
    Update update1 = nodeUpdate(1, propertyId, "foo", labelId);
    Update update2 = nodeUpdate(2, propertyId, "bar", labelId);
    Update update3 = nodeUpdate(3, propertyId, "baz", labelId);
    Update update42 = nodeUpdate(4, 42, "42", 42);
    IndexStoreView storeView = newStoreView(update1, update2, update3, update42);
    MultipleIndexPopulator batchingPopulator = new MultipleIndexPopulator(storeView, NullLogProvider.getInstance(), EntityType.NODE, mock(SchemaState.class), new CallingThreadJobScheduler(), tokens, NULL, INSTANCE, "", AUTH_DISABLED, Config.defaults());
    IndexPopulator populator1 = addPopulator(batchingPopulator, index1);
    IndexPopulator populator42 = addPopulator(batchingPopulator, index42);
    batchingPopulator.createStoreScan(NULL).run(NO_EXTERNAL_UPDATES);
    verify(populator1).add(eq(forUpdates(index1, update1, update2, update3)), any());
    verify(populator42).add(eq(forUpdates(index42, update42)), any());
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) SchemaState(org.neo4j.internal.schema.SchemaState) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) CallingThreadJobScheduler(org.neo4j.test.scheduler.CallingThreadJobScheduler) Test(org.junit.jupiter.api.Test)

Example 3 with CallingThreadJobScheduler

use of org.neo4j.test.scheduler.CallingThreadJobScheduler 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

Test (org.junit.jupiter.api.Test)3 SchemaState (org.neo4j.internal.schema.SchemaState)3 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)3 CallingThreadJobScheduler (org.neo4j.test.scheduler.CallingThreadJobScheduler)3 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)2 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)2 FullScanStoreView (org.neo4j.kernel.impl.transaction.state.storeview.FullScanStoreView)1 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)1 StorageReader (org.neo4j.storageengine.api.StorageReader)1