Search in sources :

Example 16 with GraphDatabaseBuilder

use of org.neo4j.graphdb.factory.GraphDatabaseBuilder in project neo4j by neo4j.

the class UdcExtensionImplTest method createDatabase.

private GraphDatabaseService createDatabase(Map<String, String> config) throws IOException {
    GraphDatabaseBuilder graphDatabaseBuilder = new TestEnterpriseGraphDatabaseFactory().newImpermanentDatabaseBuilder();
    graphDatabaseBuilder.loadPropertiesFromURL(getClass().getResource("/org/neo4j/ext/udc/udc.properties"));
    if (config != null) {
        graphDatabaseBuilder.setConfig(config);
    }
    return graphDatabaseBuilder.newGraphDatabase();
}
Also used : TestEnterpriseGraphDatabaseFactory(org.neo4j.test.TestEnterpriseGraphDatabaseFactory) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Example 17 with GraphDatabaseBuilder

use of org.neo4j.graphdb.factory.GraphDatabaseBuilder in project neo4j by neo4j.

the class StoreMigratorFrom21IT method mustMendDuplicatePropertiesWhenUpgradingFromVersion21.

@Test
public void mustMendDuplicatePropertiesWhenUpgradingFromVersion21() throws Exception {
    // The rules:
    // If an index is present, all duplicates should be removed and the property set to the value in the index
    // If an index is not present, the property should be set to the value of the last duplicate in the property
    // chain, all duplicates except the first should be removed
    // If an index is not present, the first property in the duplicate chain should be kept for the users
    // benefit, moved to a special property value, `__DUPLICATE_<propkey>`
    //
    // This is the broken store that we are upgrading:
    //
    //   (#0:Label { keyA: "actual", keyA: "phony!", keyA: "phony!" })
    //   (#1 { keyA: "actual", keyA: "actual", keyA: "actual" })
    //   (#2:Label { keyA: "real1", keyA: "phony", keyA: "phony", keyD: "real2", keyD: "phony", keyD: "phony" })
    //   (#3 { keyA: "real1", keyA: "phony", keyA: "phony", keyD: "real2", keyD: "phony", keyD: "phony" })
    //   (#4 { keyA: "actual", keyB: "actual", keyC: "actual" })
    //   (#0)-[#0:REL { keyA: "actual", keyA: "actual", keyA: "actual" }]->(#1)
    //   (#0)-[#1:REL { keyA: "real1", keyA: "phony", keyA: "phony",
    //                  keyD: "real2", keyE: "phony", keyF: "phony" }]->(#1)
    //   (#2)-[#2:REL { keyA: "actual", keyB: "actual", keyC: "actual" }]->(#0)
    //
    // And this is what we want to end up with, after upgrading:
    //
    //   (#0:Label { keyA: "actual" })
    //   (#1 { keyA: "actual", __DUPLICATE_keyA: "actual" })
    //   (#2:Label { keyA: "real1", keyD: "real2" })
    //   (#3 { keyA: "real1", __DUPLICATE_keyA_1: "real1", __DUPLICATE_keyA_2: "real1",
    //         keyD: "real2", __DUPLICATE_keyD_1: "real2", __DUPLICATE_keyD_2: "real2" })
    //   (#4 { keyA: "actual", keyB: "actual", keyC: "actual" })
    //   (#0)-[#0:REL { keyA: "actual", __DUPLICATE_keyA: "actual" }]->(#1)
    //   (#0)-[#1:REL { keyA: "real1", __DUPLICATE_keyA_1: "real1", __DUPLICATE_keyA_2: "real1",
    //                  keyD: "real2", __DUPLICATE_keyD_1: "real2", __DUPLICATE_keyD_2: "real2" }]->(#1)
    //   (#2)-[#2:REL { keyA: "actual", keyB: "actual", keyC: "actual" }]->(#0)
    File dir = MigrationTestUtils.find21FormatStoreDirectoryWithDuplicateProperties(storeDir.directory());
    TestGraphDatabaseFactory factory = new TestGraphDatabaseFactory();
    GraphDatabaseBuilder builder = factory.newEmbeddedDatabaseBuilder(dir).setConfig(GraphDatabaseSettings.allow_store_upgrade, "true");
    GraphDatabaseService database = builder.newGraphDatabase();
    database.shutdown();
    ConsistencyCheckService service = new ConsistencyCheckService();
    ConsistencyCheckService.Result result = service.runFullConsistencyCheck(dir.getAbsoluteFile(), Config.empty(), ProgressMonitorFactory.NONE, NullLogProvider.getInstance(), false);
    assertTrue(result.isSuccessful());
    database = builder.newGraphDatabase();
    // Upgrade is now completed. Verify the contents:
    DependencyResolver dependencyResolver = ((GraphDatabaseAPI) database).getDependencyResolver();
    // Verify that the properties appear correct to the outside world:
    try (Transaction ignore = database.beginTx()) {
        verifyProperties(database.getNodeById(0), Pair.of("keyA", new Object[] { "actual", "phony!", "phony!" }));
        verifyProperties(database.getNodeById(1), Pair.of("keyA", new Object[] { "actual", "actual", "actual" }));
        verifyProperties(database.getNodeById(2), Pair.of("keyA", new Object[] { "real1", "phony", "phony" }), Pair.of("keyD", new Object[] { "real2", "phony", "phony" }));
        verifyProperties(database.getNodeById(3), Pair.of("keyA", new Object[] { "real1", "real1", "real1" }), Pair.of("keyD", new Object[] { "real2", "real2", "real2" }));
        verifyProperties(database.getNodeById(4), Pair.of("keyA", new Object[] { "actual" }), Pair.of("keyB", new Object[] { "actual" }), Pair.of("keyC", new Object[] { "actual" }));
        verifyProperties(database.getRelationshipById(0), Pair.of("keyA", new Object[] { "actual", "actual", "actual" }));
        verifyProperties(database.getRelationshipById(1), Pair.of("keyA", new Object[] { "real1", "real1", "real1" }), Pair.of("keyD", new Object[] { "real2", "real2", "real2" }));
        verifyProperties(database.getRelationshipById(2), Pair.of("keyA", new Object[] { "actual" }), Pair.of("keyB", new Object[] { "actual" }), Pair.of("keyC", new Object[] { "actual" }));
    }
    // Verify that there are no two properties on the entities, that have the same key:
    // (This is important because the verification above cannot tell if we have two keys with the same value)
    KernelAPI kernel = dependencyResolver.resolveDependency(KernelAPI.class);
    try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        Iterators.asUniqueSet(statement.readOperations().nodeGetPropertyKeys(0));
        Iterators.asUniqueSet(statement.readOperations().nodeGetPropertyKeys(1));
        Iterators.asUniqueSet(statement.readOperations().nodeGetPropertyKeys(2));
        Iterators.asUniqueSet(statement.readOperations().relationshipGetPropertyKeys(0));
        Iterators.asUniqueSet(statement.readOperations().relationshipGetPropertyKeys(1));
    }
    database.shutdown();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Statement(org.neo4j.kernel.api.Statement) DependencyResolver(org.neo4j.graphdb.DependencyResolver) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) ConsistencyCheckService(org.neo4j.consistency.ConsistencyCheckService) File(java.io.File) KernelAPI(org.neo4j.kernel.api.KernelAPI) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) Test(org.junit.Test)

Example 18 with GraphDatabaseBuilder

use of org.neo4j.graphdb.factory.GraphDatabaseBuilder in project neo4j by neo4j.

the class CheckPointerIntegrationTest method shouldBeAbleToStartAndShutdownMultipleTimesTheDBWithoutCommittingTransactions.

@Test
public void shouldBeAbleToStartAndShutdownMultipleTimesTheDBWithoutCommittingTransactions() throws Throwable {
    // given
    GraphDatabaseBuilder graphDatabaseBuilder = builder.setConfig(GraphDatabaseSettings.check_point_interval_time, "300m").setConfig(GraphDatabaseSettings.check_point_interval_tx, "10000").setConfig(GraphDatabaseSettings.logical_log_rotation_threshold, "1g");
    // when
    graphDatabaseBuilder.newGraphDatabase().shutdown();
    graphDatabaseBuilder.newGraphDatabase().shutdown();
    // then - 2 check points have been written in the log
    List<CheckPoint> checkPoints = new CheckPointCollector(storeDir, fs).find(0);
    assertEquals(2, checkPoints.size());
}
Also used : GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder) CheckPoint(org.neo4j.kernel.impl.transaction.log.entry.CheckPoint) Test(org.junit.Test)

Example 19 with GraphDatabaseBuilder

use of org.neo4j.graphdb.factory.GraphDatabaseBuilder in project neo4j by neo4j.

the class TestGraphDatabaseFactory method newImpermanentDatabase.

public GraphDatabaseService newImpermanentDatabase(Map<Setting<?>, String> config) {
    GraphDatabaseBuilder builder = newImpermanentDatabaseBuilder();
    for (Map.Entry<Setting<?>, String> entry : config.entrySet()) {
        Setting<?> key = entry.getKey();
        String value = entry.getValue();
        builder.setConfig(key, value);
    }
    return builder.newGraphDatabase();
}
Also used : Setting(org.neo4j.graphdb.config.Setting) Map(java.util.Map) MapUtil.stringMap(org.neo4j.helpers.collection.MapUtil.stringMap) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Example 20 with GraphDatabaseBuilder

use of org.neo4j.graphdb.factory.GraphDatabaseBuilder in project neo4j by neo4j.

the class DbRepresentation method of.

public static DbRepresentation of(File storeDir, boolean includeIndexes, Config config) {
    GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir);
    builder.setConfig(config.getRaw());
    GraphDatabaseService db = builder.newGraphDatabase();
    try {
        return of(db, includeIndexes);
    } finally {
        db.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) GraphDatabaseBuilder(org.neo4j.graphdb.factory.GraphDatabaseBuilder)

Aggregations

GraphDatabaseBuilder (org.neo4j.graphdb.factory.GraphDatabaseBuilder)21 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)8 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)8 File (java.io.File)6 Test (org.junit.Test)6 Transaction (org.neo4j.graphdb.Transaction)5 GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)5 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)5 Edge (com.tinkerpop.blueprints.Edge)2 Vertex (com.tinkerpop.blueprints.Vertex)2 Map (java.util.Map)2 GlobalGraphOperations (org.neo4j.tooling.GlobalGraphOperations)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BooleanSupplier (java.util.function.BooleanSupplier)1 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)1 AccessStatsKeepingStoreAccess (org.neo4j.consistency.statistics.AccessStatsKeepingStoreAccess)1