Search in sources :

Example 21 with DatabaseManagementService

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

the class ImportCommandTest method assertTokenIndexesCreated.

private void assertTokenIndexesCreated() {
    DatabaseManagementService dbms = dbmsService();
    try (var tx = dbms.database(DEFAULT_DATABASE_NAME).beginTx()) {
        var indexes = stream(tx.schema().getIndexes().spliterator(), false).collect(toList());
        assertThat(indexes.stream().filter(index -> index.getIndexType() == LOOKUP).count()).isEqualTo(2);
        assertTrue(indexes.stream().anyMatch(IndexDefinition::isNodeIndex));
        assertTrue(indexes.stream().anyMatch(IndexDefinition::isRelationshipIndex));
    } finally {
        dbms.shutdown();
    }
}
Also used : Arrays(java.util.Arrays) ResourceIterator(org.neo4j.graphdb.ResourceIterator) Direction(org.neo4j.graphdb.Direction) Config(org.neo4j.configuration.Config) InputException(org.neo4j.internal.batchimport.input.InputException) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Path(java.nio.file.Path) Standard(org.neo4j.kernel.impl.store.format.standard.Standard) Set(java.util.Set) RelationshipType.withName(org.neo4j.graphdb.RelationshipType.withName) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock) StandardCharsets(java.nio.charset.StandardCharsets) Collectors.joining(java.util.stream.Collectors.joining) ExecutionContext(org.neo4j.cli.ExecutionContext) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) StreamSupport.stream(java.util.stream.StreamSupport.stream) StoreType(org.neo4j.kernel.impl.store.StoreType) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MissingParameterException(picocli.CommandLine.MissingParameterException) RelationshipType(org.neo4j.graphdb.RelationshipType) SuppressOutput(org.neo4j.test.rule.SuppressOutput) LOOKUP(org.neo4j.graphdb.schema.IndexType.LOOKUP) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ParameterException(picocli.CommandLine.ParameterException) Node(org.neo4j.graphdb.Node) ArrayList(java.util.ArrayList) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) String.join(java.lang.String.join) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Exceptions.withMessage(org.neo4j.internal.helpers.Exceptions.withMessage) COMMAS(org.neo4j.csv.reader.Configuration.COMMAS) Files(java.nio.file.Files) Iterators(org.neo4j.internal.helpers.collection.Iterators) MapUtil.store(org.neo4j.internal.helpers.collection.MapUtil.store) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) Iterables.asList(org.neo4j.internal.helpers.collection.Iterables.asList) IOException(java.io.IOException) Label.label(org.neo4j.graphdb.Label.label) AfterEach(org.junit.jupiter.api.AfterEach) IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) IllegalMultilineFieldException(org.neo4j.csv.reader.IllegalMultilineFieldException) MutableInt(org.apache.commons.lang3.mutable.MutableInt) Validator(org.neo4j.common.Validator) Exceptions.contains(org.neo4j.internal.helpers.Exceptions.contains) RandomExtension(org.neo4j.test.extension.RandomExtension) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Iterators.count(org.neo4j.internal.helpers.collection.Iterators.count) IntPredicate(java.util.function.IntPredicate) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RandomRule(org.neo4j.test.rule.RandomRule) FALSE(org.neo4j.configuration.SettingValueParsers.FALSE) Iterables.single(org.neo4j.internal.helpers.collection.Iterables.single) Transaction(org.neo4j.graphdb.Transaction) Resources(org.junit.jupiter.api.parallel.Resources) GraphDatabaseInternalSettings.databases_root_path(org.neo4j.configuration.GraphDatabaseInternalSettings.databases_root_path) CommandLine(picocli.CommandLine) GraphDatabaseSettings.default_database(org.neo4j.configuration.GraphDatabaseSettings.default_database) Type(org.neo4j.internal.batchimport.input.csv.Type) Predicate(java.util.function.Predicate) TestDirectory(org.neo4j.test.rule.TestDirectory) UUID(java.util.UUID) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) Neo4jLayoutExtension(org.neo4j.test.extension.Neo4jLayoutExtension) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) List(java.util.List) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Label(org.neo4j.graphdb.Label) System.lineSeparator(java.lang.System.lineSeparator) MapUtil.stringMap(org.neo4j.internal.helpers.collection.MapUtil.stringMap) System.currentTimeMillis(java.lang.System.currentTimeMillis) GraphDatabaseSettings.transaction_logs_root_path(org.neo4j.configuration.GraphDatabaseSettings.transaction_logs_root_path) HashMap(java.util.HashMap) SuppressOutputExtension(org.neo4j.test.extension.SuppressOutputExtension) FileUtils.writeToFile(org.neo4j.io.fs.FileUtils.writeToFile) GraphDatabaseSettings.preallocate_logical_logs(org.neo4j.configuration.GraphDatabaseSettings.preallocate_logical_logs) HashSet(java.util.HashSet) Configuration(org.neo4j.csv.reader.Configuration) Charset(java.nio.charset.Charset) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Inject(org.neo4j.test.extension.Inject) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Iterables(org.neo4j.internal.helpers.collection.Iterables) DuplicateInputIdException(org.neo4j.internal.batchimport.cache.idmapping.string.DuplicateInputIdException) GraphDatabaseInternalSettings(org.neo4j.configuration.GraphDatabaseInternalSettings) PrintStream(java.io.PrintStream) Validators(org.neo4j.kernel.impl.util.Validators) Iterator(java.util.Iterator) PrefetchingIterator(org.neo4j.internal.helpers.collection.PrefetchingIterator) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) GraphDatabaseSettings.store_internal_log_path(org.neo4j.configuration.GraphDatabaseSettings.store_internal_log_path) Collectors.toList(java.util.stream.Collectors.toList) Relationship(org.neo4j.graphdb.Relationship) Iterators.asSet(org.neo4j.internal.helpers.collection.Iterators.asSet) GraphDatabaseSettings.neo4j_home(org.neo4j.configuration.GraphDatabaseSettings.neo4j_home) Collections(java.util.Collections) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 22 with DatabaseManagementService

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

the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT method createIndexDataAndShutdown.

private static void createIndexDataAndShutdown(DatabaseManagementServiceBuilder builder, String indexProvider, Label label, Consumer<GraphDatabaseService> otherActions) {
    builder.setConfig(GraphDatabaseSettings.default_schema_provider, indexProvider);
    DatabaseManagementService dbms = builder.build();
    try {
        GraphDatabaseService db = dbms.database(DEFAULT_DATABASE_NAME);
        otherActions.accept(db);
        createIndexData(db, label);
    } finally {
        dbms.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 23 with DatabaseManagementService

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

the class IndexConfigMigrationIT method create3_5Database.

@Disabled("Here as reference for how 3.5 db was created")
@Test
void create3_5Database() throws Exception {
    Path storeDir = tempStoreDirectory();
    DatabaseManagementServiceBuilder builder = new TestDatabaseManagementServiceBuilder(storeDir);
    setSpatialConfig(builder);
    DatabaseManagementService dbms = builder.build();
    GraphDatabaseService db = dbms.database(DEFAULT_DATABASE_NAME);
    createIndex(db, NATIVE_BTREE10.providerName(), label1);
    // createIndex( db, NATIVE20.providerName(), label2 ); // <- Those index providers are removed in 4.0, but here for reference.
    // createIndex( db, NATIVE10.providerName(), label3 );
    // createIndex( db, LUCENE10.providerName(), label4 );
    createSpatialData(db, label1, label2, label3, label4);
    for (FulltextIndexDescription fulltextIndex : FulltextIndexDescription.values()) {
        createFulltextIndex(db, fulltextIndex.indexProcedure, fulltextIndex.indexName, fulltextIndex.tokenName, propKey, fulltextIndex.configMap);
    }
    dbms.shutdown();
    Path zipFile = storeDir.resolveSibling(storeDir.getFileName().toString() + ".zip");
    ZipUtils.zip(new DefaultFileSystemAbstraction(), storeDir, zipFile);
    System.out.println("Db created in " + zipFile.toAbsolutePath());
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 24 with DatabaseManagementService

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

the class IndexSamplingIntegrationTest method shouldSampleNotUniqueIndex.

@ParameterizedTest
@EnumSource(Entity.class)
void shouldSampleNotUniqueIndex(Entity entity) throws Throwable {
    GraphDatabaseService db;
    DatabaseManagementService managementService = null;
    long deletedNodes = 0;
    try {
        // Given
        managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).build();
        db = managementService.database(DEFAULT_DATABASE_NAME);
        try (Transaction tx = db.beginTx()) {
            entity.createIndex(tx, schemaName, TOKEN, property);
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            tx.schema().awaitIndexOnline(schemaName, 1, TimeUnit.MINUTES);
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            for (int i = 0; i < entities; i++) {
                entity.createEntity(tx, TOKEN, property, names[i % names.length]);
            }
            tx.commit();
        }
        try (Transaction tx = db.beginTx()) {
            for (int i = 0; i < (entities / 10); i++) {
                entity.deleteFirstFound(tx, TOKEN, property, names[i % names.length]);
                deletedNodes++;
            }
            tx.commit();
        }
    } finally {
        if (managementService != null) {
            managementService.shutdown();
        }
    }
    // When
    triggerIndexResamplingOnNextStartup();
    // Then
    // lucene will consider also the delete nodes, native won't
    var indexSample = fetchIndexSamplingValues();
    assertThat(indexSample.uniqueValues()).as("Unique values").isEqualTo(names.length);
    assertThat(indexSample.sampleSize()).as("Sample size").isGreaterThanOrEqualTo(entities - deletedNodes).isLessThanOrEqualTo(entities);
    // but regardless, the deleted nodes should not be considered in the index size value
    assertThat(indexSample.updates()).as("Updates").isEqualTo(0);
    assertThat(indexSample.indexSize()).as("Index size").isEqualTo(entities - deletedNodes);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with DatabaseManagementService

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

the class DatabaseStartupTest method startCommunityDatabaseOnProvidedNonAbsoluteFile.

@Test
void startCommunityDatabaseOnProvidedNonAbsoluteFile() {
    Path directory = Path.of("target/notAbsoluteDirectory");
    EphemeralCommunityManagementServiceFactory factory = new EphemeralCommunityManagementServiceFactory();
    DatabaseManagementServiceBuilder databaseFactory = new EphemeralDatabaseManagementServiceBuilder(directory, factory);
    DatabaseManagementService managementService = databaseFactory.build();
    managementService.database(DEFAULT_DATABASE_NAME);
    managementService.shutdown();
}
Also used : Path(java.nio.file.Path) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

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