}
@Test
public void testReadOnlyOperationsAndNoTransaction()
{
GraphDatabaseService db = new EmbeddedGraphDatabase( PATH );
Transaction tx = db.beginTx();
Node node1 = db.createNode();
Node node2 = db.createNode();
Relationship rel = node1.createRelationshipTo( node2, withName( "TEST" ) );
node1.setProperty( "key1", "value1" );
rel.setProperty( "key1", "value1" );
tx.success();
tx.finish();
// make sure write operations still throw exception
try
{
db.createNode();
fail( "Write operation and no transaction should throw exception" );
}
catch ( NotInTransactionException e )
{ // good
}
try
{
node1.createRelationshipTo( node2, withName( "TEST2" ) );
fail( "Write operation and no transaction should throw exception" );
}
catch ( NotInTransactionException e )
{ // good
}
try
{
node1.setProperty( "key1", "value2" );
fail( "Write operation and no transaction should throw exception" );
}
catch ( NotInTransactionException e )
{ // good
}
try
{
rel.removeProperty( "key1" );
fail( "Write operation and no transaction should throw exception" );
}
catch ( NotInTransactionException e )
{ // good
}
// clear caches and try reads
((AbstractGraphDatabase)db).getConfig().getGraphDbModule().
getNodeManager().clearCache();
assertEquals( node1, db.getNodeById( node1.getId() ) );
assertEquals( node2, db.getNodeById( node2.getId() ) );
assertEquals( rel, db.getRelationshipById( rel.getId() ) );
((AbstractGraphDatabase)db).getConfig().getGraphDbModule().
getNodeManager().clearCache();
assertEquals( "value1", node1.getProperty( "key1" ) );
Relationship loadedRel = node1.getSingleRelationship(