// 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/SqlException.java
// public class SqlException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
//     private static final int MAX_CAUSE_DEPTH = 100;
// 
//     final String code;
// 
//     public SqlException(String level, String code, String message) {
//         super(level + ": SQLSTATE=" + code + ", MESSAGE=" + message);
//         this.code = code;
//     }
// 
//     public SqlException(String message) {
//         super(message);
//         this.code = null;
//     }
// 
//     public SqlException(Throwable cause) {
//         super(cause);
//         this.code = null;
//     }
// 
//     public String getCode() {
//         return code;
//     }
// 
//     @FunctionalInterface
//     public interface CheckedRunnable {
// 
//         void run() throws Exception;
//     }
// 
//     public static boolean ifCause(Throwable th, Consumer<SqlException> action, CheckedRunnable others) throws Exception {
//         int depth = 1;
//         while (depth++ < MAX_CAUSE_DEPTH && th != null && !(th instanceof SqlException)) {
//             th = th.getCause();
//         }
//         if (th instanceof SqlException) {
//             action.accept((SqlException) th);
//             return true;
//         } else {
//             others.run();
//             return false;
//         }
//     }
// }


import com.pgasync.Connectible;
import com.pgasync.Connection;
import com.pgasync.SqlException;
import org.junit.Rule;
import org.junit.Test;
import java.util.function.Consumer;
                        .validationQuery(clause)
                        .plain(),
                action
        );
    }

    private void withPool(String clause, Consumer<Connectible> action) throws Exception {
        withSource(dbr.builder
                        .validationQuery(clause)
                        .pool(),
                action
        );
    }

    @Test
    public void shouldReturnValidPlainConnection() throws Exception {
        withPlain("Select 89", plain -> {
            Connection conn = plain.getConnection().join();
            conn.close().join();
        });
    }

    @Test(expected = SqlException.class)
    public void shouldNotReturnInvalidPlainConnection() throws Exception {
        withPlain("Selec t 89", plain -> plain.getConnection().join());
    }

    @Test
    public void shouldReturnValidPooledConnection() throws Exception {
        withPool("Select 89", source -> {
// 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/SqlException.java
// public class SqlException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
//     private static final int MAX_CAUSE_DEPTH = 100;
// 
//     final String code;
// 
//     public SqlException(String level, String code, String message) {
//         super(level + ": SQLSTATE=" + code + ", MESSAGE=" + message);
//         this.code = code;
//     }
// 
//     public SqlException(String message) {
//         super(message);
//         this.code = null;
//     }
// 
//     public SqlException(Throwable cause) {
//         super(cause);
//         this.code = null;
//     }
// 
//     public String getCode() {
//         return code;
//     }
// 
//     @FunctionalInterface
//     public interface CheckedRunnable {
// 
//         void run() throws Exception;
//     }
// 
//     public static boolean ifCause(Throwable th, Consumer<SqlException> action, CheckedRunnable others) throws Exception {
//         int depth = 1;
//         while (depth++ < MAX_CAUSE_DEPTH && th != null && !(th instanceof SqlException)) {
//             th = th.getCause();
//         }
//         if (th instanceof SqlException) {
//             action.accept((SqlException) th);
//             return true;
//         } else {
//             others.run();
//             return false;
//         }
//     }
// }


// Path: src/test/java/com/github/pgasync/ValidatedConnectionTest.java
import com.pgasync.Connectible;
import com.pgasync.Connection;
import com.pgasync.SqlException;
import org.junit.Rule;
import org.junit.Test;
import java.util.function.Consumer;

                        .validationQuery(clause)
                        .plain(),
                action
        );
    }

    private void withPool(String clause, Consumer<Connectible> action) throws Exception {
        withSource(dbr.builder
                        .validationQuery(clause)
                        .pool(),
                action
        );
    }

    @Test
    public void shouldReturnValidPlainConnection() throws Exception {
        withPlain("Select 89", plain -> {
            Connection conn = plain.getConnection().join();
            conn.close().join();
        });
    }

    @Test(expected = SqlException.class)
    public void shouldNotReturnInvalidPlainConnection() throws Exception {
        withPlain("Selec t 89", plain -> plain.getConnection().join());
    }

    @Test
    public void shouldReturnValidPooledConnection() throws Exception {
        withPool("Select 89", source -> {
            Connection conn = source.getConnection().join();