use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class LabelRecoveryTest method shouldRecoverNodeWithDynamicLabelRecords.
/**
* Reading a node command might leave a node record which referred to
* labels in one or more dynamic records as marked as heavy even if that
* node already had references to dynamic records, changed in a transaction,
* but had no labels on that node changed within that same transaction.
* Now defensively only marks as heavy if there were one or more dynamic
* records provided when providing the record object with the label field
* value. This would give the opportunity to load the dynamic records the
* next time that record would be ensured heavy.
*/
@Test
public void shouldRecoverNodeWithDynamicLabelRecords() throws Exception {
// GIVEN
database = new TestGraphDatabaseFactory().setFileSystem(fs).newImpermanentDatabase();
Node node;
Label[] labels = new Label[] { label("a"), label("b"), label("c"), label("d"), label("e"), label("f"), label("g"), label("h"), label("i"), label("j"), label("k") };
try (Transaction tx = database.beginTx()) {
node = database.createNode(labels);
tx.success();
}
// WHEN
try (Transaction tx = database.beginTx()) {
node.setProperty("prop", "value");
tx.success();
}
EphemeralFileSystemAbstraction snapshot = fs.snapshot();
database.shutdown();
database = new TestGraphDatabaseFactory().setFileSystem(snapshot).newImpermanentDatabase();
// THEN
try (Transaction ignored = database.beginTx()) {
node = database.getNodeById(node.getId());
for (Label label : labels) {
assertTrue(node.hasLabel(label));
}
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class RelationshipProxyTest method createDropRelationshipLongArrayProperty.
@Test
public void createDropRelationshipLongArrayProperty() {
Label markerLabel = DynamicLabel.label("marker");
String testPropertyKey = "testProperty";
byte[] propertyValue = RandomUtils.nextBytes(1024);
try (Transaction tx = db.beginTx()) {
Node start = db.createNode(markerLabel);
Node end = db.createNode(markerLabel);
Relationship relationship = start.createRelationshipTo(end, withName("type"));
relationship.setProperty(testPropertyKey, propertyValue);
tx.success();
}
try (Transaction tx = db.beginTx()) {
Relationship relationship = db.getRelationshipById(0);
assertArrayEquals(propertyValue, (byte[]) relationship.getProperty(testPropertyKey));
tx.success();
}
try (Transaction tx = db.beginTx()) {
Relationship relationship = db.getRelationshipById(0);
relationship.removeProperty(testPropertyKey);
tx.success();
}
try (Transaction tx = db.beginTx()) {
Relationship relationship = db.getRelationshipById(0);
assertFalse(relationship.hasProperty(testPropertyKey));
tx.success();
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class TestConcurrentIteratorModification method shouldNotThrowConcurrentModificationExceptionWhenUpdatingWhileIterating.
@Test
public void shouldNotThrowConcurrentModificationExceptionWhenUpdatingWhileIterating() {
// given
GraphDatabaseService graph = dbRule.getGraphDatabaseAPI();
Label label = Label.label("Bird");
Node node1, node2, node3;
try (Transaction tx = graph.beginTx()) {
node1 = graph.createNode(label);
node2 = graph.createNode(label);
tx.success();
}
// when
Set<Node> result = new HashSet<>();
try (Transaction tx = graph.beginTx()) {
node3 = graph.createNode(label);
ResourceIterator<Node> iterator = graph.findNodes(label);
node3.removeLabel(label);
graph.createNode(label);
while (iterator.hasNext()) {
result.add(iterator.next());
}
tx.success();
}
// then does not throw and retains view from iterator creation time
assertEquals(asSet(node1, node2), result);
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class NodeProxyTest method createDropNodeLongStringProperty.
@Test
public void createDropNodeLongStringProperty() {
Label markerLabel = Label.label("marker");
String testPropertyKey = "testProperty";
String propertyValue = RandomStringUtils.randomAscii(255);
try (Transaction tx = db.beginTx()) {
Node node = db.createNode(markerLabel);
node.setProperty(testPropertyKey, propertyValue);
tx.success();
}
try (Transaction tx = db.beginTx()) {
Node node = Iterators.single(db.findNodes(markerLabel));
assertEquals(propertyValue, node.getProperty(testPropertyKey));
tx.success();
}
try (Transaction tx = db.beginTx()) {
Node node = Iterators.single(db.findNodes(markerLabel));
node.removeProperty(testPropertyKey);
tx.success();
}
try (Transaction tx = db.beginTx()) {
Node node = Iterators.single(db.findNodes(markerLabel));
assertFalse(node.hasProperty(testPropertyKey));
tx.success();
}
}
use of org.neo4j.graphdb.Label in project neo4j by neo4j.
the class TestTransactionEvents method nodeCanBecomeSchemaIndexableInBeforeCommitByAddingProperty.
@Test
public void nodeCanBecomeSchemaIndexableInBeforeCommitByAddingProperty() throws Exception {
// Given we have a schema index...
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
Label label = label("Label");
IndexDefinition index;
try (Transaction tx = db.beginTx()) {
index = db.schema().indexFor(label).on("indexed").create();
tx.success();
}
// ... and a transaction event handler that likes to add the indexed property on nodes
db.registerTransactionEventHandler(new TransactionEventHandler.Adapter<Object>() {
@Override
public Object beforeCommit(TransactionData data) throws Exception {
Iterator<Node> nodes = data.createdNodes().iterator();
if (nodes.hasNext()) {
Node node = nodes.next();
node.setProperty("indexed", "value");
}
return null;
}
});
// When we create a node with the right label, but not the right property...
try (Transaction tx = db.beginTx()) {
db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
Node node = db.createNode(label);
node.setProperty("random", 42);
tx.success();
}
// Then we should be able to look it up through the index.
try (Transaction ignore = db.beginTx()) {
Node node = db.findNode(label, "indexed", "value");
assertThat(node.getProperty("random"), is((Object) 42));
}
}
Aggregations