Search in sources :

Example 1 with DefaultSqlClientPoolConfiguration

use of org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration in project hibernate-reactive by hibernate.

the class JdbcUrlParserTest method assertOptions.

/**
 * Create the default {@link SqlConnectOptions} with the given extra properties
 * and assert that's correct.
 */
private void assertOptions(String url, String expectedDbName, Map<String, String> parameters) {
    URI uri = DefaultSqlClientPool.parse(url);
    SqlConnectOptions options = new DefaultSqlClientPoolConfiguration().connectOptions(uri);
    // These keys won't be mapped as properties
    String username = parameters.remove("user");
    String password = parameters.remove("password");
    parameters.remove("database");
    assertThat(options).as("URL: " + url).isNotNull();
    assertThat(options.getUser()).as("URL: " + url).isEqualTo(username);
    assertThat(options.getPassword()).as("URL: " + url).isEqualTo(password);
    assertThat(options.getDatabase()).as("URL: " + url).isEqualTo(expectedDbName);
    assertThat(options.getHost()).as("URL: " + url).isEqualTo("localhost");
    assertThat(options.getPort()).as("URL: " + url).isEqualTo(dbType().getDefaultPort());
    // Check extra properties
    assertThat(options.getProperties()).as("URL: " + url).containsExactlyInAnyOrderEntriesOf(parameters);
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) DefaultSqlClientPoolConfiguration(org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration) URI(java.net.URI)

Example 2 with DefaultSqlClientPoolConfiguration

use of org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration in project hibernate-reactive by hibernate.

the class JdbcUrlParserTest method missingUser.

@Test
public void missingUser() {
    final HibernateError error = assertThrows(HibernateError.class, () -> {
        String url = createJdbcUrl("localhost", dbType().getDefaultPort(), DEFAULT_DB, Map.of());
        URI uri = DefaultSqlClientPool.parse(url);
        new DefaultSqlClientPoolConfiguration().connectOptions(uri);
    });
    assertThat(error.getMessage()).contains("database username not specified");
}
Also used : HibernateError(org.hibernate.HibernateError) DefaultSqlClientPoolConfiguration(org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration) URI(java.net.URI) Test(org.junit.Test)

Example 3 with DefaultSqlClientPoolConfiguration

use of org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration in project hibernate-reactive by hibernate.

the class ReactiveConnectionPoolTest method configureAndStartPool.

private ReactiveConnectionPool configureAndStartPool(Map<String, Object> config) {
    DefaultSqlClientPoolConfiguration poolConfig = new DefaultSqlClientPoolConfiguration();
    poolConfig.configure(config);
    registryRule.addService(SqlClientPoolConfiguration.class, poolConfig);
    registryRule.addService(JdbcServices.class, new JdbcServicesImpl() {

        @Override
        public SqlStatementLogger getSqlStatementLogger() {
            return new SqlStatementLogger();
        }
    });
    DefaultSqlClientPool reactivePool = new DefaultSqlClientPool();
    reactivePool.injectServices(registryRule.getServiceRegistry());
    reactivePool.configure(config);
    reactivePool.start();
    return reactivePool;
}
Also used : JdbcServicesImpl(org.hibernate.engine.jdbc.internal.JdbcServicesImpl) DefaultSqlClientPool(org.hibernate.reactive.pool.impl.DefaultSqlClientPool) DefaultSqlClientPoolConfiguration(org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration) SqlStatementLogger(org.hibernate.engine.jdbc.spi.SqlStatementLogger)

Example 4 with DefaultSqlClientPoolConfiguration

use of org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration in project hibernate-reactive by hibernate.

the class DefaultPortTest method testUnrecognizedSchemeException.

@Test
public void testUnrecognizedSchemeException() throws URISyntaxException {
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        URI uri = new URI("bogusScheme://localhost/database");
        new DefaultSqlClientPoolConfiguration().connectOptions(uri);
    });
}
Also used : DefaultSqlClientPoolConfiguration(org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration) URI(java.net.URI) Test(org.junit.Test)

Example 5 with DefaultSqlClientPoolConfiguration

use of org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration in project hibernate-reactive by hibernate.

the class DefaultPortTest method testDefaultPortIsSet.

@Test
public void testDefaultPortIsSet() throws URISyntaxException {
    DefaultSqlClientPoolConfiguration configuration = new DefaultSqlClientPoolConfiguration();
    configuration.configure(requiredProperties());
    SqlConnectOptions sqlConnectOptions = configuration.connectOptions(new URI(scheme() + "://localhost/database"));
    Assertions.assertThat(sqlConnectOptions.getPort()).as("Default port not defined for " + dbType()).isEqualTo(dbType().getDefaultPort());
}
Also used : SqlConnectOptions(io.vertx.sqlclient.SqlConnectOptions) DefaultSqlClientPoolConfiguration(org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration) URI(java.net.URI) Test(org.junit.Test)

Aggregations

DefaultSqlClientPoolConfiguration (org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration)5 URI (java.net.URI)4 Test (org.junit.Test)3 SqlConnectOptions (io.vertx.sqlclient.SqlConnectOptions)2 HibernateError (org.hibernate.HibernateError)1 JdbcServicesImpl (org.hibernate.engine.jdbc.internal.JdbcServicesImpl)1 SqlStatementLogger (org.hibernate.engine.jdbc.spi.SqlStatementLogger)1 DefaultSqlClientPool (org.hibernate.reactive.pool.impl.DefaultSqlClientPool)1