use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class NativeIndexProviderTest method shouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor.
@Test
void shouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor() throws IOException, IndexEntryConflictException {
// given
Value someValue = Values.of(1);
provider = newProvider();
// when
IndexDescriptor descriptor = descriptorUnique();
try (IndexAccessor accessor = provider.getOnlineAccessor(descriptor, samplingConfig(), tokenNameLookup);
IndexUpdater indexUpdater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
indexUpdater.process(IndexEntryUpdate.add(1, descriptor.schema(), someValue));
// then
// ... expect no failure on duplicate value
indexUpdater.process(IndexEntryUpdate.add(2, descriptor.schema(), someValue));
}
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class TokenIndexPopulatorTest method updaterShouldApplyUpdates.
@Test
void updaterShouldApplyUpdates() throws Exception {
// Give
MutableLongObjectMap<long[]> entityTokens = LongObjectMaps.mutable.empty();
populator.create();
List<TokenIndexEntryUpdate<?>> updates = TokenIndexUtility.generateSomeRandomUpdates(entityTokens, random);
try (IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL)) {
for (TokenIndexEntryUpdate<?> update : updates) {
updater.process(update);
}
}
// then
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
populator.close(true, NULL);
TokenIndexUtility.verifyUpdates(entityTokens, layout, this::getTree);
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class TokenIndexPopulatorTest method shouldHandleInterleavedRandomizedUpdates.
@Test
void shouldHandleInterleavedRandomizedUpdates() throws IndexEntryConflictException, IOException {
// Give
int numberOfEntities = 1_000;
long currentScanId = 0;
MutableLongObjectMap<long[]> entityTokens = LongObjectMaps.mutable.empty();
populator.create();
while (currentScanId < numberOfEntities) {
// Collect a batch of max 100 updates from scan
List<TokenIndexEntryUpdate<?>> updates = new ArrayList<>();
for (int i = 0; i < 100 && currentScanId < numberOfEntities; i++) {
TokenIndexUtility.generateRandomUpdate(currentScanId, entityTokens, updates, random);
// Advance scan
currentScanId++;
}
// Add updates to populator
populator.add(updates, NULL);
// Interleave external updates in id range lower than currentScanId
try (IndexUpdater updater = populator.newPopulatingUpdater(NodePropertyAccessor.EMPTY, NULL)) {
for (int i = 0; i < 100; i++) {
long entityId = random.nextLong(currentScanId);
// Current tokens for the entity in the tree
long[] beforeTokens = entityTokens.get(entityId);
if (beforeTokens == null) {
beforeTokens = EMPTY_LONG_ARRAY;
}
long[] afterTokens = TokenIndexUtility.generateRandomTokens(random);
entityTokens.put(entityId, Arrays.copyOf(afterTokens, afterTokens.length));
updater.process(IndexEntryUpdate.change(entityId, null, beforeTokens, afterTokens));
}
}
}
populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
populator.close(true, NULL);
TokenIndexUtility.verifyUpdates(entityTokens, layout, this::getTree);
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class FusionIndexUpdaterTest method initiateMocks.
private void initiateMocks() {
IndexSlot[] activeSlots = fusionVersion.aliveSlots();
updaters = new EnumMap<>(IndexSlot.class);
fill(updaters, SwallowingIndexUpdater.INSTANCE);
aliveUpdaters = new IndexUpdater[activeSlots.length];
for (int i = 0; i < activeSlots.length; i++) {
IndexUpdater mock = mock(IndexUpdater.class);
aliveUpdaters[i] = mock;
switch(activeSlots[i]) {
case GENERIC:
updaters.put(GENERIC, mock);
break;
case LUCENE:
updaters.put(LUCENE, mock);
break;
default:
throw new RuntimeException();
}
}
fusionIndexUpdater = new FusionIndexUpdater(fusionVersion.slotSelector(), new LazyInstanceSelector<>(updaters, throwingFactory()));
}
use of org.neo4j.kernel.api.index.IndexUpdater in project neo4j by neo4j.
the class FusionIndexUpdaterTest method closeMustCloseOthersIfAnyThrow.
@Test
void closeMustCloseOthersIfAnyThrow() throws Exception {
for (IndexSlot indexSlot : fusionVersion.aliveSlots()) {
IndexUpdater failingUpdater = updaters.get(indexSlot);
FusionIndexTestHelp.verifyOtherIsClosedOnSingleThrow(failingUpdater, fusionIndexUpdater, without(aliveUpdaters, failingUpdater));
initiateMocks();
}
}
Aggregations