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();
}
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();
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations