BoneCP implements Serializable, Closeable { protected void watchConnection(ConnectionHandle connectionHandle) { String message = captureStackTrace(UNCLOSED_EXCEPTION_MESSAGE); this.closeConnectionExecutor.submit(new CloseThreadMonitor(Thread.currentThread(), connectionHandle, message, this.closeConnectionWatchTimeoutInMs)); } BoneCP(BoneCPConfig config); synchronized void shutdown(); void close(); Connection getConnection(); ListenableFuture<Connection> getAsyncConnection(); boolean isConnectionHandleAlive(ConnectionHandle connection); int getTotalLeased(); int getTotalFree(); int getTotalCreatedConnections(); BoneCPConfig getConfig(); Statistics getStatistics(); AtomicBoolean getDbIsDown(); static final String MBEAN_CONFIG; static final String MBEAN_BONECP; }
@Test public void testWatchConnection() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchFieldException{ Field field = testClass.getClass().getDeclaredField("closeConnectionExecutor"); field.setAccessible(true); ExecutorService mockExecutor = EasyMock.createNiceMock(ExecutorService.class); field.set(testClass, mockExecutor); Method method = testClass.getClass().getDeclaredMethod("watchConnection", ConnectionHandle.class); method.setAccessible(true); expect(mockExecutor.submit((CloseThreadMonitor) anyObject())).andReturn(null).once(); replay(mockExecutor); method.invoke(testClass, mockConnection); verify(mockExecutor); method.invoke(testClass, new Object[]{null}); }