Search in sources :

Example 41 with TestDatabaseManagementServiceBuilder

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

the class TestLogPruning method newDb.

private GraphDatabaseAPI newDb(String logPruning, int rotateEveryNTransactions) {
    this.rotateEveryNTransactions = rotateEveryNTransactions;
    fs = new EphemeralFileSystemAbstraction();
    TestDatabaseManagementServiceBuilder gdf = new TestDatabaseManagementServiceBuilder();
    gdf.setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs));
    DatabaseManagementServiceBuilder builder = gdf.impermanent();
    builder.setConfig(keep_logical_logs, logPruning);
    managementService = builder.build();
    this.db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    files = db.getDependencyResolver().resolveDependency(LogFiles.class);
    return db;
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) EphemeralFileSystemAbstraction(org.neo4j.io.fs.EphemeralFileSystemAbstraction) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) UncloseableDelegatingFileSystemAbstraction(org.neo4j.io.fs.UncloseableDelegatingFileSystemAbstraction)

Example 42 with TestDatabaseManagementServiceBuilder

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

the class KernelDiagnosticsIT method createIndexInIsolatedDbInstance.

private static void createIndexInIsolatedDbInstance(Path homeDir, GraphDatabaseSettings.SchemaIndex index) {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(homeDir).setConfig(GraphDatabaseSettings.default_schema_provider, index.providerName()).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    try {
        Label label = Label.label("Label-" + index.providerName());
        String key = "key";
        try (Transaction tx = db.beginTx()) {
            for (int i = 0; i < 100; i++) {
                tx.createNode(label).setProperty(key, i);
            }
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            tx.schema().indexFor(label).on(key).create();
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            tx.schema().awaitIndexesOnline(2, MINUTES);
            tx.commit();
        }
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) Label(org.neo4j.graphdb.Label) ByteUnit.bytesToString(org.neo4j.io.ByteUnit.bytesToString) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 43 with TestDatabaseManagementServiceBuilder

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

the class TestRecoveryRelationshipTypes method recoverNeoAndHavingAllRelationshipTypesAfterRecovery.

@Test
void recoverNeoAndHavingAllRelationshipTypesAfterRecovery() throws Exception {
    // Given (create transactions and kill process, leaving it needing for recovery)
    Path storeDir = testDirectory.homePath();
    Process process = start(getClass().getName(), storeDir.toAbsolutePath().toString());
    assertEquals(0, process.waitFor());
    // When
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    // Then
    try (Transaction transaction = db.beginTx()) {
        Iterator<RelationshipType> typeResourceIterator = transaction.getAllRelationshipTypes().iterator();
        assertEquals(MyRelTypes.TEST.name(), typeResourceIterator.next().name());
    } finally {
        managementService.shutdown();
    }
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) RelationshipType(org.neo4j.graphdb.RelationshipType) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 44 with TestDatabaseManagementServiceBuilder

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

the class FileWatchIT method setUp.

@BeforeEach
void setUp() {
    logProvider = new AssertableLogProvider();
    managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setInternalLogProvider(logProvider).build();
    database = managementService.database(DEFAULT_DATABASE_NAME);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 45 with TestDatabaseManagementServiceBuilder

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

the class FileLockerTest method mustPreventMultipleInstancesFromStartingOnSameStore.

@Test
void mustPreventMultipleInstancesFromStartingOnSameStore() {
    Path storeDir = testDirectory.homePath();
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(storeDir).build();
    try {
        GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
        try (Transaction tx = db.beginTx()) {
            tx.createNode();
            tx.commit();
        }
        assertThrows(Exception.class, () -> {
            new TestDatabaseManagementServiceBuilder(storeDir).build();
        });
    } finally {
        managementService.shutdown();
    }
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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