Search in sources :

Example 26 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project neo4j by neo4j.

the class IncrementalBackupTests method createTransactiongWithWeirdRelationshipGroupRecord.

private DbRepresentation createTransactiongWithWeirdRelationshipGroupRecord(File path) {
    db = startGraphDatabase(path);
    int i = 0;
    Node node;
    DynamicRelationshipType typeToDelete = DynamicRelationshipType.withName("A");
    DynamicRelationshipType theOtherType = DynamicRelationshipType.withName("B");
    int defaultDenseNodeThreshold = Integer.parseInt(GraphDatabaseSettings.dense_node_threshold.getDefaultValue());
    try (Transaction tx = db.beginTx()) {
        node = db.createNode();
        for (; i < defaultDenseNodeThreshold - 1; i++) {
            node.createRelationshipTo(db.createNode(), theOtherType);
        }
        node.createRelationshipTo(db.createNode(), typeToDelete);
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        node.createRelationshipTo(db.createNode(), theOtherType);
        for (Relationship relationship : node.getRelationships(Direction.BOTH, typeToDelete)) {
            relationship.delete();
        }
        tx.success();
    }
    DbRepresentation result = DbRepresentation.of(db);
    db.shutdown();
    return result;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) DynamicRelationshipType(org.neo4j.graphdb.DynamicRelationshipType) DbRepresentation(org.neo4j.test.DbRepresentation)

Example 27 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project neo4j by neo4j.

the class TestReadOnlyNeo4j method createSomeData.

private DbRepresentation createSomeData() {
    RelationshipType type = withName("KNOWS");
    GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem(new UncloseableDelegatingFileSystemAbstraction(fs.get())).newImpermanentDatabase(PATH);
    try (Transaction tx = db.beginTx()) {
        Node prevNode = db.createNode();
        for (int i = 0; i < 100; i++) {
            Node node = db.createNode();
            Relationship rel = prevNode.createRelationshipTo(node, type);
            node.setProperty("someKey" + i % 10, i % 15);
            rel.setProperty("since", System.currentTimeMillis());
        }
        tx.success();
    }
    DbRepresentation result = DbRepresentation.of(db);
    db.shutdown();
    return result;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) UncloseableDelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction) DbRepresentation(org.neo4j.test.DbRepresentation)

Aggregations

DbRepresentation (org.neo4j.test.DbRepresentation)27 Test (org.junit.Test)18 Transaction (org.neo4j.graphdb.Transaction)11 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)10 Node (org.neo4j.graphdb.Node)9 File (java.io.File)7 Relationship (org.neo4j.graphdb.Relationship)4 CoreGraphDatabase (org.neo4j.causalclustering.core.CoreGraphDatabase)2 ReadReplicaGraphDatabase (org.neo4j.causalclustering.readreplica.ReadReplicaGraphDatabase)2 DynamicRelationshipType (org.neo4j.graphdb.DynamicRelationshipType)2 WriteOperationsNotAllowedException (org.neo4j.graphdb.security.WriteOperationsNotAllowedException)2 ManagedCluster (org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Clock (java.time.Clock)1 Duration.ofSeconds (java.time.Duration.ofSeconds)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1