Search in sources :

Example 71 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class DumpCommandIT method putStoreInDirectory.

private void putStoreInDirectory(Config config, Path databaseDirectory) {
    String databaseName = databaseDirectory.getFileName().toString();
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseDirectory.getParent().getParent().getParent()).setConfig(config).setConfig(default_database, databaseName).build();
    managementService.shutdown();
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 72 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class MemoryRecommendationsCommandTest method createDatabaseWithNativeIndexes.

private static void createDatabaseWithNativeIndexes(Path homeDirectory, String databaseName) {
    // Create one index for every provider that we have
    for (SchemaIndex schemaIndex : SchemaIndex.values()) {
        DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(homeDirectory).setConfig(default_schema_provider, schemaIndex.providerName()).setConfig(default_database, databaseName).build();
        GraphDatabaseService db = managementService.database(databaseName);
        String key = "key-" + schemaIndex.name();
        try {
            Label labelOne = Label.label("one");
            try (Transaction tx = db.beginTx()) {
                tx.schema().indexFor(labelOne).on(key).create();
                tx.commit();
            }
            try (Transaction tx = db.beginTx()) {
                RandomValues randomValues = RandomValues.create();
                for (int i = 0; i < 10_000; i++) {
                    tx.createNode(labelOne).setProperty(key, randomValues.nextValue().asObject());
                }
                tx.commit();
            }
        } finally {
            managementService.shutdown();
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) SchemaIndex(org.neo4j.configuration.GraphDatabaseSettings.SchemaIndex) Label(org.neo4j.graphdb.Label) RandomValues(org.neo4j.values.storable.RandomValues) MemoryRecommendationsCommand.bytesToString(org.neo4j.commandline.dbms.MemoryRecommendationsCommand.bytesToString) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 73 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class PushToCloudCommandTest method createDbAndDump.

private void createDbAndDump() {
    Config config = Config.newBuilder().set(GraphDatabaseSettings.neo4j_home, homeDir.toAbsolutePath()).set(default_database, DBNAME).build();
    DatabaseLayout databaseLayout = DatabaseLayout.of(config);
    Neo4jLayout neo4jLayout = databaseLayout.getNeo4jLayout();
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(neo4jLayout.homeDirectory()).setConfig(config).build();
    managementService.database(databaseLayout.getDatabaseName());
    managementService.shutdown();
    dump = directory.file("some-archive.dump");
    new RealDumpCreator(ctx).dumpDatabase(DBNAME, dump);
}
Also used : TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Config(org.neo4j.configuration.Config) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Neo4jLayout(org.neo4j.io.layout.Neo4jLayout) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 74 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class IndexConfigMigrationIT method shouldHaveCorrectDataAndIndexConfiguration.

@Test
void shouldHaveCorrectDataAndIndexConfiguration() throws IOException, IndexNotFoundKernelException {
    Path databaseDir = databaseLayout.databaseDirectory();
    unzip(getClass(), ZIP_FILE_3_5, databaseDir);
    // when
    DatabaseManagementServiceBuilder builder = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setConfig(GraphDatabaseSettings.allow_upgrade, true);
    DatabaseManagementService dbms = builder.build();
    try {
        GraphDatabaseAPI db = (GraphDatabaseAPI) dbms.database(DEFAULT_DATABASE_NAME);
        Set<CoordinateReferenceSystem> allCRS = Iterables.asSet(all());
        try (Transaction tx = db.beginTx()) {
            validateIndexes(tx);
            for (Node node : tx.getAllNodes()) {
                hasLabels(node, label1, label2, label3, label4);
                Object property = node.getProperty(propKey);
                if (property instanceof PointValue) {
                    allCRS.remove(((PointValue) property).getCoordinateReferenceSystem());
                }
            }
            assertTrue(allCRS.isEmpty(), "Expected all CRS to be represented in store, but missing " + allCRS);
            assertIndexConfiguration(db, tx);
            assertFulltextIndexConfiguration(db, tx);
            tx.commit();
        }
    } finally {
        dbms.shutdown();
    }
    // Assert old index files has been removed
    Path baseSchemaIndexFolder = IndexDirectoryStructure.baseSchemaIndexFolder(databaseDir);
    Set<Path> retiredIndexProviderDirectories = Set.of(baseSchemaIndexFolder.resolve("lucene"), baseSchemaIndexFolder.resolve("lucene-1.0"), baseSchemaIndexFolder.resolve("lucene_native-1.0"), baseSchemaIndexFolder.resolve("lucene_native-2.0"));
    try (Stream<Path> list = Files.list(baseSchemaIndexFolder)) {
        list.forEach(indexProviderDirectory -> assertFalse(retiredIndexProviderDirectories.contains(indexProviderDirectory), "Expected old index provider directories to be deleted during migration but store still had directory " + indexProviderDirectory));
    }
}
Also used : Path(java.nio.file.Path) PointValue(org.neo4j.values.storable.PointValue) Node(org.neo4j.graphdb.Node) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 75 with DatabaseManagementService

use of org.neo4j.dbms.api.DatabaseManagementService in project neo4j by neo4j.

the class IndexSamplingIntegrationTest method fetchIndexSamplingValues.

private IndexSample fetchIndexSamplingValues() throws IndexNotFoundKernelException, TransactionFailureException {
    DatabaseManagementService managementService = null;
    try {
        // Then
        managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
        GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
        GraphDatabaseAPI api = (GraphDatabaseAPI) db;
        Kernel kernel = api.getDependencyResolver().resolveDependency(Kernel.class);
        try (KernelTransaction tx = kernel.beginTransaction(EXPLICIT, AUTH_DISABLED)) {
            return tx.schemaRead().indexSample(indexId(tx));
        }
    } finally {
        if (managementService != null) {
            managementService.shutdown();
        }
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Kernel(org.neo4j.kernel.api.Kernel)

Aggregations

DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)155 Test (org.junit.jupiter.api.Test)100 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)79 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)61 Transaction (org.neo4j.graphdb.Transaction)60 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)56 Path (java.nio.file.Path)37 Node (org.neo4j.graphdb.Node)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Label (org.neo4j.graphdb.Label)16 MethodSource (org.junit.jupiter.params.provider.MethodSource)10 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)9 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)9 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)8 Config (org.neo4j.configuration.Config)7 DatabaseManagementServiceBuilder (org.neo4j.dbms.api.DatabaseManagementServiceBuilder)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 GBPTreeCountsStore (org.neo4j.internal.counts.GBPTreeCountsStore)6 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)6 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)6