use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TestMigrateToDenseNodeSupport method migrateDbWithDenseNodes.
@Test
public void migrateDbWithDenseNodes() throws Exception {
// migrate
new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(dir).setConfig(allow_store_upgrade, "true").newGraphDatabase().shutdown();
// check consistency
assertConsistentStore(dir);
// open again to do extra checks
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(dir).newGraphDatabase();
try (Transaction tx = db.beginTx()) {
ResourceIterator<Node> allNodesWithLabel = db.findNodes(referenceNode);
Node refNode = Iterators.single(allNodesWithLabel);
int sparseCount = 0;
for (Relationship relationship : refNode.getRelationships(Types.SPARSE, OUTGOING)) {
verifySparseNode(db, relationship.getEndNode());
sparseCount++;
}
int denseCount = 0;
for (Relationship relationship : refNode.getRelationships(Types.DENSE, OUTGOING)) {
verifyDenseNode(db, relationship.getEndNode());
denseCount++;
}
assertEquals(10, sparseCount);
assertEquals(10, denseCount);
tx.success();
}
db.shutdown();
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TestPropertyReadOnNewEntityBeforeLockRelease method initializeIndex.
@BeforeClass
public static void initializeIndex() throws Exception {
try (Transaction tx = db.beginTx()) {
Node node = db.createNode();
db.index().forNodes(INDEX_NAME).add(node, "foo", "bar");
tx.success();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class RestoreDatabaseCommandTest method shouldAllowForcedCopyOverAnExistingDatabase.
@Test
public void shouldAllowForcedCopyOverAnExistingDatabase() throws Exception {
// given
String databaseName = "to";
Config config = configWith(Config.empty(), databaseName, directory.absolutePath().getAbsolutePath());
File fromPath = new File(directory.absolutePath(), "from");
File toPath = config.get(DatabaseManagementSystemSettings.database_path);
int fromNodeCount = 10;
int toNodeCount = 20;
createDbAt(fromPath, fromNodeCount);
createDbAt(toPath, toNodeCount);
// when
new RestoreDatabaseCommand(fileSystemRule.get(), fromPath, config, databaseName, true).execute();
// then
GraphDatabaseService copiedDb = new GraphDatabaseFactory().newEmbeddedDatabase(toPath);
try (Transaction ignored = copiedDb.beginTx()) {
assertEquals(fromNodeCount, Iterables.count(copiedDb.getAllNodes()));
}
copiedDb.shutdown();
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class ConcurrentInstanceStartupIT method concurrentStartupShouldWork.
@Test
public void concurrentStartupShouldWork() throws Exception {
// Ensures that the instances don't race to create the test's base directory and only care about their own.
testDirectory.directory("nothingToSeeHereMoveAlong");
StringBuffer initialHostsBuffer = new StringBuffer("127.0.0.1:5001");
for (int i = 2; i <= INSTANCE_COUNT; i++) {
initialHostsBuffer.append(",127.0.0.1:500" + i);
}
final String initialHosts = initialHostsBuffer.toString();
final CyclicBarrier barrier = new CyclicBarrier(INSTANCE_COUNT);
final List<Thread> daThreads = new ArrayList<Thread>(INSTANCE_COUNT);
final HighlyAvailableGraphDatabase[] dbs = new HighlyAvailableGraphDatabase[INSTANCE_COUNT];
for (int i = 1; i <= INSTANCE_COUNT; i++) {
final int finalI = i;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
barrier.await();
dbs[finalI - 1] = startDbAtBase(finalI, initialHosts);
} catch (InterruptedException | BrokenBarrierException e) {
throw new RuntimeException(e);
}
}
});
daThreads.add(t);
t.start();
}
for (Thread daThread : daThreads) {
daThread.join();
}
boolean masterDone = false;
for (HighlyAvailableGraphDatabase db : dbs) {
if (db.isMaster()) {
if (masterDone) {
throw new Exception("Two masters discovered");
}
masterDone = true;
}
try (Transaction tx = db.beginTx()) {
db.createNode();
tx.success();
}
}
assertTrue(masterDone);
for (HighlyAvailableGraphDatabase db : dbs) {
db.shutdown();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class DeletionTest method shouldDeleteRecords.
/**
* The problem would manifest even if the transaction was performed on the Master, it would then occur when the
* Slave pulls updates and tries to apply the transaction. The reason for the test to run transactions against the
* Slave is because it makes guarantees for when the master has to apply the transaction.
*/
@Test
public void shouldDeleteRecords() throws Throwable {
// given
ManagedCluster cluster = clusterRule.startCluster();
HighlyAvailableGraphDatabase master = cluster.getMaster();
HighlyAvailableGraphDatabase slave = cluster.getAnySlave();
Relationship rel;
try (Transaction tx = slave.beginTx()) {
rel = slave.createNode().createRelationshipTo(slave.createNode(), withName("FOO"));
tx.success();
}
try (Transaction transaction = master.beginTx()) {
assertNotNull(master.getRelationshipById(rel.getId()));
}
// when
try (Transaction tx = slave.beginTx()) {
rel.delete();
tx.success();
}
// then - there should have been no exceptions
slave.shutdown();
master.shutdown();
}
Aggregations