1
+ /**
2
+ * Copyright (c) 2002-2016 "Neo Technology,"
3
+ * Network Engine for Objects in Lund AB [http://neotechnology.com]
4
+ *
5
+ * This file is part of Neo4j.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ package org .neo4j .driver .internal .pool ;
20
+
21
+ import org .junit .Test ;
22
+
23
+ import java .util .LinkedList ;
24
+
25
+ import org .neo4j .driver .internal .spi .Connection ;
26
+ import org .neo4j .driver .internal .spi .StreamCollector ;
27
+ import org .neo4j .driver .internal .util .Consumer ;
28
+ import org .neo4j .driver .v1 .exceptions .DatabaseException ;
29
+
30
+ import static org .hamcrest .CoreMatchers .equalTo ;
31
+ import static org .hamcrest .CoreMatchers .hasItem ;
32
+ import static org .hamcrest .MatcherAssert .assertThat ;
33
+ import static org .mockito .Matchers .any ;
34
+ import static org .mockito .Mockito .doThrow ;
35
+ import static org .mockito .Mockito .mock ;
36
+
37
+ public class PooledConnectionTest
38
+ {
39
+ @ Test
40
+ public void shouldReturnToPoolIfExceptionDuringReset () throws Throwable
41
+ {
42
+ // Given
43
+ final LinkedList <PooledConnection > returnedToPool = new LinkedList <>();
44
+ Connection conn = mock ( Connection .class );
45
+
46
+ doThrow ( new DatabaseException ( "asd" , "asd" ) ).when (conn ).reset ( any ( StreamCollector .class ) );
47
+
48
+ PooledConnection pooledConnection = new PooledConnection ( conn , new Consumer <PooledConnection >()
49
+ {
50
+ @ Override
51
+ public void accept ( PooledConnection pooledConnection )
52
+ {
53
+ returnedToPool .add ( pooledConnection );
54
+ }
55
+ } );
56
+
57
+ // When
58
+ pooledConnection .close ();
59
+
60
+ // Then
61
+ assertThat ( returnedToPool , hasItem (pooledConnection ) );
62
+ assertThat ( returnedToPool .size (), equalTo ( 1 ));
63
+ }
64
+ }
0 commit comments