Search in sources :

Example 21 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class ConcurrentUpdateIT method populateDbWithConcurrentUpdates.

@Test
void populateDbWithConcurrentUpdates() throws Exception {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
    GraphDatabaseService database = managementService.database(DEFAULT_DATABASE_NAME);
    try {
        RandomValues randomValues = RandomValues.create();
        int counter = 1;
        for (int j = 0; j < 100; j++) {
            try (Transaction transaction = database.beginTx()) {
                for (int i = 0; i < 5; i++) {
                    Node node = transaction.createNode(Label.label("label" + counter));
                    node.setProperty("property", randomValues.nextValue().asObject());
                }
                transaction.commit();
            }
            counter++;
        }
        int populatorCount = 5;
        ExecutorService executor = Executors.newFixedThreadPool(populatorCount);
        CountDownLatch startSignal = new CountDownLatch(1);
        AtomicBoolean endSignal = new AtomicBoolean();
        for (int i = 0; i < populatorCount; i++) {
            executor.submit(new Populator(database, counter, startSignal, endSignal));
        }
        try {
            try (Transaction transaction = database.beginTx()) {
                transaction.schema().indexFor(Label.label("label10")).on("property").create();
                transaction.commit();
            }
            startSignal.countDown();
            try (Transaction transaction = database.beginTx()) {
                transaction.schema().awaitIndexesOnline(populatorCount, TimeUnit.MINUTES);
                transaction.commit();
            }
        } finally {
            endSignal.set(true);
            executor.shutdown();
        // Basically we don't care to await their completion because they've done their job
        }
    } finally {
        managementService.shutdown();
        ConsistencyCheckService consistencyCheckService = new ConsistencyCheckService();
        Config config = Config.defaults(GraphDatabaseSettings.pagecache_memory, "8m");
        consistencyCheckService.runFullConsistencyCheck(databaseLayout, config, ProgressMonitorFactory.NONE, new Log4jLogProvider(System.out), false);
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Config(org.neo4j.configuration.Config) Log4jLogProvider(org.neo4j.logging.log4j.Log4jLogProvider) Node(org.neo4j.graphdb.Node) RandomValues(org.neo4j.values.storable.RandomValues) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) ExecutorService(java.util.concurrent.ExecutorService) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 22 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class IndexPopulationIT method setUp.

@BeforeEach
void setUp() {
    logProvider = new AssertableLogProvider(true);
    managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setInternalLogProvider(logProvider).build();
    database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    executorService = Executors.newCachedThreadPool();
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 23 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class IndexPopulationIT method shutdownDatabaseDuringIndexPopulations.

@Test
void shutdownDatabaseDuringIndexPopulations() {
    AssertableLogProvider assertableLogProvider = new AssertableLogProvider(true);
    Path storeDir = directory.directory("shutdownDbTest");
    Label testLabel = Label.label("testLabel");
    String propertyName = "testProperty";
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).setInternalLogProvider(assertableLogProvider).build();
    GraphDatabaseService shutDownDb = managementService.database(DEFAULT_DATABASE_NAME);
    prePopulateDatabase(shutDownDb, testLabel, propertyName);
    try (Transaction transaction = shutDownDb.beginTx()) {
        transaction.schema().indexFor(testLabel).on(propertyName).create();
        transaction.commit();
    }
    managementService.shutdown();
    assertThat(assertableLogProvider).forClass(IndexPopulationJob.class).forLevel(ERROR).doesNotHaveAnyLogs();
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) Label(org.neo4j.graphdb.Label) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.jupiter.api.Test)

Example 24 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class MultipleIndexPopulationStressIT method populateDbAndIndexes.

private void populateDbAndIndexes(long nodeCount, long relCount) throws InterruptedException {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).build();
    final GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    try {
        try (var tx = db.beginTx();
            var softly = new AutoCloseableSoftAssertions()) {
            softly.assertThat(tx.getAllNodes().stream().count()).as("Number of nodes").isEqualTo(nodeCount);
            softly.assertThat(tx.getAllRelationships().stream().count()).as("Number of relationships").isEqualTo(relCount);
        }
        createIndexes(db);
        final AtomicBoolean end = new AtomicBoolean();
        executor = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            executor.submit(() -> {
                ChangeRandomEntities changeRandomEntities = new ChangeRandomEntities(db, RandomValues.create(), nodeCount, relCount);
                while (!end.get()) {
                    changeRandomEntities.node();
                    changeRandomEntities.relationship();
                }
            });
        }
        while (!indexesAreOnline(db)) {
            Thread.sleep(100);
        }
        end.set(true);
        executor.shutdown();
        executor.awaitTermination(10, SECONDS);
        executor = null;
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) AutoCloseableSoftAssertions(org.assertj.core.api.AutoCloseableSoftAssertions) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 25 with TestDatabaseManagementServiceBuilder

use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.

the class MultipleIndexPopulationStressIT method dropIndexes.

private void dropIndexes() {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(directory.homePath()).setConfig(GraphDatabaseSettings.pagecache_memory, "8m").build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    try (Transaction tx = db.beginTx()) {
        tx.schema().getIndexes().forEach(IndexDefinition::drop);
        tx.commit();
    } finally {
        managementService.shutdown();
    }
    expectingNLI = false;
    expectingRTI = false;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Aggregations

TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)135 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)74 Test (org.junit.jupiter.api.Test)48 Transaction (org.neo4j.graphdb.Transaction)42 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)38 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)30 Path (java.nio.file.Path)23 BeforeEach (org.junit.jupiter.api.BeforeEach)18 Node (org.neo4j.graphdb.Node)18 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)13 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)11 PageCache (org.neo4j.io.pagecache.PageCache)10 UncloseableDelegatingFileSystemAbstraction (org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction)9 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)8 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 TokenIndexProviderFactory (org.neo4j.kernel.impl.index.schema.TokenIndexProviderFactory)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Dependencies (org.neo4j.collection.Dependencies)6 Config (org.neo4j.configuration.Config)6 DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)6