use of org.neo4j.graphdb.factory.GraphDatabaseFactory in project neo4j by neo4j.
the class DatabaseRule method create.
private void create() throws IOException {
createResources();
try {
GraphDatabaseFactory factory = newFactory();
configure(factory);
databaseBuilder = newBuilder(factory);
configure(databaseBuilder);
} catch (RuntimeException e) {
deleteResources();
throw e;
}
}
use of org.neo4j.graphdb.factory.GraphDatabaseFactory in project neo4j by neo4j.
the class DuplicatePropertyRemoverTest method setUp.
@BeforeClass
public static void setUp() {
GraphDatabaseFactory factory = new TestGraphDatabaseFactory();
GraphDatabaseService db = factory.newEmbeddedDatabase(storePath.absolutePath());
api = (GraphDatabaseAPI) db;
Label nodeLabel = Label.label("Label");
propertyNames = new ArrayList<>();
try (Transaction transaction = db.beginTx()) {
node = db.createNode(nodeLabel);
nodeId = node.getId();
for (int i = 0; i < PROPERTY_COUNT; i++) {
String propKey = "key" + i;
propertyNames.add(propKey);
String propValue = "value" + i;
boolean isBigProp = ThreadLocalRandom.current().nextBoolean();
if (isBigProp) {
propValue += propValue;
propValue += propValue;
propValue += propValue;
propValue += propValue;
propValue += propValue;
}
node.setProperty(propKey, propValue);
}
transaction.success();
}
Collections.shuffle(propertyNames);
DependencyResolver resolver = api.getDependencyResolver();
NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
nodeStore = neoStores.getNodeStore();
PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
indexedPropertyKeys = PropertyDeduplicatorTestUtil.indexPropertyKeys(propertyKeyTokenStore);
propertyStore = neoStores.getPropertyStore();
remover = new DuplicatePropertyRemover(nodeStore, propertyStore);
}
use of org.neo4j.graphdb.factory.GraphDatabaseFactory in project neo4j by neo4j.
the class FreePortIT method initialize.
public GraphDatabaseService initialize() throws IOException {
GraphDatabaseService db;
db = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(temporaryFolder.newFolder()).setConfig(ShellSettings.remote_shell_enabled, "true").setConfig(ShellSettings.remote_shell_host, HOST).setConfig(ShellSettings.remote_shell_port, Integer.toString(PORT)).newGraphDatabase();
return db;
}
use of org.neo4j.graphdb.factory.GraphDatabaseFactory in project neo4j by neo4j.
the class RestoreDatabaseCommandTest method shouldAllowForcedCopyOverAnExistingDatabase.
@Test
public void shouldAllowForcedCopyOverAnExistingDatabase() throws Exception {
// given
String databaseName = "to";
Config config = configWith(Config.empty(), databaseName, directory.absolutePath().getAbsolutePath());
File fromPath = new File(directory.absolutePath(), "from");
File toPath = config.get(DatabaseManagementSystemSettings.database_path);
int fromNodeCount = 10;
int toNodeCount = 20;
createDbAt(fromPath, fromNodeCount);
createDbAt(toPath, toNodeCount);
// when
new RestoreDatabaseCommand(fileSystemRule.get(), fromPath, config, databaseName, true).execute();
// then
GraphDatabaseService copiedDb = new GraphDatabaseFactory().newEmbeddedDatabase(toPath);
try (Transaction ignored = copiedDb.beginTx()) {
assertEquals(fromNodeCount, Iterables.count(copiedDb.getAllNodes()));
}
copiedDb.shutdown();
}
use of org.neo4j.graphdb.factory.GraphDatabaseFactory in project neo4j by neo4j.
the class BackupServiceStressTesting method shouldBehaveCorrectlyUnderStress.
@Test
public void shouldBehaveCorrectlyUnderStress() throws Exception {
long durationInMinutes = parseLong(fromEnv("BACKUP_SERVICE_STRESS_DURATION", DEFAULT_DURATION_IN_MINUTES));
String directory = fromEnv("BACKUP_SERVICE_STRESS_WORKING_DIRECTORY", DEFAULT_WORKING_DIR);
String backupHostname = fromEnv("BACKUP_SERVICE_STRESS_BACKUP_HOSTNAME", DEFAULT_HOSTNAME);
int backupPort = parseInt(fromEnv("BACKUP_SERVICE_STRESS_BACKUP_PORT", DEFAULT_PORT));
String txPrune = fromEnv("BACKUP_SERVICE_STRESS_TX_PRUNE", DEFAULT_TX_PRUNE);
boolean enableIndexes = parseBoolean(fromEnv("BACKUP_SERVICE_STRESS_ENABLE_INDEXES", DEFAULT_ENABLE_INDEXES));
File store = new File(directory, "store");
File work = new File(directory, "work");
FileUtils.deleteRecursively(store);
FileUtils.deleteRecursively(work);
File storeDirectory = ensureExistsAndEmpty(store);
File workDirectory = ensureExistsAndEmpty(work);
final Map<String, String> config = configureBackup(configureTxLogRotationAndPruning(new HashMap<>(), txPrune), backupHostname, backupPort);
GraphDatabaseBuilder graphDatabaseBuilder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDirectory.getAbsoluteFile()).setConfig(config);
final AtomicBoolean stopTheWorld = new AtomicBoolean();
BooleanSupplier notExpired = untilTimeExpired(durationInMinutes, MINUTES);
Runnable onFailure = () -> stopTheWorld.set(true);
BooleanSupplier keepGoingSupplier = () -> !stopTheWorld.get() && notExpired.getAsBoolean();
AtomicReference<GraphDatabaseService> dbRef = new AtomicReference<>();
ExecutorService service = Executors.newFixedThreadPool(3);
try {
dbRef.set(graphDatabaseBuilder.newGraphDatabase());
if (enableIndexes) {
WorkLoad.setupIndexes(dbRef.get());
}
Future<Throwable> workload = service.submit(new WorkLoad(keepGoingSupplier, onFailure, dbRef::get));
Future<Throwable> backupWorker = service.submit(new BackupLoad(keepGoingSupplier, onFailure, backupHostname, backupPort, workDirectory));
Future<Throwable> startStopWorker = service.submit(new StartStop(keepGoingSupplier, onFailure, graphDatabaseBuilder::newGraphDatabase, dbRef));
long expirationTime = currentTimeMillis() + TimeUnit.MINUTES.toMillis(durationInMinutes + 5);
assertSuccessfulExecution(workload, maxWaitTime(expirationTime), expirationTime);
assertSuccessfulExecution(backupWorker, maxWaitTime(expirationTime), expirationTime);
assertSuccessfulExecution(startStopWorker, maxWaitTime(expirationTime), expirationTime);
service.shutdown();
if (!service.awaitTermination(30, TimeUnit.SECONDS)) {
ThreadTestUtils.dumpAllStackTraces();
fail("Didn't manage to shut down the workers correctly, dumped threads for forensic purposes");
}
} finally {
dbRef.get().shutdown();
service.shutdown();
}
// let's cleanup disk space when everything went well
FileUtils.deleteRecursively(storeDirectory);
FileUtils.deleteRecursively(workDirectory);
}
Aggregations