public void failure() { try { if ( tx != null ) { tx.failure(); tx.close(); } } finally { tx = null; } } }
@Override public Void doWork( CommandState state ) { state.tx.failure(); state.tx.close(); state.tx = null; return null; } }
public void rollback() { if ( tx != null ) { try { tx.failure(); tx.close(); } finally { tx = null; } } }
@Test public void shouldRollbackParentIfFailureCalled() { // When placeboTx.failure(); placeboTx.close(); // Then verify( kernelTransaction, times(2) ).failure(); // We accept two calls to failure, since KernelTX#failure is idempotent }
@Test public void successCannotOverrideFailure() { // When placeboTx.failure(); placeboTx.success(); placeboTx.close(); // Then verify( kernelTransaction ).failure(); verify( kernelTransaction, never() ).success(); }
private long countNodes( String... labels ) { Set<Label> givenLabels = new HashSet<>( labels.length ); for ( String label : labels ) { givenLabels.add( Label.label( label ) ); } try ( Transaction transaction = graphdb().beginTx() ) { long count = 0; for ( Node node : graphdb().getAllNodes() ) { Set<Label> nodeLabels = Iterables.asSet( node.getLabels() ); if ( nodeLabels.containsAll( givenLabels ) ) { count++; } } transaction.failure(); return count; } }
@Test public void testRelationshipAddPropertyWithNullValue() { Node node1 = getGraphDb().createNode(); Node node2 = getGraphDb().createNode(); Relationship rel1 = node1.createRelationshipTo( node2, TEST ); try { rel1.setProperty( "foo", null ); fail( "Null value should result in exception." ); } catch ( IllegalArgumentException e ) { // OK } getTransaction().failure(); }
@Test public void shouldRemoveIndexForConstraintEvenIfDroppedInCreatingTransaction() { try ( Transaction tx = graphDb.beginTx() ) { // given graphDb.schema() .constraintFor( LABEL ).assertPropertyIsUnique( PROPERTY_KEY ) .create() .drop(); // when - rolling back tx.failure(); } // then assertNull( "Should not have constraint index", getIndex( LABEL, PROPERTY_KEY ) ); }
@Test public void shouldCountRolledBackTransactions() throws Exception { GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase(); try { TransactionCounters counts = db.getDependencyResolver().resolveDependency( TransactionCounters.class ); TransactionCountersChecker checker = new TransactionCountersChecker( counts ); try ( Transaction tx = db.beginTx() ) { dbConsumer.accept( db ); tx.failure(); } checker.verifyRolledBacked( isWriteTx, counts ); } finally { db.shutdown(); } }
@Override public void onRollback() { if (tx != null && isTransactionInProgress) { tx.failure(); tx.finish(); nodeIds.clear(); processedNodes.clear(); } tx = null; isTransactionInProgress = false; }
transaction.failure();
@Test public void onlineConstraintShouldRejectChangingEntryToAlreadyIndexedValueThatOtherTransactionsAreRemoving() { // Given givenOnlineConstraint(); transaction( setProperty( b, "b" ), success ); Transaction otherTx = db.beginTx(); a.removeLabel( label ); suspend( otherTx ); // When try { transaction( setProperty( b, "a" ), success, fail( "Changing a property to an already indexed value should have thrown" ) ); } catch ( ConstraintViolationException ignore ) { // we're happy } finally { resume( otherTx ); otherTx.failure(); otherTx.close(); } }
@Test public void testRollbackDeleteRelationship() { Node node1 = getGraphDb().createNode(); Node node2 = getGraphDb().createNode(); Relationship rel1 = node1.createRelationshipTo( node2, TEST ); newTransaction(); node1.delete(); rel1.delete(); getTransaction().failure(); getTransaction().close(); setTransaction( getGraphDb().beginTx() ); node1.delete(); node2.delete(); rel1.delete(); }
tx.failure(); tx.close();
tx.failure(); tx.close();
@After public void tearDown() throws Exception { if (tx!=null) { tx.failure(); tx.close(); } } @AfterClass
@Test public void testRelationshipAddProperty() { Node node1 = getGraphDb().createNode(); Node node2 = getGraphDb().createNode(); Relationship rel1 = node1.createRelationshipTo( node2, TEST ); Relationship rel2 = node2.createRelationshipTo( node1, TEST ); Integer int1 = 1; Integer int2 = 2; String string1 = "1"; String string2 = "2"; // add property rel1.setProperty( key1, int1 ); rel2.setProperty( key1, string1 ); rel1.setProperty( key2, string2 ); rel2.setProperty( key2, int2 ); assertTrue( rel1.hasProperty( key1 ) ); assertTrue( rel2.hasProperty( key1 ) ); assertTrue( rel1.hasProperty( key2 ) ); assertTrue( rel2.hasProperty( key2 ) ); assertTrue( !rel1.hasProperty( key3 ) ); assertTrue( !rel2.hasProperty( key3 ) ); assertEquals( int1, rel1.getProperty( key1 ) ); assertEquals( string1, rel2.getProperty( key1 ) ); assertEquals( string2, rel1.getProperty( key2 ) ); assertEquals( int2, rel2.getProperty( key2 ) ); getTransaction().failure(); }
getTransaction().failure();
@Test public void testMetaIsType() throws Exception { try (Transaction tx = db.beginTx()) { Node node = db.createNode(); Relationship rel = node.createRelationshipTo(node, RelationshipType.withName("FOO")); testIsTypeName(node, "NODE"); testIsTypeName(rel, "RELATIONSHIP"); Path path = db.traversalDescription().evaluator(toDepth(1)).traverse(node).iterator().next(); // TODO PATH FAILS testIsTypeName(path, "PATH"); tx.failure(); } testIsTypeName(singletonMap("a", 10), "MAP"); testIsTypeName(asList(1, 2), "LIST"); testIsTypeName(1L, "INTEGER"); testIsTypeName(1, "INTEGER"); testIsTypeName(1.0D, "FLOAT"); testIsTypeName(1.0, "FLOAT"); testIsTypeName("a", "STRING"); testIsTypeName(false, "BOOLEAN"); testIsTypeName(true, "BOOLEAN"); testIsTypeName(null, "NULL"); } @Test
@Test public void testMetaType() throws Exception { try (Transaction tx = db.beginTx()) { Node node = db.createNode(); Relationship rel = node.createRelationshipTo(node, RelationshipType.withName("FOO")); testTypeName(node, "NODE"); testTypeName(rel, "RELATIONSHIP"); Path path = db.traversalDescription().evaluator(toDepth(1)).traverse(node).iterator().next(); // TODO PATH FAILS testTypeName(path, "PATH"); tx.failure(); } testTypeName(singletonMap("a", 10), "MAP"); testTypeName(asList(1, 2), "LIST"); testTypeName(1L, "INTEGER"); testTypeName(1, "INTEGER"); testTypeName(1.0D, "FLOAT"); testTypeName(1.0, "FLOAT"); testTypeName("a", "STRING"); testTypeName(false, "BOOLEAN"); testTypeName(true, "BOOLEAN"); testTypeName(null, "NULL"); }