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;
}
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();
}
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();
}
}
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));
}
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));
}
Aggregations