Search in sources :

Example 6 with GraphDatabaseService

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();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 7 with GraphDatabaseService

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();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 8 with GraphDatabaseService

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();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) File(java.io.File) Test(org.junit.Test)

Example 9 with GraphDatabaseService

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());
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Node(org.neo4j.graphdb.Node) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 10 with GraphDatabaseService

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/"));
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Coordinate(org.neo4j.graphdb.spatial.Coordinate) CRS(org.neo4j.graphdb.spatial.CRS) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) Point(org.neo4j.graphdb.spatial.Point) Result(org.neo4j.graphdb.Result) 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