use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class HaCountsIT method createAnIndex.
private NewIndexDescriptor createAnIndex(HighlyAvailableGraphDatabase db, Label label, String propertyName) throws KernelException {
try (Transaction tx = db.beginTx()) {
Statement statement = statement(db);
int labelId = statement.tokenWriteOperations().labelGetOrCreateForName(label.name());
int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(propertyName);
NewIndexDescriptor index = statement.schemaWriteOperations().indexCreate(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId));
tx.success();
return index;
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class HaCountsIT method awaitOnline.
private long awaitOnline(HighlyAvailableGraphDatabase db, NewIndexDescriptor index) throws KernelException {
long start = System.currentTimeMillis();
long end = start + 3000;
while (System.currentTimeMillis() < end) {
try (Transaction tx = db.beginTx()) {
switch(statement(db).readOperations().indexGetState(index)) {
case ONLINE:
return indexingService(db).getIndexId(index.schema());
case FAILED:
throw new IllegalStateException("Index failed instead of becoming ONLINE");
default:
break;
}
tx.success();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignored
}
}
}
throw new IllegalStateException("Index did not become ONLINE within reasonable time");
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class HaCountsIT method assertOnNodeCounts.
private void assertOnNodeCounts(int expectedTotalNodes, int expectedLabelledNodes, Label label, HighlyAvailableGraphDatabase db) {
try (Transaction ignored = db.beginTx()) {
final Statement statement = statement(db);
final int labelId = statement.readOperations().labelGetForName(label.name());
assertEquals(expectedTotalNodes, statement.readOperations().countsForNode(-1));
assertEquals(expectedLabelledNodes, statement.readOperations().countsForNode(labelId));
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class HaCountsIT method createANode.
private void createANode(HighlyAvailableGraphDatabase db, Label label, String value, String property) {
try (Transaction tx = db.beginTx()) {
Node node = db.createNode(label);
node.setProperty(property, value);
tx.success();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TestBasicHaOperations method testBasicPropagationFromSlaveToMaster.
@Test
public void testBasicPropagationFromSlaveToMaster() throws Throwable {
// given
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase master = cluster.getMaster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
long nodeId;
// a node with a property
try (Transaction tx = master.beginTx()) {
Node node = master.createNode();
nodeId = node.getId();
node.setProperty("foo", "bar");
tx.success();
}
cluster.sync();
// the slave does a change
try (Transaction tx = slave.beginTx()) {
slave.getNodeById(nodeId).setProperty("foo", "bar2");
tx.success();
}
// the master must pick up the change
try (Transaction tx = master.beginTx()) {
assertEquals("bar2", master.getNodeById(nodeId).getProperty("foo"));
tx.success();
}
}
Aggregations