use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class GenericBlockBasedIndexPopulatorTest method shouldThrowOnDuplicatedValuesFromExternalUpdates.
@Test
void shouldThrowOnDuplicatedValuesFromExternalUpdates() throws IOException {
// given
BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(UNIQUE_INDEX_DESCRIPTOR);
try {
// when
Value duplicate = Values.of("duplicate");
ValueIndexEntryUpdate<?> firstExternalUpdate = ValueIndexEntryUpdate.add(1, INDEX_DESCRIPTOR, duplicate);
ValueIndexEntryUpdate<?> secondExternalUpdate = ValueIndexEntryUpdate.add(2, INDEX_DESCRIPTOR, duplicate);
assertThrows(IndexEntryConflictException.class, () -> {
try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
updater.process(firstExternalUpdate);
updater.process(secondExternalUpdate);
}
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
});
} finally {
populator.close(true, NULL);
}
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class IndexAccessorTests method shouldHandleCloseWithoutCallsToProcess.
@Test
void shouldHandleCloseWithoutCallsToProcess() throws Exception {
// given
IndexUpdater updater = accessor.newUpdater(ONLINE, NULL);
// when
updater.close();
// then
// ... should be fine
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class BlockBasedIndexPopulatorTest method shouldFailOnUpdatedTooLargeValue.
@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldFailOnUpdatedTooLargeValue(boolean updateBeforeScanCompleted) throws IndexEntryConflictException, IOException {
// / given
ByteBufferFactory bufferFactory = new ByteBufferFactory(UnsafeDirectByteBufferAllocator::new, SUFFICIENTLY_LARGE_BUFFER_SIZE);
BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR, bufferFactory, INSTANCE);
try {
int size = populator.tree.keyValueSizeCap() + 1;
if (!updateBeforeScanCompleted) {
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
}
assertThrows(IllegalArgumentException.class, () -> {
try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
updater.process(IndexEntryUpdate.add(0, INDEX_DESCRIPTOR, generateStringValueResultingInIndexEntrySize(layout(), size)));
}
});
} finally {
populator.close(false, NULL);
}
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class BlockBasedIndexPopulatorTest method shouldAcceptUpdatedMaxSizeValue.
@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldAcceptUpdatedMaxSizeValue(boolean updateBeforeScanCompleted) throws Throwable {
// given
ByteBufferFactory bufferFactory = new ByteBufferFactory(UnsafeDirectByteBufferAllocator::new, SUFFICIENTLY_LARGE_BUFFER_SIZE);
BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR, bufferFactory, INSTANCE);
try {
int size = populator.tree.keyValueSizeCap();
GenericLayout layout = layout();
Value value = generateStringValueResultingInIndexEntrySize(layout, size);
IndexEntryUpdate<IndexDescriptor> update = IndexEntryUpdate.add(0, INDEX_DESCRIPTOR, value);
Race.ThrowingRunnable updateAction = () -> {
try (IndexUpdater updater = populator.newPopulatingUpdater(NULL)) {
updater.process(update);
}
};
if (updateBeforeScanCompleted) {
updateAction.run();
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
} else {
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
updateAction.run();
}
// when
try (Seeker<GenericKey, NativeIndexValue> seek = seek(populator.tree, layout)) {
// then
assertTrue(seek.next());
assertEquals(value, seek.key().asValue());
assertFalse(seek.next());
}
} finally {
populator.close(true, NULL);
}
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class NativeIndexAccessorTests method shouldIndexAdd.
@Test
void shouldIndexAdd() throws Exception {
// given
ValueIndexEntryUpdate<IndexDescriptor>[] updates = someUpdatesSingleType();
try (IndexUpdater updater = accessor.newUpdater(ONLINE, NULL)) {
// when
processAll(updater, updates);
}
// then
forceAndCloseAccessor();
valueUtil.verifyUpdates(updates, this::getTree);
}
Aggregations