use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TestGraphProperties method testEquals.
@Test
public void testEquals() {
GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
PropertyContainer graphProperties = properties(db);
try (Transaction tx = db.beginTx()) {
graphProperties.setProperty("test", "test");
tx.success();
}
assertEquals(graphProperties, properties(db));
db.shutdown();
db = (GraphDatabaseAPI) factory.newImpermanentDatabase();
assertFalse(graphProperties.equals(properties(db)));
db.shutdown();
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class TestGraphProperties method produceUncleanStore.
private EphemeralFileSystemAbstraction produceUncleanStore(EphemeralFileSystemAbstraction fileSystem, File storeDir) {
GraphDatabaseService db = new TestGraphDatabaseFactory().setFileSystem(fileSystem).newImpermanentDatabase(storeDir);
Transaction tx = db.beginTx();
Node node = db.createNode();
node.setProperty("name", "Something");
properties((GraphDatabaseAPI) db).setProperty("prop", "Some value");
tx.success();
tx.close();
EphemeralFileSystemAbstraction snapshot = fileSystem.snapshot();
db.shutdown();
return snapshot;
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class RelationshipChainExplorerTest method createStoreWithOneHighDegreeNodeAndSeveralDegreeTwoNodes.
private StoreAccess createStoreWithOneHighDegreeNodeAndSeveralDegreeTwoNodes(int nDegreeTwoNodes) {
File storeDirectory = storeLocation.graphDbDir();
GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDirectory).setConfig(GraphDatabaseSettings.record_format, getRecordFormatName()).newGraphDatabase();
try (Transaction transaction = database.beginTx()) {
Node denseNode = database.createNode();
for (int i = 0; i < nDegreeTwoNodes; i++) {
Node degreeTwoNode = database.createNode();
Node leafNode = database.createNode();
if (i % 2 == 0) {
denseNode.createRelationshipTo(degreeTwoNode, TestRelationshipType.CONNECTED);
} else {
degreeTwoNode.createRelationshipTo(denseNode, TestRelationshipType.CONNECTED);
}
degreeTwoNode.createRelationshipTo(leafNode, TestRelationshipType.CONNECTED);
}
transaction.success();
}
database.shutdown();
PageCache pageCache = pageCacheRule.getPageCache(fileSystemRule.get());
StoreAccess storeAccess = new StoreAccess(fileSystemRule.get(), pageCache, storeDirectory, Config.empty());
return storeAccess.initialize();
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class RecoveryIT method recoveryShouldFixPartiallyAppliedSchemaIndexUpdates.
@Test(timeout = 60_000)
public void recoveryShouldFixPartiallyAppliedSchemaIndexUpdates() {
Label label = Label.label("Foo");
String property = "Bar";
// cause failure during 'relationship.delete()' command application
ClassGuardedAdversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, true), Command.RelationshipCommand.class);
adversary.disable();
File storeDir = directory.graphDbDir();
GraphDatabaseService db = AdversarialPageCacheGraphDatabaseFactory.create(fileSystemRule.get(), adversary).newEmbeddedDatabaseBuilder(storeDir).newGraphDatabase();
try {
try (Transaction tx = db.beginTx()) {
db.schema().constraintFor(label).assertPropertyIsUnique(property).create();
tx.success();
}
long relationshipId = createRelationship(db);
TransactionFailureException txFailure = null;
try (Transaction tx = db.beginTx()) {
Node node = db.createNode(label);
node.setProperty(property, "B");
// this should fail because of the adversary
db.getRelationshipById(relationshipId).delete();
tx.success();
adversary.enable();
} catch (TransactionFailureException e) {
txFailure = e;
}
assertNotNull(txFailure);
adversary.disable();
// heal the db so it is possible to inspect the data
healthOf(db).healed();
// now we can observe partially committed state: node is in the index and relationship still present
try (Transaction tx = db.beginTx()) {
assertNotNull(findNode(db, label, property, "B"));
assertNotNull(db.getRelationshipById(relationshipId));
tx.success();
}
// panic the db again to force recovery on the next startup
healthOf(db).panic(txFailure.getCause());
// restart the database, now with regular page cache
db.shutdown();
db = startDatabase(storeDir);
// now we observe correct state: node is in the index and relationship is removed
try (Transaction tx = db.beginTx()) {
assertNotNull(findNode(db, label, property, "B"));
assertRelationshipNotExist(db, relationshipId);
tx.success();
}
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class CompositeIndexingIT method shouldSeeAllNodesAddedBeforeTransaction.
@Test
public void shouldSeeAllNodesAddedBeforeTransaction() throws Exception {
if (// this test does not make any sense for UNIQUE indexes
index.type() != UNIQUE) {
long nodeID1 = createNode();
long nodeID2 = createNode();
long nodeID3 = createNode();
try (Transaction ignore = graphDatabaseAPI.beginTx()) {
PrimitiveLongIterator resultIterator = seek();
Set<Long> result = PrimitiveLongCollections.toSet(resultIterator);
assertThat(result, contains(nodeID1, nodeID2, nodeID3));
}
}
}
Aggregations