Search in sources :

Example 1 with TokenIndexEntryUpdate

use of org.neo4j.storageengine.api.TokenIndexEntryUpdate 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);
}
Also used : TokenIndexEntryUpdate(org.neo4j.storageengine.api.TokenIndexEntryUpdate) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 2 with TokenIndexEntryUpdate

use of org.neo4j.storageengine.api.TokenIndexEntryUpdate 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);
}
Also used : TokenIndexEntryUpdate(org.neo4j.storageengine.api.TokenIndexEntryUpdate) ArrayList(java.util.ArrayList) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 3 with TokenIndexEntryUpdate

use of org.neo4j.storageengine.api.TokenIndexEntryUpdate in project neo4j by neo4j.

the class TokenIndexAccessorTest method shouldAddWithUpdater.

@Test
void shouldAddWithUpdater() throws IndexEntryConflictException, IOException {
    // Give
    MutableLongObjectMap<long[]> entityTokens = LongObjectMaps.mutable.empty();
    List<TokenIndexEntryUpdate<?>> updates = generateSomeRandomUpdates(entityTokens, random);
    // When
    try (IndexUpdater updater = accessor.newUpdater(ONLINE, NULL)) {
        for (TokenIndexEntryUpdate<?> update : updates) {
            updater.process(update);
        }
    }
    // Then
    forceAndCloseAccessor();
    verifyUpdates(entityTokens, layout, this::getTree);
}
Also used : TokenIndexEntryUpdate(org.neo4j.storageengine.api.TokenIndexEntryUpdate) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Test (org.junit.jupiter.api.Test)3 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)3 TokenIndexEntryUpdate (org.neo4j.storageengine.api.TokenIndexEntryUpdate)3 ArrayList (java.util.ArrayList)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1