diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/UnixDomainSocketTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/UnixDomainSocketTest.java index 7ee23ab3c..67f455395 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/UnixDomainSocketTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/UnixDomainSocketTest.java @@ -23,10 +23,13 @@ import io.vertx.ext.unit.TestContext; import io.vertx.ext.unit.junit.VertxUnitRunner; import io.vertx.sqlclient.PoolOptions; +import io.vertx.sqlclient.impl.ConnectionFactoryBase; import org.junit.*; import org.junit.runner.RunWith; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; @RunWith(VertxUnitRunner.class) @@ -106,4 +109,18 @@ public void testIgnoreSslMode(TestContext context) { pgConnection.close(); })); } + + @Test + public void testNativeTransportMustBeEnabled() { + Vertx vertx = Vertx.vertx(); + try { + PgPool.pool(vertx, PgConnectOptions.fromUri("postgresql:///dbname?host=/var/lib/postgresql"), new PoolOptions()); + fail(); + } catch (IllegalArgumentException expected) { + // Expected + assertEquals(ConnectionFactoryBase.NATIVE_TRANSPORT_REQUIRED, expected.getMessage()); + } finally { + vertx.close(); + } + } } diff --git a/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/ConnectionFactoryBase.java b/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/ConnectionFactoryBase.java index c811f3eee..8d589b7b8 100644 --- a/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/ConnectionFactoryBase.java +++ b/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/ConnectionFactoryBase.java @@ -32,6 +32,8 @@ */ public abstract class ConnectionFactoryBase implements ConnectionFactory { + public static final String NATIVE_TRANSPORT_REQUIRED = "The Vertx instance must use a native transport in order to connect to connect through domain sockets"; + protected final VertxInternal vertx; protected final NetClient netClient; protected final Map properties; @@ -54,6 +56,12 @@ public abstract class ConnectionFactoryBase implements ConnectionFactory { private final long reconnectInterval; protected ConnectionFactoryBase(VertxInternal vertx, SqlConnectOptions options) { + + // check we can do domain sockets + if (options.isUsingDomainSocket() && !vertx.isNativeTransportEnabled()) { + throw new IllegalArgumentException(NATIVE_TRANSPORT_REQUIRED); + } + this.vertx = vertx; this.properties = options.getProperties() == null ? null : Collections.unmodifiableMap(options.getProperties()); this.server = options.getSocketAddress();