use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class Mknode method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws Exception {
GraphDatabaseAPI db = getServer().getDb();
Node node = db.createNode(parseLabels(parser));
setProperties(node, parser.option("np", null));
if (parser.options().containsKey("cd")) {
cdTo(session, node);
}
if (parser.options().containsKey("v")) {
out.println("Node " + getDisplayName(getServer(), session, node, false) + " created");
}
return Continuation.INPUT_COMPLETE;
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class Rm method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws Exception {
NodeOrRelationship thing = getCurrent(session);
boolean forProperty = parser.options().containsKey("p");
boolean forLabel = parser.options().containsKey("l");
if (forProperty || !forLabel) {
// Property
if (parser.arguments().isEmpty()) {
throw new ShellException("Must supply the property key or label name to " + "remove, like: rm title");
}
String key = parser.arguments().get(0);
if (thing.removeProperty(key) == null) {
out.println("Property '" + key + "' not found");
}
} else {
Node node = thing.asNode();
for (Label label : parseLabels(parser)) {
node.removeLabel(label);
}
}
return Continuation.INPUT_COMPLETE;
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class AbstractShellIT method getCurrentNode.
protected Node getCurrentNode() throws RemoteException, ShellException {
Serializable current = shellServer.interpretVariable(shellClient.getId(), Variables.CURRENT_KEY);
int nodeId = parseInt(current.toString().substring(1));
try (Transaction tx = db.beginTx()) {
Node nodeById = db.getNodeById(nodeId);
tx.success();
return nodeById;
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ClusterLocksIT method takeExclusiveLockOnSameNodeAfterSwitch.
private void takeExclusiveLockOnSameNodeAfterSwitch(Label testLabel, HighlyAvailableGraphDatabase master, HighlyAvailableGraphDatabase db) throws EntityNotFoundException {
try (Transaction transaction = db.beginTx()) {
Node node = getNode(master, testLabel);
transaction.acquireWriteLock(node);
node.setProperty("key", "value");
transaction.success();
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TransactionThroughMasterSwitchStressIT method oneRound.
private void oneRound() throws Throwable {
// GIVEN a cluster and a node
final String key = "key";
ManagedCluster cluster = clusterRule.startCluster();
final GraphDatabaseService master = cluster.getMaster();
final long nodeId = createNode(master);
cluster.sync();
// and a bunch of workers contending on that node, each changing it
Workers<Runnable> transactors = new Workers<>("Transactors");
final AtomicInteger successes = new AtomicInteger();
final AtomicBoolean end = new AtomicBoolean();
for (int i = 0; i < 10; i++) {
transactors.start(new Runnable() {
@Override
public void run() {
Random random = ThreadLocalRandom.current();
while (!end.get()) {
boolean committed = true;
try (Transaction tx = master.beginTx()) {
Node node = master.getNodeById(nodeId);
// Acquiring lock, read int property value, increment, set incremented int property
// should not break under any circumstances.
tx.acquireWriteLock(node);
node.setProperty(key, (Integer) node.getProperty(key, 0) + 1);
// Throw in relationship for good measure
node.createRelationshipTo(master.createNode(), TEST);
Thread.sleep(random.nextInt(1_000));
tx.success();
} catch (Throwable e) {
// It's OK
committed = false;
}
if (committed) {
successes.incrementAndGet();
}
}
}
});
}
// WHEN entering a period of induced cluster instabilities
reelectTheSameMasterMakingItGoToPendingAndBack(cluster);
// ... letting transactions run a bit after the role switch as well.
long targetSuccesses = successes.get() + 20;
while (successes.get() < targetSuccesses) {
Thread.sleep(100);
}
end.set(true);
transactors.awaitAndThrowOnError(RuntimeException.class);
// THEN verify that the count is equal to the number of successful transactions
assertEquals(successes.get(), getNodePropertyValue(master, nodeId, key));
}
Aggregations