Skip to content

Commit

Permalink
Creating a client with a domain socket options should only work when …
Browse files Browse the repository at this point in the history
…the transport supports it

fixes #1114
  • Loading branch information
vietj committed Jan 3, 2022
1 parent 7365faa commit 352e8da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> properties;
Expand All @@ -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();
Expand Down

0 comments on commit 352e8da

Please sign in to comment.