From b958a6c2b8e58fe20bc88aeed3ba306eff26c583 Mon Sep 17 00:00:00 2001 From: Pontus Melke Date: Mon, 20 Nov 2017 13:53:43 +0100 Subject: [PATCH] More tests --- .../kernel/api/TransactionStateTestBase.java | 52 ++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/TransactionStateTestBase.java b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/TransactionStateTestBase.java index 1050cba4c4616..e084318bec1ae 100644 --- a/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/TransactionStateTestBase.java +++ b/community/kernel-api/src/test/java/org/neo4j/internal/kernel/api/TransactionStateTestBase.java @@ -52,7 +52,7 @@ public void shouldSeeNodeInTransaction() throws Exception tx.success(); } - try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) + try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertEquals( nodeId, graphDb.getNodeById( nodeId ).getId() ); } @@ -84,7 +84,7 @@ public void shouldSeeNewLabeledNodeInTransaction() throws Exception tx.success(); } - try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) + try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertThat( graphDb.getNodeById( nodeId ).getLabels(), @@ -111,11 +111,11 @@ public void shouldSeeLabelChangesInTransaction() throws Exception tx.success(); } - try ( org.neo4j.graphdb.Transaction ctx = graphDb.beginTx() ) + try ( org.neo4j.graphdb.Transaction ignore = graphDb.beginTx() ) { assertThat( graphDb.getNodeById( nodeId ).getLabels(), - containsInAnyOrder( label( toRetainName ), label( toDeleteName ) ) ); + containsInAnyOrder( label( toRetainName ), label( toDeleteName ) ) ); } try ( Transaction tx = session.beginTransaction() ) @@ -139,14 +139,54 @@ public void shouldSeeLabelChangesInTransaction() throws Exception { assertThat( graphDb.getNodeById( nodeId ).getLabels(), - containsInAnyOrder( label( toRetainName ), label( toAddName ) )); + containsInAnyOrder( label( toRetainName ), label( toAddName ) ) ); + } + } + + @Test + public void shouldDiscoverDeletedNodeInTransaction() throws Exception + { + long nodeId; + try ( Transaction tx = session.beginTransaction() ) + { + nodeId = tx.dataWrite().nodeCreate(); + tx.success(); + } + + try ( Transaction tx = session.beginTransaction() ) + { + assertTrue( tx.dataWrite().nodeDelete( nodeId ) ); + try ( NodeCursor node = cursors.allocateNodeCursor() ) + { + tx.dataRead().singleNode( nodeId, node ); + assertFalse( node.next() ); + } + tx.success(); + } + } + + @Test + public void shouldHandleMultipleNodeDeletions() throws Exception + { + long nodeId; + try ( Transaction tx = session.beginTransaction() ) + { + nodeId = tx.dataWrite().nodeCreate(); + tx.success(); + } + + try ( Transaction tx = session.beginTransaction() ) + { + assertTrue( tx.dataWrite().nodeDelete( nodeId ) ); + assertFalse( tx.dataWrite().nodeDelete( nodeId ) ); + tx.success(); } } private void assertLabels( LabelSet labels, int... expected ) { assertEquals( expected.length, labels.numberOfLabels() ); - Arrays.sort(expected); + Arrays.sort( expected ); int[] labelArray = new int[labels.numberOfLabels()]; for ( int i = 0; i < labels.numberOfLabels(); i++ ) {