Search in sources :

Example 61 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.

the class IndexingServiceIntegrationTest method dropIndexDirectlyOnIndexingServiceRaceWithCheckpoint.

@ParameterizedTest
@MethodSource("parameters")
void dropIndexDirectlyOnIndexingServiceRaceWithCheckpoint(GraphDatabaseSettings.SchemaIndex schemaIndex) throws Throwable {
    setUp(schemaIndex);
    IndexingService indexingService = getIndexingService(database);
    CheckPointer checkPointer = getCheckPointer(database);
    IndexDescriptor indexDescriptor;
    try (Transaction tx = database.beginTx()) {
        IndexDefinitionImpl indexDefinition = (IndexDefinitionImpl) tx.schema().indexFor(Label.label("label")).on("prop").create();
        indexDescriptor = indexDefinition.getIndexReference();
        tx.commit();
    }
    try (Transaction tx = database.beginTx()) {
        tx.schema().awaitIndexesOnline(1, TimeUnit.HOURS);
        tx.commit();
    }
    Race race = new Race();
    race.addContestant(Race.throwing(() -> checkPointer.forceCheckPoint(new SimpleTriggerInfo("Test force"))));
    race.addContestant(Race.throwing(() -> indexingService.dropIndex(indexDescriptor)));
    race.go();
}
Also used : SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Race(org.neo4j.test.Race) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexDefinitionImpl(org.neo4j.kernel.impl.coreapi.schema.IndexDefinitionImpl) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 62 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.

the class FulltextIndexTransactionStateTest method queryResultsMustIncludeOldPropertyValuesWhenRemovalsAreUndone.

@MethodSource("entityTypeProvider")
@ParameterizedTest
void queryResultsMustIncludeOldPropertyValuesWhenRemovalsAreUndone(EntityUtil entityUtil) {
    createIndexAndWait(entityUtil);
    long entityId;
    try (Transaction tx = db.beginTx()) {
        entityId = entityUtil.createEntityWithProperty(tx, "primo");
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        entityUtil.assertQueryFindsIdsInOrder(tx, "primo", entityId);
        Entity entity = entityUtil.getEntity(tx, entityId);
        entity.removeProperty(PROP);
        entityUtil.assertQueryFindsIdsInOrder(tx, "primo");
        entity.setProperty(PROP, "primo");
        entityUtil.assertQueryFindsIdsInOrder(tx, "primo", entityId);
        tx.commit();
    }
}
Also used : Entity(org.neo4j.graphdb.Entity) Transaction(org.neo4j.graphdb.Transaction) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 63 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.

the class FulltextIndexTransactionStateTest method queryingIndexInPopulatingStateMustBlockUntilIndexIsOnlineEvenWhenTransactionHasState.

@MethodSource("entityTypeProvider")
@ParameterizedTest
void queryingIndexInPopulatingStateMustBlockUntilIndexIsOnlineEvenWhenTransactionHasState(EntityUtil entityUtil) throws InterruptedException {
    trapPopulation.set(true);
    try (Transaction tx = db.beginTx()) {
        entityUtil.createEntityWithProperty(tx, "value");
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        entityUtil.createIndex(tx);
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        entityUtil.createEntityWithProperty(tx, "value");
        try (var resultStream = entityUtil.queryIndex(tx, "value").stream()) {
            populationScanFinished.await();
            populationScanFinished.release();
            assertThat(resultStream.count()).isEqualTo(2);
        }
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 64 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.

the class FulltextIndexTransactionStateTest method fulltextIndexMustWorkAfterRestartWithTxStateChanges.

@MethodSource("entityTypeProvider")
@ParameterizedTest
void fulltextIndexMustWorkAfterRestartWithTxStateChanges(EntityUtil entityUtil) {
    createIndexAndWait(entityUtil);
    restartDatabase();
    try (Transaction tx = db.beginTx()) {
        // create an indexed entity ...
        long id = entityUtil.createEntityWithProperty(tx, "value");
        // ... and not indexed one
        entityUtil.createEntity(tx);
        entityUtil.assertQueryFindsIdsInOrder(tx, "*", id);
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 65 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project neo4j by neo4j.

the class BTreeIndexKeySizeValidationIT method shouldEnforceSizeCapSingleValueSingleType.

/**
 * Key size validation test for single type.
 *
 * Validate that we handle index reads and writes correctly for dynamically sized values (arrays and strings)
 * of all different types with length close to and over the max limit for given type.
 *
 * We do this by inserting arrays of increasing size (doubling each iteration) and when we hit the upper limit
 * we do binary search between the established min and max limit.
 * We also verify that the largest successful array length for each type is as expected because this value
 * is documented and if it changes, documentation also needs to change.
 */
@ParameterizedTest
@MethodSource("pageSizes")
void shouldEnforceSizeCapSingleValueSingleType(int pageSize) {
    startDb(pageSize);
    List<String> failureMessages = new ArrayList<>();
    NamedDynamicValueGenerator[] dynamicValueGenerators = NamedDynamicValueGenerator.values();
    for (NamedDynamicValueGenerator generator : dynamicValueGenerators) {
        int expectedMax = pageSize == PAGE_SIZE_16K ? generator.expectedMax16k : generator.expectedMax;
        String propKey = PROP_KEYS[0] + generator.name();
        createIndex(propKey);
        BinarySearch binarySearch = new BinarySearch();
        Object propValue;
        while (!binarySearch.finished()) {
            propValue = generator.dynamicValue(random, binarySearch.arrayLength);
            long expectedNodeId = -1;
            // Write
            boolean wasAbleToWrite = true;
            try (Transaction tx = db.beginTx()) {
                Node node = tx.createNode(LABEL_ONE);
                node.setProperty(propKey, propValue);
                expectedNodeId = node.getId();
                tx.commit();
            } catch (Exception e) {
                wasAbleToWrite = false;
            }
            // Read
            verifyReadExpected(propKey, propValue, expectedNodeId, wasAbleToWrite);
            // Progress binary search
            binarySearch.progress(wasAbleToWrite);
        }
        if (expectedMax != binarySearch.longestSuccessful) {
            failureMessages.add(generator.name() + ": expected=" + expectedMax + ", actual=" + binarySearch.longestSuccessful);
        }
    }
    if (failureMessages.size() > 0) {
        StringJoiner joiner = new StringJoiner(System.lineSeparator(), "Some value types did not have expected longest successful array. " + "This is a strong indicator that documentation of max limit needs to be updated." + System.lineSeparator(), "");
        for (String failureMessage : failureMessages) {
            joiner.add(failureMessage);
        }
        fail(joiner.toString());
    }
}
Also used : Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) Transaction(org.neo4j.graphdb.Transaction) StringJoiner(java.util.StringJoiner) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

MethodSource (org.junit.jupiter.params.provider.MethodSource)1199 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1184 Transaction (org.neo4j.graphdb.Transaction)103 Stream (java.util.stream.Stream)70 Test (org.junit.jupiter.api.Test)67 ArrayList (java.util.ArrayList)63 InterruptAfter (io.aeron.test.InterruptAfter)60 List (java.util.List)60 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)58 TimeUnit (java.util.concurrent.TimeUnit)54 IOException (java.io.IOException)52 CountDownLatch (java.util.concurrent.CountDownLatch)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)52 lombok.val (lombok.val)52 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)51 Arguments (org.junit.jupiter.params.provider.Arguments)47 AfterEach (org.junit.jupiter.api.AfterEach)46 SSLEngine (javax.net.ssl.SSLEngine)44 AtomicReference (java.util.concurrent.atomic.AtomicReference)43 Path (java.nio.file.Path)42