File tree Expand file tree Collapse file tree 2 files changed +27
-5
lines changed
main/java/org/neo4j/driver/internal
test/java/org/neo4j/driver/v1/integration Expand file tree Collapse file tree 2 files changed +27
-5
lines changed Original file line number Diff line number Diff line change @@ -137,9 +137,13 @@ public Transaction beginTransaction()
137
137
@ Override
138
138
public void run ()
139
139
{
140
- currentTransaction .markAsRolledBack ();
141
- currentTransaction = null ;
142
- connection .onError ( null );
140
+ //must check if transaction has been closed
141
+ if (currentTransaction != null )
142
+ {
143
+ currentTransaction .markAsRolledBack ();
144
+ currentTransaction = null ;
145
+ connection .onError ( null );
146
+ }
143
147
}
144
148
});
145
149
return currentTransaction ;
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ public void shouldRunAndCommit() throws Throwable
54
54
// Then the outcome of both statements should be visible
55
55
StatementResult result = session .run ( "MATCH (n) RETURN count(n)" );
56
56
long nodes = result .single ().get ( "count(n)" ).asLong ();
57
- assertThat ( nodes , equalTo ( 2l ) );
57
+ assertThat ( nodes , equalTo ( 2L ) );
58
58
}
59
59
60
60
@ Test
@@ -70,7 +70,7 @@ public void shouldRunAndRollbackByDefault() throws Throwable
70
70
// Then there should be no visible effect of the transaction
71
71
StatementResult cursor = session .run ( "MATCH (n) RETURN count(n)" );
72
72
long nodes = cursor .single ().get ( "count(n)" ).asLong ();
73
- assertThat ( nodes , equalTo ( 0l ) );
73
+ assertThat ( nodes , equalTo ( 0L ) );
74
74
}
75
75
76
76
@ Test
@@ -146,4 +146,22 @@ public void shouldHandleNullParametersGracefully()
146
146
147
147
}
148
148
149
+ //See GH #146
150
+ @ Test
151
+ public void shouldHandleFailureAfterClosingTransaction ()
152
+ {
153
+ // GIVEN a successful query in a transaction
154
+ Transaction tx = session .beginTransaction ();
155
+ StatementResult result = tx .run ("CREATE (n) RETURN n" );
156
+ result .consume ();
157
+ tx .success ();
158
+ tx .close ();
159
+
160
+ // EXPECT
161
+ exception .expect ( ClientException .class );
162
+
163
+ //WHEN running a malformed query in the original session
164
+ session .run ("CREAT (n) RETURN n" ).consume ();
165
+ }
166
+
149
167
}
You can’t perform that action at this time.
0 commit comments