// Path: src/main/java/com/github/gquintana/metrics/proxy/ReflectProxyFactory.java
// public class ReflectProxyFactory implements ProxyFactory {
// 	/**
// 	 * {@inheritDoc}
// 	 */
//         @Override
// 	public <T> T newProxy(ProxyHandler<T> proxyHandler, ProxyClass proxyClass) {
// 		return (T) Proxy.newProxyInstance(proxyClass.getClassLoader(), proxyClass.getInterfaces(), proxyHandler);
// 	}
// }


import javax.sql.DataSource;
import java.sql.*;
import java.util.Random;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Slf4jReporter;
import com.codahale.metrics.Snapshot;
import com.codahale.metrics.Timer;
import com.github.gquintana.metrics.proxy.ReflectProxyFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package com.github.gquintana.metrics.sql;

/*
 * #%L
 * Metrics SQL
 * %%
 * Copyright (C) 2014 Open-Source
 * %%
 * 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.
 * #L%
 */




/**
 * Metering test
 */
public class MeteringTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(MeteringTest.class);
    private MetricRegistry metricRegistry;
    private JdbcProxyFactory proxyFactory;
    private DataSource rawDataSource;
    private DataSource dataSource;
    private Slf4jReporter metricsReporter;

    @Before
    public void setUp() throws SQLException {
        metricRegistry = new MetricRegistry();
        metricsReporter = Slf4jReporter.forRegistry(metricRegistry)
                .outputTo(LOGGER)
                .withLoggingLevel(Slf4jReporter.LoggingLevel.INFO)
                .build();
        rawDataSource = H2DbUtil.createDataSource();
        try (Connection connection = rawDataSource.getConnection()) {
            H2DbUtil.initTable(connection);
        }
        proxyFactory = MetricsSql.forRegistry(metricRegistry)
// Path: src/main/java/com/github/gquintana/metrics/proxy/ReflectProxyFactory.java
// public class ReflectProxyFactory implements ProxyFactory {
// 	/**
// 	 * {@inheritDoc}
// 	 */
//         @Override
// 	public <T> T newProxy(ProxyHandler<T> proxyHandler, ProxyClass proxyClass) {
// 		return (T) Proxy.newProxyInstance(proxyClass.getClassLoader(), proxyClass.getInterfaces(), proxyHandler);
// 	}
// }


// Path: src/test/java/com/github/gquintana/metrics/sql/MeteringTest.java
import javax.sql.DataSource;
import java.sql.*;
import java.util.Random;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Slf4jReporter;
import com.codahale.metrics.Snapshot;
import com.codahale.metrics.Timer;
import com.github.gquintana.metrics.proxy.ReflectProxyFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package com.github.gquintana.metrics.sql;

/*
 * #%L
 * Metrics SQL
 * %%
 * Copyright (C) 2014 Open-Source
 * %%
 * 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.
 * #L%
 */




/**
 * Metering test
 */
public class MeteringTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(MeteringTest.class);
    private MetricRegistry metricRegistry;
    private JdbcProxyFactory proxyFactory;
    private DataSource rawDataSource;
    private DataSource dataSource;
    private Slf4jReporter metricsReporter;

    @Before
    public void setUp() throws SQLException {
        metricRegistry = new MetricRegistry();
        metricsReporter = Slf4jReporter.forRegistry(metricRegistry)
                .outputTo(LOGGER)
                .withLoggingLevel(Slf4jReporter.LoggingLevel.INFO)
                .build();
        rawDataSource = H2DbUtil.createDataSource();
        try (Connection connection = rawDataSource.getConnection()) {
            H2DbUtil.initTable(connection);
        }
        proxyFactory = MetricsSql.forRegistry(metricRegistry)
                .withProxyFactory(new ReflectProxyFactory()).build();