use of org.neo4j.io.memory.ByteBufferFactory 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.io.memory.ByteBufferFactory 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.io.memory.ByteBufferFactory in project neo4j by neo4j.
the class BlockBasedIndexPopulatorTest method shouldAcceptBatchAddedMaxSizeValue.
@Test
void shouldAcceptBatchAddedMaxSizeValue() 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();
GenericLayout layout = layout();
Value value = generateStringValueResultingInIndexEntrySize(layout, size);
Collection<? extends IndexEntryUpdate<?>> data = singletonList(IndexEntryUpdate.add(0, INDEX_DESCRIPTOR, value));
populator.add(data, NULL);
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
// 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);
}
}
Aggregations