use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j-documentation by neo4j.
the class JavaExecutionEngineDocTest method setUp.
@Before
public void setUp() throws IOException {
managementService = new TestDatabaseManagementServiceBuilder().impermanent().build();
db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = this.db.beginTx()) {
tx.schema().indexFor(Label.label("Person")).on("name").withName("My index").create();
tx.commit();
}
try (Transaction tx = this.db.beginTx()) {
Node michaelaNode = tx.createNode(Label.label("Person"));
Node bobNode = tx.createNode(Label.label("Person"));
Node johanNode = tx.createNode(Label.label("Person"));
bobNode.setProperty("name", "Bob");
johanNode.setProperty("name", "Johan");
michaelaNode.setProperty("name", "Michaela");
michaelaNodeId = michaelaNode.getId();
bobNodeId = bobNode.getId();
johanNodeId = johanNode.getId();
tx.commit();
}
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder 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));
}
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class StartOldDbOnCurrentVersionAndCreateFusionIndexIT 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);
createIndexDataAndShutdown(builder, "lucene-1.0", Provider.LUCENE_10.label);
createIndexDataAndShutdown(builder, "lucene+native-1.0", Provider.FUSION_10.label);
createIndexDataAndShutdown(builder, "lucene+native-2.0", Provider.FUSION_20.label);
createIndexDataAndShutdown(builder, GraphDatabaseSettings.SchemaIndex.NATIVE_BTREE10.providerName(), Provider.BTREE_10.label, db -> {
try (Transaction tx = db.beginTx()) {
tx.execute("CALL db.index.fulltext.createNodeIndex('fts1', ['Fts1'], ['prop1'] )").close();
tx.execute("CALL db.index.fulltext.createNodeIndex('fts2', ['Fts2', 'Fts3'], ['prop1', 'prop2'] )").close();
tx.execute("CALL db.index.fulltext.createNodeIndex('fts3', ['Fts4'], ['prop1'], {eventually_consistent: 'true'} )").close();
tx.execute("CALL db.index.fulltext.createRelationshipIndex('fts4', ['FtsRel1', 'FtsRel2'], ['prop1', 'prop2'], " + "{eventually_consistent: 'true'} )").close();
tx.commit();
}
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(10, TimeUnit.MINUTES);
Node node = tx.createNode(Label.label("Fts1"), Label.label("Fts2"), Label.label("Fts3"), Label.label("Fts4"));
node.setProperty("prop1", "abc");
node.setProperty("prop2", "abc");
node.createRelationshipTo(node, RelationshipType.withName("FtsRel1")).setProperty("prop1", "abc");
node.createRelationshipTo(node, RelationshipType.withName("FtsRel2")).setProperty("prop2", "abc");
tx.commit();
}
try (Transaction tx = db.beginTx()) {
tx.execute("call db.index.fulltext.awaitEventuallyConsistentIndexRefresh").close();
tx.commit();
}
});
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.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class DefaultDatabaseManagerIT method setUp.
@BeforeEach
void setUp() {
managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setConfig(GraphDatabaseSettings.logical_log_rotation_threshold, kibiBytes(128)).build();
database = managementService.database(DEFAULT_DATABASE_NAME);
databaseManager = ((GraphDatabaseAPI) database).getDependencyResolver().resolveDependency(DatabaseManager.class);
defaultNamedDatabaseId = databaseManager.databaseIdRepository().getByName(DEFAULT_DATABASE_NAME).orElseThrow();
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder 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();
}
}
}
Aggregations