|
22 | 22 | import org.junit.Test;
|
23 | 23 | import org.junit.rules.ExpectedException;
|
24 | 24 |
|
25 |
| -import java.util.Map; |
26 |
| -import java.util.concurrent.atomic.AtomicBoolean; |
27 |
| - |
28 | 25 | import org.neo4j.driver.internal.logging.DevNullLogger;
|
29 | 26 | import org.neo4j.driver.internal.spi.Connection;
|
30 |
| -import org.neo4j.driver.internal.spi.Logger; |
31 |
| -import org.neo4j.driver.internal.spi.StreamCollector; |
32 | 27 | import org.neo4j.driver.v1.Transaction;
|
33 |
| -import org.neo4j.driver.v1.Value; |
34 | 28 | import org.neo4j.driver.v1.exceptions.ClientException;
|
35 | 29 |
|
36 | 30 | import static junit.framework.TestCase.assertNotNull;
|
37 |
| -import static org.jsoup.helper.Validate.fail; |
38 | 31 | import static org.mockito.Mockito.mock;
|
39 |
| -import static org.mockito.Mockito.spy; |
40 | 32 | import static org.mockito.Mockito.verify;
|
41 | 33 | import static org.mockito.Mockito.when;
|
42 | 34 |
|
@@ -143,81 +135,4 @@ public void shouldNotAllowMoreTransactionsInSessionWhileConnectionClosed() throw
|
143 | 135 | // When
|
144 | 136 | sess.beginTransaction();
|
145 | 137 | }
|
146 |
| - |
147 |
| - @Test |
148 |
| - public void shouldWarnAndCloseOnLeak() throws Throwable |
149 |
| - { |
150 |
| - // Given |
151 |
| - CloseTrackingConnection connection = new CloseTrackingConnection(); |
152 |
| - Logger logger = spy( Logger.class ); |
153 |
| - |
154 |
| - // When |
155 |
| - new InternalSession( connection, logger ); |
156 |
| - |
157 |
| - // Then |
158 |
| - long deadline = System.currentTimeMillis() + 1000 * 30; |
159 |
| - while ( !connection.closeCalled.get() ) |
160 |
| - { |
161 |
| - System.gc(); |
162 |
| - if ( System.currentTimeMillis() > deadline ) |
163 |
| - { |
164 |
| - fail( "Expected unclosed session object to close its inner connection on finalize." ); |
165 |
| - } |
166 |
| - } |
167 |
| - |
168 |
| - verify( logger ).error( "Neo4j Session object leaked, please ensure that your application calls the `close` method on Sessions before disposing of the objects.", null ); |
169 |
| - } |
170 |
| - |
171 |
| - private static class CloseTrackingConnection implements Connection |
172 |
| - { |
173 |
| - AtomicBoolean closeCalled = new AtomicBoolean(); |
174 |
| - |
175 |
| - @Override |
176 |
| - public void init( String clientName ) |
177 |
| - { |
178 |
| - |
179 |
| - } |
180 |
| - |
181 |
| - @Override |
182 |
| - public void run( String statement, Map<String,Value> parameters, StreamCollector collector ) |
183 |
| - { |
184 |
| - |
185 |
| - } |
186 |
| - |
187 |
| - @Override |
188 |
| - public void discardAll() |
189 |
| - { |
190 |
| - |
191 |
| - } |
192 |
| - |
193 |
| - @Override |
194 |
| - public void pullAll( StreamCollector collector ) |
195 |
| - { |
196 |
| - |
197 |
| - } |
198 |
| - |
199 |
| - @Override |
200 |
| - public void reset( StreamCollector collector ) |
201 |
| - { |
202 |
| - |
203 |
| - } |
204 |
| - |
205 |
| - @Override |
206 |
| - public void sync() |
207 |
| - { |
208 |
| - |
209 |
| - } |
210 |
| - |
211 |
| - @Override |
212 |
| - public void close() |
213 |
| - { |
214 |
| - closeCalled.set( true ); |
215 |
| - } |
216 |
| - |
217 |
| - @Override |
218 |
| - public boolean isOpen() |
219 |
| - { |
220 |
| - return true; |
221 |
| - } |
222 |
| - } |
223 | 138 | }
|
0 commit comments