use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class RollbackIdLeakIT method nonClean.
private DbRestarter nonClean() {
return new DbRestarter() {
private DatabaseManagementService dbms;
private EphemeralFileSystemAbstraction fsSnapshot;
@Override
public GraphDatabaseService start() {
return start(fs);
}
@Override
public GraphDatabaseService restart() {
fsSnapshot = fs.snapshot();
dbms.shutdown();
return start(fsSnapshot);
}
@Override
public void close() throws IOException {
dbms.shutdown();
fsSnapshot.close();
}
private GraphDatabaseService start(EphemeralFileSystemAbstraction fs) {
dbms = new TestDatabaseManagementServiceBuilder(directory.homePath()).setFileSystem(fs).build();
return dbms.database(DEFAULT_DATABASE_NAME);
}
};
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class RecordFormatMigrationIT method requestMigrationIfStoreFormatNotSpecifiedButIsAvailableInRuntime.
@Test
void requestMigrationIfStoreFormatNotSpecifiedButIsAvailableInRuntime() {
DatabaseManagementService managementService = startManagementService(StandardV4_0.NAME);
GraphDatabaseAPI database = getDefaultDatabase(managementService);
try (Transaction transaction = database.beginTx()) {
Node node = transaction.createNode();
node.setProperty("a", "b");
transaction.commit();
}
managementService.shutdown();
managementService = new TestDatabaseManagementServiceBuilder(databaseDirectory).build();
database = getDefaultDatabase(managementService);
try {
assertDefaultDatabaseFailed(database);
} finally {
managementService.shutdown();
}
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class DbmsSupportController method maybeInvokeCallback.
private static void maybeInvokeCallback(Object testInstance, TestDatabaseManagementServiceBuilder builder, String callback) {
if (callback == null || callback.isEmpty()) {
// Callback disabled
return;
}
for (Method declaredMethod : getAllMethods(testInstance.getClass())) {
if (declaredMethod.getName().equals(callback)) {
// Make sure it returns void
if (declaredMethod.getReturnType() != Void.TYPE) {
throw new IllegalArgumentException("The method '" + callback + "', must return void.");
}
// Make sure we have compatible parameters
Class<?>[] parameterTypes = declaredMethod.getParameterTypes();
if (parameterTypes.length != 1 || !parameterTypes[0].isAssignableFrom(TestDatabaseManagementServiceBuilder.class)) {
throw new IllegalArgumentException("The method '" + callback + "', must take one parameter that is assignable from " + TestDatabaseManagementServiceBuilder.class.getSimpleName() + ".");
}
// Make sure we have the required annotation
if (declaredMethod.getAnnotation(ExtensionCallback.class) == null) {
throw new IllegalArgumentException("The method '" + callback + "', must be annotated with " + ExtensionCallback.class.getSimpleName() + ".");
}
// All match, try calling it
declaredMethod.setAccessible(true);
try {
declaredMethod.invoke(testInstance, builder);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("The method '" + callback + "' is not accessible.", e);
} catch (InvocationTargetException e) {
throw new RuntimeException("The method '" + callback + "' threw an exception.", e);
}
// All done
return;
}
}
// No method matching the provided name
throw new IllegalArgumentException("The method with name '" + callback + "' cannot be found.");
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class RestartIT method shouldBeAbleToReadExistingStoreOnRestart.
@Test
void shouldBeAbleToReadExistingStoreOnRestart() throws IOException {
// Given an existing store
testDir.cleanup();
var storeDir = testDir.absolutePath();
var oldManagementService = new TestDatabaseManagementServiceBuilder(storeDir).build();
oldManagementService.shutdown();
// When start with that store
var managementService = new TestDatabaseManagementServiceBuilder(storeDir).build();
// Then should be able to access it
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try (var tx = db.beginTx()) {
assertThat(tx.getAllNodes()).isEmpty();
} finally {
managementService.shutdown();
}
}
use of org.neo4j.test.TestDatabaseManagementServiceBuilder in project neo4j by neo4j.
the class TestReadOnlyNeo4j method createIndex.
private void createIndex() {
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath()).setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs)).impermanent().build();
GraphDatabaseService db = managementService.database(DEFAULT_DATABASE_NAME);
try (Transaction tx = db.beginTx()) {
tx.schema().indexFor(Label.label("label")).on("prop").create();
tx.commit();
}
try (Transaction tx = db.beginTx()) {
tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
tx.commit();
}
managementService.shutdown();
}
Aggregations