use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class ImportToolTest method shouldBeAbleToImportAnonymousNodes.
@Test
public void shouldBeAbleToImportAnonymousNodes() throws Exception {
// GIVEN
List<String> nodeIds = asList("1", "", "", "", "3", "", "", "", "", "", "5");
Configuration config = Configuration.COMMAS;
List<RelationshipDataLine> relationshipData = asList(relationship("1", "3", "KNOWS"));
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeData(true, config, nodeIds, TRUE).getAbsolutePath(), "--relationships", relationshipData(true, config, relationshipData.iterator(), TRUE, true).getAbsolutePath());
// THEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
Iterable<Node> allNodes = db.getAllNodes();
int anonymousCount = 0;
for (final String id : nodeIds) {
if (id.isEmpty()) {
anonymousCount++;
} else {
assertNotNull(Iterators.single(Iterators.filter(nodeFilter(id), allNodes.iterator())));
}
}
assertEquals(anonymousCount, count(Iterators.filter(nodeFilter(""), allNodes.iterator())));
tx.success();
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class ImportToolTest method shouldBeEquivalentToUseRawAsciiOrCharacterAsQuoteConfiguration2.
@Test
public void shouldBeEquivalentToUseRawAsciiOrCharacterAsQuoteConfiguration2() throws Exception {
// GIVEN
// 126 ~ (tilde)
char weirdDelimiter = 126;
String weirdStringDelimiter = "~";
String name1 = weirdDelimiter + "Weird" + weirdDelimiter;
String name2 = "Start " + weirdDelimiter + "middle thing" + weirdDelimiter + " end!";
File data = data(":ID,name", "1," + name1, "2," + name2);
// WHEN given as string
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", data.getAbsolutePath(), "--quote", weirdStringDelimiter);
// THEN
assertEquals(weirdStringDelimiter, "" + weirdDelimiter);
assertEquals(weirdStringDelimiter.charAt(0), weirdDelimiter);
Set<String> names = asSet("Weird", name2);
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
for (Node node : db.getAllNodes()) {
String name = (String) node.getProperty("name");
assertTrue("Didn't expect node with name '" + name + "'", names.remove(name));
}
assertTrue(names.isEmpty());
tx.success();
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class ImportToolTest method shouldSkipEmptyFiles.
@Test
public void shouldSkipEmptyFiles() throws Exception {
// GIVEN
File data = data("");
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", data.getAbsolutePath());
// THEN
GraphDatabaseService graphDatabaseService = dbRule.getGraphDatabaseAPI();
try (Transaction tx = graphDatabaseService.beginTx()) {
ResourceIterator<Node> allNodes = graphDatabaseService.getAllNodes().iterator();
assertFalse("Expected database to be empty", allNodes.hasNext());
tx.success();
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class ConcurrentCreateAndGetRelationshipsIT method tryToReproduceTheIssue.
@Test
public void tryToReproduceTheIssue() throws Exception {
// GIVEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
CountDownLatch startSignal = new CountDownLatch(1);
AtomicBoolean stopSignal = new AtomicBoolean();
AtomicReference<Exception> failure = new AtomicReference<Exception>();
Node parentNode = createNode(db);
Collection<Worker> workers = createWorkers(db, startSignal, stopSignal, failure, parentNode);
// WHEN
startSignal.countDown();
sleep(500);
stopSignal.set(true);
awaitWorkersToEnd(workers);
// THEN
if (failure.get() != null) {
throw new Exception("A worker failed", failure.get());
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class GraphDatabaseServiceExecuteTest method shouldNotReturnInternalCartesianPointType.
@Test
public void shouldNotReturnInternalCartesianPointType() throws Exception {
// given
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
// when
Result execute = graphDb.execute("RETURN point({x: 13.37, y: 13.37, crs:'cartesian'}) AS p");
// then
Object obj = execute.next().get("p");
assertThat(obj, Matchers.instanceOf(Point.class));
Point point = (Point) obj;
assertThat(point.getCoordinate(), equalTo(new Coordinate(13.37, 13.37)));
CRS crs = point.getCRS();
assertThat(crs.getCode(), equalTo(7203));
assertThat(crs.getType(), equalTo("cartesian"));
assertThat(crs.getHref(), equalTo("http://spatialreference.org/ref/sr-org/7203/"));
}
Aggregations