[#3234] Added new lifecycle listener to check ConnectionProvider
This commit is contained in:
parent
0319a1dbb8
commit
769f24c378
@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This work is dual-licensed
|
||||
* - under the Apache Software License 2.0 (the "ASL")
|
||||
* - under the jOOQ License and Maintenance Agreement (the "jOOQ License")
|
||||
* =============================================================================
|
||||
* You may choose which license applies to you:
|
||||
*
|
||||
* - If you're using this work with Open Source databases, you may choose
|
||||
* either ASL or jOOQ License.
|
||||
* - If you're using this work with at least one commercial database, you must
|
||||
* choose jOOQ License
|
||||
*
|
||||
* For more information, please visit http://www.jooq.org/licenses
|
||||
*
|
||||
* Apache Software License 2.0:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* jOOQ License and Maintenance Agreement:
|
||||
* -----------------------------------------------------------------------------
|
||||
* Data Geekery grants the Customer the non-exclusive, timely limited and
|
||||
* non-transferable license to install and use the Software under the terms of
|
||||
* the jOOQ License and Maintenance Agreement.
|
||||
*
|
||||
* This library is distributed with a LIMITED WARRANTY. See the jOOQ License
|
||||
* and Maintenance Agreement for more details: http://www.jooq.org/licensing
|
||||
*/
|
||||
package org.jooq.test._.listeners;
|
||||
|
||||
import static org.jooq.test._.listeners.Lifecycle.METHOD_COMPARATOR;
|
||||
import static org.jooq.test._.listeners.Lifecycle.increment;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.jooq.ConnectionProvider;
|
||||
|
||||
/**
|
||||
* A lifecycle listener to check {@link ConnectionProvider} lifecycles in integration tests
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class ConnectionProviderLifecycleListener implements ConnectionProvider {
|
||||
|
||||
public static final Map<Method, Integer> ACQUIRE_COUNT = new TreeMap<Method, Integer>(METHOD_COMPARATOR);
|
||||
public static final Map<Method, Integer> RELEASE_COUNT = new TreeMap<Method, Integer>(METHOD_COMPARATOR);
|
||||
|
||||
private final ConnectionProvider delegate;
|
||||
|
||||
public ConnectionProviderLifecycleListener(ConnectionProvider delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection acquire() {
|
||||
increment(ACQUIRE_COUNT);
|
||||
return delegate.acquire();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(Connection connection) {
|
||||
increment(RELEASE_COUNT);
|
||||
delegate.release(connection);
|
||||
}
|
||||
}
|
||||
@ -40,6 +40,9 @@
|
||||
*/
|
||||
package org.jooq.test._.listeners;
|
||||
|
||||
import static org.jooq.test._.listeners.Lifecycle.METHOD_COMPARATOR;
|
||||
import static org.jooq.test._.listeners.Lifecycle.increment;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.SQLException;
|
||||
@ -47,6 +50,7 @@ import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.jooq.ExecuteContext;
|
||||
import org.jooq.impl.DefaultExecuteListener;
|
||||
import org.jooq.tools.jdbc.DefaultCallableStatement;
|
||||
import org.jooq.tools.jdbc.DefaultPreparedStatement;
|
||||
import org.jooq.tools.jdbc.DefaultResultSet;
|
||||
@ -57,7 +61,7 @@ import org.jooq.tools.jdbc.DefaultResultSet;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class JDBCLifecycleListener extends AbstractLifecycleListener {
|
||||
public class JDBCLifecycleListener extends DefaultExecuteListener {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
|
||||
@ -44,8 +44,6 @@ import java.lang.reflect.Method;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jooq.impl.DefaultExecuteListener;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@ -54,12 +52,7 @@ import org.junit.Test;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public abstract class AbstractLifecycleListener extends DefaultExecuteListener {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
*/
|
||||
private static final long serialVersionUID = -2283264126211556442L;
|
||||
public class Lifecycle {
|
||||
|
||||
protected static Comparator<Method> METHOD_COMPARATOR = new Comparator<Method>() {
|
||||
|
||||
@ -71,7 +64,7 @@ public abstract class AbstractLifecycleListener extends DefaultExecuteListener {
|
||||
|
||||
private static final Object INCREMENT_MONITOR = new Object();
|
||||
|
||||
protected final void increment(Map<Method, Integer> map) {
|
||||
protected static final void increment(Map<Method, Integer> map) {
|
||||
synchronized (INCREMENT_MONITOR) {
|
||||
Method m = testMethod();
|
||||
|
||||
@ -40,11 +40,15 @@
|
||||
*/
|
||||
package org.jooq.test._.listeners;
|
||||
|
||||
import static org.jooq.test._.listeners.Lifecycle.METHOD_COMPARATOR;
|
||||
import static org.jooq.test._.listeners.Lifecycle.increment;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.jooq.ExecuteContext;
|
||||
import org.jooq.impl.DefaultExecuteListener;
|
||||
|
||||
/**
|
||||
* An <code>ExecuteListener</code> that collects data about the lifecycle of
|
||||
@ -52,7 +56,7 @@ import org.jooq.ExecuteContext;
|
||||
*
|
||||
* @author Lukas Eder
|
||||
*/
|
||||
public class LifecycleWatcherListener extends AbstractLifecycleListener {
|
||||
public class LifecycleWatcherListener extends DefaultExecuteListener {
|
||||
|
||||
/**
|
||||
* Generated UID
|
||||
|
||||
@ -43,6 +43,8 @@ package org.jooq.test;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.jooq.SQLDialect.CUBRID;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
import static org.jooq.test._.listeners.ConnectionProviderLifecycleListener.ACQUIRE_COUNT;
|
||||
import static org.jooq.test._.listeners.ConnectionProviderLifecycleListener.RELEASE_COUNT;
|
||||
import static org.jooq.test._.listeners.JDBCLifecycleListener.RS_CLOSE_COUNT;
|
||||
import static org.jooq.test._.listeners.JDBCLifecycleListener.RS_START_COUNT;
|
||||
import static org.jooq.test._.listeners.JDBCLifecycleListener.STMT_CLOSE_COUNT;
|
||||
@ -107,7 +109,9 @@ import org.jooq.test._.converters.Boolean_YES_NO_LC;
|
||||
import org.jooq.test._.converters.Boolean_YES_NO_UC;
|
||||
import org.jooq.test._.converters.Boolean_YN_LC;
|
||||
import org.jooq.test._.converters.Boolean_YN_UC;
|
||||
import org.jooq.test._.listeners.ConnectionProviderLifecycleListener;
|
||||
import org.jooq.test._.listeners.JDBCLifecycleListener;
|
||||
import org.jooq.test._.listeners.Lifecycle;
|
||||
import org.jooq.test._.listeners.LifecycleWatcherListener;
|
||||
import org.jooq.test._.listeners.PrettyPrinter;
|
||||
import org.jooq.test._.listeners.TestStatisticsListener;
|
||||
@ -499,7 +503,12 @@ public abstract class jOOQAbstractTest<
|
||||
logStat.info("Total", total);
|
||||
|
||||
int unbalanced = 0;
|
||||
JooqLogger logLife = JooqLogger.getLogger(LifecycleWatcherListener.class);
|
||||
JooqLogger logLife = JooqLogger.getLogger(Lifecycle.class);
|
||||
|
||||
logLife.info("");
|
||||
logLife.info("CONNECTION PROVIDER LIFECYCLE STATS");
|
||||
logLife.info("-----------------------------------");
|
||||
unbalanced = extracted(logLife, unbalanced, ACQUIRE_COUNT, RELEASE_COUNT);
|
||||
|
||||
logLife.info("");
|
||||
logLife.info("EXECUTE LISTENER LIFECYCLE STATS");
|
||||
@ -961,14 +970,21 @@ public abstract class jOOQAbstractTest<
|
||||
.withRenderMapping(new RenderMapping()
|
||||
.withDefaultSchema(defaultSchema));
|
||||
|
||||
return DSL.using(create0(settings).configuration().derive(
|
||||
DefaultExecuteListenerProvider.providers(
|
||||
new JDBCLifecycleListener(),
|
||||
new LifecycleWatcherListener(),
|
||||
new TestStatisticsListener(),
|
||||
new PrettyPrinter()
|
||||
org.jooq.Configuration c = create0(settings).configuration();
|
||||
|
||||
return DSL.using(c
|
||||
.derive(
|
||||
new ConnectionProviderLifecycleListener(c.connectionProvider())
|
||||
)
|
||||
));
|
||||
.derive(
|
||||
DefaultExecuteListenerProvider.providers(
|
||||
new JDBCLifecycleListener(),
|
||||
new LifecycleWatcherListener(),
|
||||
new TestStatisticsListener(),
|
||||
new PrettyPrinter()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected final DSLContext create(Settings settings) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user