// Path: src/main/java/com/pgasync/Connectible.java
// public interface Connectible extends QueryExecutor {
// 
//     CompletableFuture<Connection> getConnection();
// 
//     CompletableFuture<Void> close();
// }
// 
// Path: src/main/java/com/pgasync/Connection.java
// public interface Connection extends QueryExecutor {
// 
//     CompletableFuture<PreparedStatement> prepareStatement(String sql, Oid... parametersTypes);
// 
//     /**
//      * The typical scenario of using notifications is as follows:
//      * - {@link #subscribe(String, Consumer)}
//      * - Some calls of @onNotification callback
//      * - {@link Listening#unlisten()}
//      *
//      * @param channel Channel name to listen to.
//      * @param onNotification Callback, thar is cinvoked every time notification arrives.
//      * @return CompletableFuture instance, completed when subscription will be registered at the backend.
//      */
//     CompletableFuture<Listening> subscribe(String channel, Consumer<String> onNotification);
// 
//     CompletableFuture<Void> close();
// }
// 
// Path: src/main/java/com/pgasync/Listening.java
// @FunctionalInterface
// public interface Listening {
// 
//     CompletableFuture<Void> unlisten();
// }


import com.pgasync.Connectible;
import com.pgasync.Connection;
import com.pgasync.Listening;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;
package com.github.pgasync;




/**
 * @author Antti Laisi
 */
public class ListenNotifyTest {

    @ClassRule
    public static DatabaseRule dbr = new DatabaseRule(DatabaseRule.createPoolBuilder(5));

    private Connectible pool;

    @Before
    public void setup() {
        pool = dbr.pool();
    }

    @After
    public void shutdown() {
        pool.close().join();
    }

    @Test
    public void shouldReceiveNotificationsOnListenedChannel() throws InterruptedException {
        BlockingQueue<String> result = new LinkedBlockingQueue<>(5);

// Path: src/main/java/com/pgasync/Connectible.java
// public interface Connectible extends QueryExecutor {
// 
//     CompletableFuture<Connection> getConnection();
// 
//     CompletableFuture<Void> close();
// }
// 
// Path: src/main/java/com/pgasync/Connection.java
// public interface Connection extends QueryExecutor {
// 
//     CompletableFuture<PreparedStatement> prepareStatement(String sql, Oid... parametersTypes);
// 
//     /**
//      * The typical scenario of using notifications is as follows:
//      * - {@link #subscribe(String, Consumer)}
//      * - Some calls of @onNotification callback
//      * - {@link Listening#unlisten()}
//      *
//      * @param channel Channel name to listen to.
//      * @param onNotification Callback, thar is cinvoked every time notification arrives.
//      * @return CompletableFuture instance, completed when subscription will be registered at the backend.
//      */
//     CompletableFuture<Listening> subscribe(String channel, Consumer<String> onNotification);
// 
//     CompletableFuture<Void> close();
// }
// 
// Path: src/main/java/com/pgasync/Listening.java
// @FunctionalInterface
// public interface Listening {
// 
//     CompletableFuture<Void> unlisten();
// }


// Path: src/test/java/com/github/pgasync/ListenNotifyTest.java
import com.pgasync.Connectible;
import com.pgasync.Connection;
import com.pgasync.Listening;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.*;

package com.github.pgasync;




/**
 * @author Antti Laisi
 */
public class ListenNotifyTest {

    @ClassRule
    public static DatabaseRule dbr = new DatabaseRule(DatabaseRule.createPoolBuilder(5));

    private Connectible pool;

    @Before
    public void setup() {
        pool = dbr.pool();
    }

    @After
    public void shutdown() {
        pool.close().join();
    }

    @Test
    public void shouldReceiveNotificationsOnListenedChannel() throws InterruptedException {
        BlockingQueue<String> result = new LinkedBlockingQueue<>(5);

        Connection conn = pool.getConnection().join();