diff --git a/src/main/java/ru/yandex/qatools/embed/postgresql/EmbeddedPostgres.java b/src/main/java/ru/yandex/qatools/embed/postgresql/EmbeddedPostgres.java index 6c36efa..2136559 100644 --- a/src/main/java/ru/yandex/qatools/embed/postgresql/EmbeddedPostgres.java +++ b/src/main/java/ru/yandex/qatools/embed/postgresql/EmbeddedPostgres.java @@ -36,6 +36,7 @@ public class EmbeddedPostgres implements AutoCloseable { "--locale=C", "--lc-collate=C", "--lc-ctype=C"); + private static final List DEFAULT_POSTGRES_PARAMS = asList(); private final String dataDir; private final IVersion version; private PostgresProcess process; @@ -161,6 +162,25 @@ public String start(IRuntimeConfig runtimeConfig) throws IOException { */ public String start(IRuntimeConfig runtimeConfig, String host, int port, String dbName, String user, String password, List additionalParams) throws IOException { + return start(runtimeConfig, host, port, dbName, user, password, additionalParams, DEFAULT_POSTGRES_PARAMS); + } + + /** + * Starts up the embedded postgres + * + * @param runtimeConfig required runtime configuration + * @param host host to bind to + * @param port port to bind to + * @param dbName name of the database to initialize + * @param user username to connect + * @param password password for the provided username + * @param additionalInitDbParams additional database init params (if required) + * @param additionalPostgresParams additional postgresql params (if required) + * @return connection url for the initialized postgres instance + * @throws IOException if an I/O error occurs during the process startup + */ + public String start(IRuntimeConfig runtimeConfig, String host, int port, String dbName, String user, String password, + List additionalInitDbParams, List additionalPostgresParams) throws IOException { final PostgresStarter runtime = PostgresStarter.getInstance(runtimeConfig); config = new PostgresConfig(version, new AbstractPostgresConfig.Net(host, port), @@ -168,7 +188,8 @@ public String start(IRuntimeConfig runtimeConfig, String host, int port, String new AbstractPostgresConfig.Timeout(), new AbstractPostgresConfig.Credentials(user, password) ); - config.getAdditionalInitDbParams().addAll(additionalParams); + config.getAdditionalInitDbParams().addAll(additionalInitDbParams); + config.getAdditionalPostgresParams().addAll(additionalPostgresParams); PostgresExecutable exec = runtime.prepare(config); this.process = exec.start(); return formatConnUrl(config); diff --git a/src/main/java/ru/yandex/qatools/embed/postgresql/PostgresProcess.java b/src/main/java/ru/yandex/qatools/embed/postgresql/PostgresProcess.java index ad837d5..f8f2a7d 100644 --- a/src/main/java/ru/yandex/qatools/embed/postgresql/PostgresProcess.java +++ b/src/main/java/ru/yandex/qatools/embed/postgresql/PostgresProcess.java @@ -207,6 +207,7 @@ protected List getCommandLine(Distribution distribution, PostgresConfig "-h", config.net().host(), "-D", config.storage().dbDir().getAbsolutePath() )); + ret.addAll(config.getAdditionalPostgresParams()); break; case "pg_ctl": //NOSONAR ret.addAll(asList(exe.executable().getAbsolutePath(), diff --git a/src/main/java/ru/yandex/qatools/embed/postgresql/config/AbstractPostgresConfig.java b/src/main/java/ru/yandex/qatools/embed/postgresql/config/AbstractPostgresConfig.java index b15da48..55a76dc 100644 --- a/src/main/java/ru/yandex/qatools/embed/postgresql/config/AbstractPostgresConfig.java +++ b/src/main/java/ru/yandex/qatools/embed/postgresql/config/AbstractPostgresConfig.java @@ -27,6 +27,7 @@ public abstract class AbstractPostgresConfig e protected final Credentials credentials; protected List args = new ArrayList<>(); protected List additionalInitDbParams = new ArrayList<>(); + protected List additionalPostgresParams = new ArrayList<>(); protected AbstractPostgresConfig(AbstractPostgresConfig config, Command postgres) { this(config.version, config.net(), config.storage, config.timeout(), config.credentials, new SupportConfig(postgres)); @@ -78,7 +79,6 @@ public C withAdditionalInitDbParams(List additionalInitDbParams) { return (C) this; } - /** * You may add here additional arguments for the {@code initdb} executable.
*

@@ -100,6 +100,25 @@ public List getAdditionalInitDbParams() { return additionalInitDbParams; } + /** + * You may add here additional arguments for the {@code postgres} executable.
+ *

+ * Example.
+ * to use custom number of maximum connection.
+ *

+     * getAdditionalPostgresParams().addAll(
+     *      java.util.Arrays.asList(
+     *          "-c", "max_connections=11"
+     * )
+     * 
+ * @return The list of additional parameters for the {@code postgres} executable.
+ * Not {@code null}.
+ * @see Parameter Interaction via the Shell + */ + public List getAdditionalPostgresParams() { + return additionalPostgresParams; + } + public static class Storage { private final File dbDir; private final String dbName;