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