// Path: src/main/java/com/pgasync/ResultSet.java
// public interface ResultSet extends Iterable<Row> {
// 
//     Map<String, PgColumn> getColumnsByName();
// 
//     List<PgColumn> getOrderedColumns();
// 
//     /**
//      * @param index Row index starting from 0
//      * @return Row, never null
//      */
//     Row at(int index);
// 
//     /**
//      * @return Amount of result rows.
//      */
//     int size();
// 
//     /**
//      * @return Amount of modified rows.
//      */
//     int affectedRows();
// 
// }


import static org.junit.Assert.assertEquals;
import com.pgasync.ResultSet;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.function.IntFunction;
import java.util.stream.IntStream;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
/*
 * 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.
 */

package com.github.pgasync;




/**
 * Tests for connection pool concurrency.
 *
 * @author Antti Laisi
 */
public class ConnectionPoolingTest {

    @Rule
    public final DatabaseRule dbr = new DatabaseRule();

    @Before
    public void create() {
        dbr.script(
                "DROP TABLE IF EXISTS CP_TEST;" +
                        "CREATE TABLE CP_TEST (ID VARCHAR(255) PRIMARY KEY)"
        );
    }

    @After
    public void drop() {
        dbr.query("DROP TABLE CP_TEST");
    }

    @Test
    public void shouldRunAllQueuedCallbacks() throws Exception {
        final int count = 1000;
// Path: src/main/java/com/pgasync/ResultSet.java
// public interface ResultSet extends Iterable<Row> {
// 
//     Map<String, PgColumn> getColumnsByName();
// 
//     List<PgColumn> getOrderedColumns();
// 
//     /**
//      * @param index Row index starting from 0
//      * @return Row, never null
//      */
//     Row at(int index);
// 
//     /**
//      * @return Amount of result rows.
//      */
//     int size();
// 
//     /**
//      * @return Amount of modified rows.
//      */
//     int affectedRows();
// 
// }


// Path: src/test/java/com/github/pgasync/ConnectionPoolingTest.java
import static org.junit.Assert.assertEquals;
import com.pgasync.ResultSet;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.function.IntFunction;
import java.util.stream.IntStream;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;

/*
 * 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.
 */

package com.github.pgasync;




/**
 * Tests for connection pool concurrency.
 *
 * @author Antti Laisi
 */
public class ConnectionPoolingTest {

    @Rule
    public final DatabaseRule dbr = new DatabaseRule();

    @Before
    public void create() {
        dbr.script(
                "DROP TABLE IF EXISTS CP_TEST;" +
                        "CREATE TABLE CP_TEST (ID VARCHAR(255) PRIMARY KEY)"
        );
    }

    @After
    public void drop() {
        dbr.query("DROP TABLE CP_TEST");
    }

    @Test
    public void shouldRunAllQueuedCallbacks() throws Exception {
        final int count = 1000;
        IntFunction<Callable<ResultSet>> insert = value -> () -> dbr.query("INSERT INTO CP_TEST VALUES($1)", singletonList(value));