27
27
import org .neo4j .driver .v1 .util .TestNeo4j ;
28
28
29
29
import static org .hamcrest .CoreMatchers .equalTo ;
30
- import static org .hamcrest .CoreMatchers .startsWith ;
31
30
import static org .hamcrest .Matchers .greaterThan ;
32
31
import static org .junit .Assert .assertFalse ;
33
32
import static org .junit .Assert .assertThat ;
@@ -122,7 +121,6 @@ public void shouldKillLongRunningStatement() throws Throwable
122
121
assertTrue ( startTime > 0 );
123
122
assertTrue ( endTime - startTime > killTimeout * 1000 ); // get reset by session.reset
124
123
assertTrue ( endTime - startTime < executionTimeout * 1000 / 2 ); // finished before execution finished
125
- assertFalse ( session .isOpen () );
126
124
}
127
125
catch ( Exception e )
128
126
{
@@ -199,32 +197,25 @@ public void run()
199
197
}
200
198
201
199
@ Test
202
- public void shouldNotAllowMoreStatementAfterSessionReset ()
200
+ public void shouldAllowMoreStatementAfterSessionReset ()
203
201
{
204
202
// Given
205
203
try ( Driver driver = GraphDatabase .driver ( neo4j .uri () );
206
204
Session session = driver .session () )
207
205
{
208
206
209
- session .run ( "Return 1" );
207
+ session .run ( "Return 1" ).consume ();
208
+
209
+ // When reset the state of this session
210
210
session .reset ();
211
211
212
- // When & Then
213
- try
214
- {
215
- session .run ( "Return 2" );
216
- fail ( "Should disallow more statements" );
217
- }
218
- catch ( Exception e )
219
- {
220
- assertThat ( e .getMessage (), startsWith ("No more interaction with this session is allowed " +
221
- "as the current session is already closed or marked as closed." ) );
222
- }
212
+ // Then can run successfully more statements without any error
213
+ session .run ( "Return 2" ).consume ();
223
214
}
224
215
}
225
216
226
217
@ Test
227
- public void shouldNotAllowMoreTxAfterSessionReset ()
218
+ public void shouldAllowMoreTxAfterSessionReset ()
228
219
{
229
220
// Given
230
221
try ( Driver driver = GraphDatabase .driver ( neo4j .uri () );
@@ -235,18 +226,15 @@ public void shouldNotAllowMoreTxAfterSessionReset()
235
226
tx .run ("Return 1" );
236
227
tx .success ();
237
228
}
229
+
230
+ // When reset the state of this session
238
231
session .reset ();
239
232
240
- // When & Then
241
- try
242
- {
243
- session .beginTransaction ();
244
- fail ( "Should disallow more statements" );
245
- }
246
- catch ( Exception e )
233
+ // Then can run more Tx
234
+ try ( Transaction tx = session .beginTransaction () )
247
235
{
248
- assertThat ( e . getMessage (), startsWith ( "No more interaction with this session is allowed " +
249
- "as the current session is already closed or marked as closed." ) );
236
+ tx . run ( "Return 2" );
237
+ tx . success ( );
250
238
}
251
239
}
252
240
}
0 commit comments