@Override protected void after() { success(); }
public void commit() { tx.success(); }
private void newTx() { tx.success(); tx.begin(); }
@Test public void shouldGiveHelpfulExceptionWhenDeletingNodeWithRels() { // Given Node node; node = db.createNode(); Node node2 = db.createNode(); node.createRelationshipTo( node2, RelationshipType.withName( "MAYOR_OF" ) ); tx.success(); // And given a transaction deleting just the node tx.begin(); node.delete(); // Expect exception.expect( ConstraintViolationException.class ); exception.expectMessage( "Cannot delete node<" + node.getId() + ">, because it still has relationships. " + "To delete this node, you must first delete its relationships." ); // When I commit tx.success(); }
@Test public void testChangeProperty2() { Node node = getGraphDb().createNode(); node.setProperty( "test", "test1" ); tx.success(); tx.begin(); node.removeProperty( "test" ); node.setProperty( "test", "test3" ); assertEquals( "test3", node.getProperty( "test" ) ); tx.success(); tx.begin(); assertEquals( "test3", node.getProperty( "test" ) ); node.removeProperty( "test" ); node.setProperty( "test", "test4" ); tx.success(); tx.begin(); assertEquals( "test4", node.getProperty( "test" ) ); }
@Test public void makeSureNodeStaysLockedEvenAfterManualRelease() throws Exception { String key = "name"; Node node = getGraphDb().createNode(); tx.success(); Transaction current = tx.begin(); Lock nodeLock = current.acquireWriteLock( node ); node.setProperty( key, "value" ); nodeLock.release(); worker.beginTx(); try { worker.setProperty( node, key, "ksjd" ); fail( "Shouldn't be able to grab it" ); } catch ( Exception ignored ) { } tx.success(); try { worker.finishTx(); } catch ( ExecutionException e ) { // Ok, interrupting the thread while it's waiting for a lock will lead to tx failure. } }
@Test public void testChangeProperty() { Node node = getGraphDb().createNode(); node.setProperty( "test", "test1" ); tx.success(); tx.begin(); node.setProperty( "test", "test2" ); node.removeProperty( "test" ); node.setProperty( "test", "test3" ); assertEquals( "test3", node.getProperty( "test" ) ); node.removeProperty( "test" ); node.setProperty( "test", "test4" ); tx.success(); tx.begin(); assertEquals( "test4", node.getProperty( "test" ) ); }
@Test public void canOnlyReleaseOnce() { Node node = getGraphDb().createNode(); tx.success(); Transaction current = tx.begin(); Lock nodeLock = current.acquireWriteLock( node ); nodeLock.release(); try { nodeLock.release(); fail( "Shouldn't be able to release more than once" ); } catch ( IllegalStateException e ) { // Good } }
@Test public void testNodeCreateAndDelete() { Node node = getGraphDb().createNode(); long nodeId = node.getId(); getGraphDb().getNodeById( nodeId ); node.delete(); tx.success(); tx.begin(); try { getGraphDb().getNodeById( nodeId ); fail( "Node[" + nodeId + "] should be deleted." ); } catch ( NotFoundException ignored ) { } }
@Test public void releaseReleaseManually() throws Exception { String key = "name"; Node node = getGraphDb().createNode(); tx.success(); Transaction current = tx.begin(); Lock nodeLock = current.acquireWriteLock( node ); worker.beginTx(); try { worker.setProperty( node, key, "ksjd" ); fail( "Shouldn't be able to grab it" ); } catch ( Exception ignored ) { } nodeLock.release(); worker.setProperty( node, key, "yo" ); try { worker.finishTx(); } catch ( ExecutionException e ) { // Ok, interrupting the thread while it's waiting for a lock will lead to tx failure. } }
@Override protected void after() { success(); }