Search in sources :

Example 51 with Label

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

the class SubGraphExporter method labelString.

private String labelString(Node node) {
    Iterator<Label> labels = node.getLabels().iterator();
    if (!labels.hasNext()) {
        return "";
    }
    StringBuilder result = new StringBuilder();
    while (labels.hasNext()) {
        Label next = labels.next();
        result.append(":").append(quote(next.name()));
    }
    return result.toString();
}
Also used : Label(org.neo4j.graphdb.Label)

Example 52 with Label

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

the class TestShortestPath method shouldAbortAsSoonAsPossible.

// Attempt at recreating this issue without cypher
// https://github.com/neo4j/neo4j/issues/4160
@Test
public void shouldAbortAsSoonAsPossible() {
    final Label A = Label.label("A");
    final Label B = Label.label("B");
    final Label C = Label.label("C");
    final Label D = Label.label("D");
    final Label E = Label.label("E");
    final Label F = Label.label("F");
    final RelationshipType relType = RelationshipType.withName("TO");
    recursiveSnowFlake(null, 0, 4, 5, new Label[] { A, B, C, D, E }, relType);
    final Node a = graphDb.findNodes(A).next();
    final ResourceIterator<Node> allE = graphDb.findNodes(E);
    while (allE.hasNext()) {
        final Node e = allE.next();
        final Node f = graphDb.createNode(F);
        f.createRelationshipTo(e, relType);
    }
    final CountingPathExpander countingPathExpander = new CountingPathExpander(PathExpanders.forTypeAndDirection(relType, Direction.OUTGOING));
    final ShortestPath shortestPath = new ShortestPath(Integer.MAX_VALUE, countingPathExpander, Integer.MAX_VALUE);
    final ResourceIterator<Node> allF = graphDb.findNodes(F);
    final long start = System.currentTimeMillis();
    while (allF.hasNext()) {
        final Node f = allF.next();
        shortestPath.findAllPaths(a, f);
    }
    final long totalTime = System.currentTimeMillis() - start;
    assertEquals("There are 625 different end nodes. The algorithm should start one traversal for each such node. " + "That is 625*2 visited nodes if traversal is interrupted correctly.", 1250, countingPathExpander.nodesVisited.intValue());
}
Also used : Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) RelationshipType(org.neo4j.graphdb.RelationshipType) Test(org.junit.Test)

Example 53 with Label

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

the class ImportToolTest method shouldHandleAdditiveLabelsWithSpaces.

@Test
public void shouldHandleAdditiveLabelsWithSpaces() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    final Label label1 = label("My First Label");
    final Label label2 = label("My Other Label");
    // WHEN
    importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes:My First Label:My Other Label", nodeData(true, config, nodeIds, TRUE).getAbsolutePath(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true).getAbsolutePath());
    // THEN
    verifyData(node -> {
        assertTrue(node.hasLabel(label1));
        assertTrue(node.hasLabel(label2));
    }, Validators.<Relationship>emptyValidator());
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) Label(org.neo4j.graphdb.Label) DynamicLabel(org.neo4j.graphdb.DynamicLabel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 54 with Label

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

the class BackupServiceIT method incrementallyBackupDatabaseShouldNotKeepGeneratedIdFiles.

/*
     * During incremental backup destination db should not track free ids independently from source db
     * for now we will always cleanup id files generated after incremental backup and will regenerate them afterwards
     * This should prevent situation when destination db free id following master, but never allocates it from
     * generator till some db will be started on top of it.
     * That will cause all sorts of problems with several entities in a store with same id.
     *
     * As soon as backup will be able to align ids between participants please remove description and adapt test.
     */
@Test
public void incrementallyBackupDatabaseShouldNotKeepGeneratedIdFiles() {
    defaultBackupPortHostParams();
    GraphDatabaseAPI graphDatabase = dbRule.getGraphDatabaseAPI();
    Label markerLabel = Label.label("marker");
    try (Transaction transaction = graphDatabase.beginTx()) {
        Node node = graphDatabase.createNode();
        node.addLabel(markerLabel);
        transaction.success();
    }
    try (Transaction transaction = graphDatabase.beginTx()) {
        Node node = findNodeByLabel(graphDatabase, markerLabel);
        for (int i = 0; i < 10; i++) {
            node.setProperty("property" + i, "testValue" + i);
        }
        transaction.success();
    }
    // propagate to backup node and properties
    doIncrementalBackupOrFallbackToFull();
    // removing properties will free couple of ids that will be reused during next properties creation
    try (Transaction transaction = graphDatabase.beginTx()) {
        Node node = findNodeByLabel(graphDatabase, markerLabel);
        for (int i = 0; i < 6; i++) {
            node.removeProperty("property" + i);
        }
        transaction.success();
    }
    // propagate removed properties
    doIncrementalBackupOrFallbackToFull();
    try (Transaction transaction = graphDatabase.beginTx()) {
        Node node = findNodeByLabel(graphDatabase, markerLabel);
        for (int i = 10; i < 16; i++) {
            node.setProperty("property" + i, "updatedValue" + i);
        }
        transaction.success();
    }
    // propagate to backup new properties with reclaimed ids
    doIncrementalBackupOrFallbackToFull();
    // it should be possible to at this point to start db based on our backup and create couple of properties
    // their ids should not clash with already existing
    GraphDatabaseService backupBasedDatabase = new TestGraphDatabaseFactory().newEmbeddedDatabase(backupDir.getAbsoluteFile());
    try {
        try (Transaction transaction = backupBasedDatabase.beginTx()) {
            Node node = findNodeByLabel((GraphDatabaseAPI) backupBasedDatabase, markerLabel);
            Iterable<String> propertyKeys = node.getPropertyKeys();
            for (String propertyKey : propertyKeys) {
                node.setProperty(propertyKey, "updatedClientValue" + propertyKey);
            }
            node.setProperty("newProperty", "updatedClientValue");
            transaction.success();
        }
        try (Transaction transaction = backupBasedDatabase.beginTx()) {
            Node node = findNodeByLabel((GraphDatabaseAPI) backupBasedDatabase, markerLabel);
            // newProperty + 10 defined properties.
            assertEquals("We should be able to see all previously defined properties.", 11, Iterables.asList(node.getPropertyKeys()).size());
        }
    } finally {
        backupBasedDatabase.shutdown();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) TestGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 55 with Label

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

the class RelationshipIdReuseStressIT method relationshipIdReused.

@Test
public void relationshipIdReused() throws Exception {
    Label cityLabel = Label.label("city");
    final Label bandLabel = Label.label("band");
    createBands(bandLabel);
    createCities(cityLabel);
    AtomicBoolean stopFlag = new AtomicBoolean(false);
    RelationshipsCreator relationshipsCreator = new RelationshipsCreator(stopFlag, bandLabel, cityLabel);
    List<Future> futures = new ArrayList<>();
    futures.add(startRelationshipRemoval(bandLabel, cityLabel, stopFlag));
    futures.add(startRelationshipsCreator(relationshipsCreator));
    futures.add(startRelationshipTypesCalculator(bandLabel, stopFlag));
    futures.add(startRelationshipCalculator(bandLabel, stopFlag));
    TimeUnit.SECONDS.sleep(5);
    stopFlag.set(true);
    executorService.shutdown();
    executorService.awaitTermination(5, TimeUnit.SECONDS);
    completeFutures(futures);
    long highestPossibleIdInUse = getHighestUsedIdForRelationships();
    assertThat("Number of created relationships should be higher then highest possible id, since those are " + "reused.", relationshipsCreator.getCreatedRelationships(), Matchers.greaterThan(highestPossibleIdInUse));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Label(org.neo4j.graphdb.Label) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) Test(org.junit.Test)

Aggregations

Label (org.neo4j.graphdb.Label)82 Test (org.junit.Test)55 Node (org.neo4j.graphdb.Node)48 Transaction (org.neo4j.graphdb.Transaction)44 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)12 RelationshipType (org.neo4j.graphdb.RelationshipType)8 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 DynamicLabel (org.neo4j.graphdb.DynamicLabel)6 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)6 Statement (org.neo4j.kernel.api.Statement)6 ArrayList (java.util.ArrayList)5 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)5 Relationship (org.neo4j.graphdb.Relationship)5 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)5 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)5 File (java.io.File)4 HashSet (java.util.HashSet)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)4