Search in sources :

Example 1 with GraphDatabaseFactory

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;
    }
}
Also used : GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory)

Example 2 with GraphDatabaseFactory

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);
}
Also used : PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) BeforeClass(org.junit.BeforeClass)

Example 3 with GraphDatabaseFactory

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;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory)

Example 4 with GraphDatabaseFactory

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();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) Config(org.neo4j.kernel.configuration.Config) File(java.io.File) Test(org.junit.Test)

Example 5 with GraphDatabaseFactory

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);
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GraphDatabaseFactory(org.neo4j.graphdb.factory.GraphDatabaseFactory) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) BooleanSupplier(java.util.function.BooleanSupplier) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Test(org.junit.Test)

Aggregations

GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)16 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)9 Transaction (org.neo4j.graphdb.Transaction)8 GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)5 File (java.io.File)4 Test (org.junit.Test)4 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)4 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 Label (org.neo4j.graphdb.Label)2 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 GlobalGraphOperations (org.neo4j.tooling.GlobalGraphOperations)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1