Search in sources :

Example 16 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project graphdb by neo4j-attic.

the class TestReadOnlyNeo4j method createSomeData.

private DbRepresentation createSomeData() {
    DynamicRelationshipType type = withName("KNOWS");
    GraphDatabaseService db = new EmbeddedGraphDatabase(PATH);
    Transaction tx = db.beginTx();
    Node prevNode = db.getReferenceNode();
    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();
    tx.finish();
    DbRepresentation result = DbRepresentation.of(db);
    db.shutdown();
    return result;
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) 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 17 with DbRepresentation

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

the class IncrementalBackupTests method addMoreData2.

private DbRepresentation addMoreData2(File path) {
    db = startGraphDatabase(path);
    try (Transaction tx = db.beginTx()) {
        Node donald = db.getNodeById(2);
        Node gladstone = db.createNode();
        gladstone.setProperty("name", "Gladstone");
        Relationship hates = donald.createRelationshipTo(gladstone, RelationshipType.withName("HATES"));
        hates.setProperty("since", 1948);
        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) DbRepresentation(org.neo4j.test.DbRepresentation)

Example 18 with DbRepresentation

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

the class IncrementalBackupTests method shouldNotServeTransactionsWithInvalidHighIds.

@Test
public void shouldNotServeTransactionsWithInvalidHighIds() throws Exception {
    /*
         * This is in effect a high level test for an edge case that happens when a relationship group is
         * created and deleted in the same tx. This can end up causing an IllegalArgumentException because
         * the HighIdApplier used when applying incremental updates (batch transactions in general) will postpone
         * processing of added/altered record ids but deleted ids will be processed on application. This can result
         * in a deleted record causing an IllegalArgumentException even though it is not the highest id in the tx.
         *
         * The way we try to trigger this is:
         * 0. In one tx, create a node with 49 relationships, belonging to two types.
         * 1. In another tx, create another relationship on that node (making it dense) and then delete all
         *    relationships of one type. This results in the tx state having a relationship group record that was
         *    created in this tx and also set to not in use.
         * 2. Receipt of this tx will have the offending rel group command apply its id before the groups that are
         *    altered. This will try to update the high id with a value larger than what has been seen previously and
         *    fail the update.
         * The situation is resolved by a check added in TransactionRecordState which skips the creation of such
         * commands.
         * Note that this problem can also happen in HA slaves.
         */
    DbRepresentation initialDataSetRepresentation = createInitialDataSet(serverPath);
    server = startServer(serverPath, "127.0.0.1:6362");
    OnlineBackup backup = OnlineBackup.from("127.0.0.1");
    backup.full(backupPath.getPath());
    assertEquals(initialDataSetRepresentation, getBackupDbRepresentation());
    shutdownServer(server);
    DbRepresentation furtherRepresentation = createTransactiongWithWeirdRelationshipGroupRecord(serverPath);
    server = startServer(serverPath, null);
    backup.incremental(backupPath.getPath());
    assertEquals(furtherRepresentation, getBackupDbRepresentation());
    shutdownServer(server);
}
Also used : DbRepresentation(org.neo4j.test.DbRepresentation) Test(org.junit.Test)

Example 19 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 20 with DbRepresentation

use of org.neo4j.test.DbRepresentation in project graphdb by neo4j-attic.

the class TestBackup method addMoreData.

private DbRepresentation addMoreData(String path) {
    GraphDatabaseService db = startGraphDatabase(path);
    Transaction tx = db.beginTx();
    Node node = db.createNode();
    node.setProperty("backup", "Is great");
    db.getReferenceNode().createRelationshipTo(node, DynamicRelationshipType.withName("LOVES"));
    tx.success();
    tx.finish();
    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) 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