Search in sources :

Example 1 with DatabaseManagementService

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

the class SchemaConstraintProviderApprovalTest method init.

@BeforeAll
public static void init() {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    for (TestValue value : TestValue.values()) {
        createNode(db, PROPERTY_KEY, value.value);
    }
    noIndexRun = runFindByLabelAndProperty(db);
    createConstraint(db, label(LABEL), PROPERTY_KEY);
    constraintRun = runFindByLabelAndProperty(db);
    managementService.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with DatabaseManagementService

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

the class DefaultSchemaIndexConfigTest method indexShouldHaveIndexConfig.

@ParameterizedTest
@MethodSource("providers")
void indexShouldHaveIndexConfig(GraphDatabaseSettings.SchemaIndex provider) throws IndexNotFoundKernelException {
    DatabaseManagementServiceBuilder databaseManagementServiceBuilder = dbBuilder.setConfig(default_schema_provider, provider == null ? null : provider.providerName());
    DatabaseManagementService managementService = databaseManagementServiceBuilder.build();
    GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
    try {
        // when
        createIndex(db);
        // then
        validateIndexConfig(db);
    } finally {
        managementService.shutdown();
    }
    managementService = databaseManagementServiceBuilder.build();
    db = managementService.database(DEFAULT_DATABASE_NAME);
    try {
        validateIndexConfig(db);
    } finally {
        managementService.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) DatabaseManagementServiceBuilder(org.neo4j.dbms.api.DatabaseManagementServiceBuilder) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with DatabaseManagementService

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

the class CountsComputerTest method shouldCreateAnEmptyCountsStoreFromAnEmptyDatabase.

@Test
void shouldCreateAnEmptyCountsStoreFromAnEmptyDatabase() throws IOException {
    DatabaseManagementService managementService = dbBuilder.build();
    final GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    long lastCommittedTransactionId = getLastTxId(db);
    managementService.shutdown();
    rebuildCounts(lastCommittedTransactionId);
    try (GBPTreeCountsStore store = createCountsStore(matchingBuilder(lastCommittedTransactionId))) {
        store.start(NULL, INSTANCE);
        softly.assertThat(store.txId()).as("Store Transaction id").isEqualTo(lastCommittedTransactionId);
        store.accept(new AssertEmptyCountStoreVisitor(), NULL);
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 4 with DatabaseManagementService

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

the class CountsComputerTest method shouldCreateACountsStoreWhenThereAreNodesInTheDB.

@Test
void shouldCreateACountsStoreWhenThereAreNodesInTheDB() throws IOException, KernelException {
    DatabaseManagementService managementService = dbBuilder.build();
    final GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Label[] labels = null;
    int[] labelIds = null;
    Node[] nodes = null;
    try (Transaction tx = db.beginTx()) {
        labels = createLabels(4);
        labelIds = getLabelIdsFrom(tx, labels);
        nodes = new Node[] { tx.createNode(labels[0]), tx.createNode(labels[1]), tx.createNode(labels[2]), tx.createNode() };
        tx.commit();
    }
    long lastCommittedTransactionId = getLastTxId(db);
    managementService.shutdown();
    rebuildCounts(lastCommittedTransactionId);
    try (GBPTreeCountsStore store = createCountsStore()) {
        softly.assertThat(store.txId()).as("Store Transaction id").isEqualTo(lastCommittedTransactionId);
        softly.assertThat(store.nodeCount(ANY_LABEL, NULL)).as("count: ()").isEqualTo(nodes.length);
        softly.assertThat(store.nodeCount(labelIds[0], NULL)).as("count: (:%s)", labels[0]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[1], NULL)).as("count: (:%s)", labels[1]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[2], NULL)).as("count: (:%s)", labels[2]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[3], NULL)).as("count: (:%s)", labels[3]).isEqualTo(0);
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Test(org.junit.jupiter.api.Test)

Example 5 with DatabaseManagementService

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

the class CountsComputerTest method shouldCreateACountStoreWhenDBContainsDenseNodes.

@Test
void shouldCreateACountStoreWhenDBContainsDenseNodes() throws IOException, KernelException {
    DatabaseManagementService managementService = dbBuilder.setConfig(GraphDatabaseSettings.dense_node_threshold, 2).build();
    final GraphDatabaseAPI db = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Label[] labels = null;
    int[] labelIds = null;
    RelationshipType[] relTypes = null;
    int[] relTypeIds = null;
    Node[] nodes = null;
    Relationship[] rels = null;
    try (Transaction tx = db.beginTx()) {
        labels = createLabels(4);
        labelIds = getLabelIdsFrom(tx, labels);
        relTypes = createRelationShipTypes(5);
        relTypeIds = getRelTypeIdsFrom(tx, relTypes);
        nodes = new Node[] { tx.createNode(labels[0]), tx.createNode(labels[1]), tx.createNode(labels[2]) };
        rels = new Relationship[] { nodes[0].createRelationshipTo(nodes[0], relTypes[0]), nodes[0].createRelationshipTo(nodes[1], relTypes[1]), nodes[0].createRelationshipTo(nodes[2], relTypes[2]), nodes[2].createRelationshipTo(nodes[1], relTypes[3]) };
        tx.commit();
    }
    long lastCommittedTransactionId = getLastTxId(db);
    managementService.shutdown();
    rebuildCounts(lastCommittedTransactionId);
    try (GBPTreeCountsStore store = createCountsStore()) {
        softly.assertThat(store.txId()).as("Store Transaction id").isEqualTo(lastCommittedTransactionId);
        softly.assertThat(store.nodeCount(ANY_LABEL, NULL)).as("count: ()").isEqualTo(nodes.length);
        softly.assertThat(store.nodeCount(labelIds[0], NULL)).as("count: (:%s)", labels[0]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[1], NULL)).as("count: (:%s)", labels[1]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[2], NULL)).as("count: (:%s)", labels[2]).isEqualTo(1);
        softly.assertThat(store.nodeCount(labelIds[3], NULL)).as("count: (:%s)", labels[3]).isEqualTo(0);
        softly.assertThat(store.relationshipCount(ANY_LABEL, ANY_RELATIONSHIP_TYPE, ANY_LABEL, NULL)).as("()-[]->()").isEqualTo(rels.length);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[0], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[0]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[1]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[2], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[2]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[3], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[3]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[4], ANY_LABEL, NULL)).as("count: ()-[:%s]->()", relTypes[4]).isEqualTo(0);
        softly.assertThat(store.relationshipCount(ANY_LABEL, relTypeIds[1], labelIds[1], NULL)).as("count: ()-[:%s]->(:%s)", relTypes[1], labels[1]).isEqualTo(1);
        softly.assertThat(store.relationshipCount(ANY_LABEL, ANY_RELATIONSHIP_TYPE, labelIds[1], NULL)).as("count: ()-[]->(:%s)", labels[1]).isEqualTo(2);
        softly.assertThat(store.relationshipCount(labelIds[0], ANY_RELATIONSHIP_TYPE, ANY_LABEL, NULL)).as("count: (:%s)-[]->()", labels[0]).isEqualTo(3);
    }
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship) GBPTreeCountsStore(org.neo4j.internal.counts.GBPTreeCountsStore) 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