Search in sources :

Example 56 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class TestBackup method addMoreData.

private DbRepresentation addMoreData(File path) {
    GraphDatabaseService db = startGraphDatabase(path, false);
    DbRepresentation representation;
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode();
        node.setProperty("backup", "Is great");
        db.createNode().createRelationshipTo(node, RelationshipType.withName("LOVES"));
        tx.success();
    } finally {
        representation = DbRepresentation.of(db);
        db.shutdown();
    }
    return representation;
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) DbRepresentation(org.neo4j.test.DbRepresentation)

Example 57 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class CausalClusteringRolesIT method readReplicasShouldRefuseWrites.

@Test
public void readReplicasShouldRefuseWrites() throws Exception {
    // given
    Cluster cluster = clusterRule.startCluster();
    GraphDatabaseService db = cluster.findAnyReadReplica().database();
    Transaction tx = db.beginTx();
    // then
    exceptionMatcher.expect(WriteOperationsNotAllowedException.class);
    // when
    db.createNode();
    tx.success();
    tx.close();
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Cluster(org.neo4j.causalclustering.discovery.Cluster) Test(org.junit.Test)

Example 58 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class ClusterTest method given4instanceClusterWhenMasterGoesDownThenElectNewMaster.

@Test
public void given4instanceClusterWhenMasterGoesDownThenElectNewMaster() throws Throwable {
    ClusterManager clusterManager = new ClusterManager.Builder(testDirectory.directory("4instances")).withCluster(ClusterManager.clusterOfSize(4)).build();
    try {
        clusterManager.start();
        ClusterManager.ManagedCluster cluster = clusterManager.getCluster();
        cluster.await(allSeesAllAsAvailable());
        logging.getLogger().info("STOPPING MASTER");
        cluster.shutdown(cluster.getMaster());
        logging.getLogger().info("STOPPED MASTER");
        cluster.await(ClusterManager.masterAvailable());
        GraphDatabaseService master = cluster.getMaster();
        logging.getLogger().info("CREATE NODE");
        try (Transaction tx = master.beginTx()) {
            master.createNode();
            logging.getLogger().info("CREATED NODE");
            tx.success();
        }
        logging.getLogger().info("STOPPING CLUSTER");
    } finally {
        clusterManager.safeShutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) ClusterManager(org.neo4j.kernel.impl.ha.ClusterManager) Test(org.junit.Test)

Example 59 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class IdReuseTest method shouldReuseNodeIdsFromRolledBackTransaction.

@Test
public void shouldReuseNodeIdsFromRolledBackTransaction() throws Exception {
    // Given
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    try (Transaction tx = db.beginTx()) {
        db.createNode();
        tx.failure();
    }
    db = dbRule.restartDatabase();
    // When
    Node node;
    try (Transaction tx = db.beginTx()) {
        node = db.createNode();
        tx.success();
    }
    // Then
    assertThat(node.getId(), equalTo(0L));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.Test)

Example 60 with GraphDatabaseService

use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.

the class IdReuseTest method shouldReuseRelationshipIdsFromRolledBackTransaction.

@Test
public void shouldReuseRelationshipIdsFromRolledBackTransaction() throws Exception {
    // Given
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    Node node1, node2;
    try (Transaction tx = db.beginTx()) {
        node1 = db.createNode();
        node2 = db.createNode();
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        node1.createRelationshipTo(node2, RelationshipType.withName("LIKE"));
        tx.failure();
    }
    db = dbRule.restartDatabase();
    // When
    Relationship relationship;
    try (Transaction tx = db.beginTx()) {
        node1 = db.getNodeById(node1.getId());
        node2 = db.getNodeById(node2.getId());
        relationship = node1.createRelationshipTo(node2, RelationshipType.withName("LIKE"));
        tx.success();
    }
    // Then
    assertThat(relationship.getId(), equalTo(0L));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Aggregations

GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)322 Test (org.junit.Test)225 Transaction (org.neo4j.graphdb.Transaction)182 Node (org.neo4j.graphdb.Node)142 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)77 File (java.io.File)70 Relationship (org.neo4j.graphdb.Relationship)49 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)32 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)17 Result (org.neo4j.graphdb.Result)14 Label (org.neo4j.graphdb.Label)13 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)12 HashMap (java.util.HashMap)11 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 PageCache (org.neo4j.io.pagecache.PageCache)10 DbRepresentation (org.neo4j.test.DbRepresentation)10 GraphDatabaseFactory (org.neo4j.graphdb.factory.GraphDatabaseFactory)9 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)8