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);
}
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);
}
});
}
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);
}
});
}
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();
}
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());
}
Aggregations