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