Search in sources :

Example 1 with ReactiveConnectionPool

use of org.hibernate.reactive.pool.ReactiveConnectionPool in project hibernate-reactive by hibernate.

the class ReactiveConnectionPoolTest method configureWithCredentials.

@Test
public void configureWithCredentials(TestContext context) {
    // Set up URL with invalid credentials so we can ensure that
    // explicit USER and PASS settings take precedence over credentials in the URL
    String url = DatabaseConfiguration.getJdbcUrl();
    url = url.replace("user=" + DatabaseConfiguration.USERNAME, "user=bogus");
    url = url.replace("password=" + DatabaseConfiguration.PASSWORD, "password=bogus");
    // Correct user/password are supplied explicitly in the config map and
    // should override the credentials in the URL
    Map<String, Object> config = new HashMap<>();
    config.put(Settings.URL, url);
    config.put(Settings.USER, DatabaseConfiguration.USERNAME);
    config.put(Settings.PASS, DatabaseConfiguration.PASSWORD);
    ReactiveConnectionPool reactivePool = configureAndStartPool(config);
    test(context, verifyConnectivity(context, reactivePool));
}
Also used : ReactiveConnectionPool(org.hibernate.reactive.pool.ReactiveConnectionPool) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with ReactiveConnectionPool

use of org.hibernate.reactive.pool.ReactiveConnectionPool in project hibernate-reactive by hibernate.

the class ReactiveConnectionPoolTest method configureWithWrongCredentials.

@Test
public void configureWithWrongCredentials(TestContext context) {
    String url = DatabaseConfiguration.getJdbcUrl();
    Map<String, Object> config = new HashMap<>();
    config.put(Settings.URL, url);
    config.put(Settings.USER, "bogus");
    config.put(Settings.PASS, "bogus");
    ReactiveConnectionPool reactivePool = configureAndStartPool(config);
    test(context, assertThrown(PgException.class, verifyConnectivity(context, reactivePool)).thenAccept(e -> assertThat(e.getMessage()).contains("bogus")));
}
Also used : ReactiveConnectionPool(org.hibernate.reactive.pool.ReactiveConnectionPool) JdbcServicesImpl(org.hibernate.engine.jdbc.internal.JdbcServicesImpl) TestContext(io.vertx.ext.unit.TestContext) PgException(io.vertx.pgclient.PgException) Async(io.vertx.ext.unit.Async) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Timeout(io.vertx.ext.unit.junit.Timeout) DatabaseSelectionRule(org.hibernate.reactive.testing.DatabaseSelectionRule) ReactiveConnectionPool(org.hibernate.reactive.pool.ReactiveConnectionPool) TestingRegistryRule(org.hibernate.reactive.testing.TestingRegistryRule) POSTGRESQL(org.hibernate.reactive.containers.DatabaseConfiguration.DBType.POSTGRESQL) Map(java.util.Map) DefaultSqlClientPoolConfiguration(org.hibernate.reactive.pool.impl.DefaultSqlClientPoolConfiguration) ReactiveAssertions.assertThrown(org.hibernate.reactive.testing.ReactiveAssertions.assertThrown) SqlClientPoolConfiguration(org.hibernate.reactive.pool.impl.SqlClientPoolConfiguration) Test(org.junit.Test) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SqlStatementLogger(org.hibernate.engine.jdbc.spi.SqlStatementLogger) DatabaseConfiguration(org.hibernate.reactive.containers.DatabaseConfiguration) CompletionStage(java.util.concurrent.CompletionStage) Rule(org.junit.Rule) DefaultSqlClientPool(org.hibernate.reactive.pool.impl.DefaultSqlClientPool) Settings(org.hibernate.reactive.provider.Settings) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with ReactiveConnectionPool

use of org.hibernate.reactive.pool.ReactiveConnectionPool in project hibernate-reactive by hibernate.

the class ReactiveConnectionPoolTest method configureWithJdbcUrl.

@Test
public void configureWithJdbcUrl(TestContext context) {
    String url = DatabaseConfiguration.getJdbcUrl();
    Map<String, Object> config = new HashMap<>();
    config.put(Settings.URL, url);
    ReactiveConnectionPool reactivePool = configureAndStartPool(config);
    test(context, verifyConnectivity(context, reactivePool));
}
Also used : ReactiveConnectionPool(org.hibernate.reactive.pool.ReactiveConnectionPool) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with ReactiveConnectionPool

use of org.hibernate.reactive.pool.ReactiveConnectionPool in project hibernate-reactive by hibernate.

the class ReactiveConnectionPoolInitiator method initiateService.

@Override
public ReactiveConnectionPool initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
    Object configValue = configurationValues.get(Settings.SQL_CLIENT_POOL);
    if (configValue == null) {
        return new DefaultSqlClientPool();
    }
    if (configValue instanceof ReactiveConnectionPool) {
        return (ReactiveConnectionPool) configValue;
    } else {
        final Class<ReactiveConnectionPool> implClass;
        if (configValue instanceof Class) {
            implClass = (Class) configValue;
        } else {
            final String className = configValue.toString();
            final ClassLoaderService classLoaderService = registry.getService(ClassLoaderService.class);
            try {
                implClass = classLoaderService.classForName(className);
            } catch (ClassLoadingException cle) {
                throw new ServiceException("Unable to locate specified reactive connection pool [" + className + "]");
            }
        }
        try {
            LOG.instantiatingReactivePool(implClass);
            return implClass.newInstance();
        } catch (Exception e) {
            throw new ServiceException("Unable to instantiate specified reactive connection pool [" + implClass.getName() + "]");
        }
    }
}
Also used : ReactiveConnectionPool(org.hibernate.reactive.pool.ReactiveConnectionPool) ServiceException(org.hibernate.service.spi.ServiceException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ServiceException(org.hibernate.service.spi.ServiceException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Aggregations

ReactiveConnectionPool (org.hibernate.reactive.pool.ReactiveConnectionPool)4 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)1 Timeout (io.vertx.ext.unit.junit.Timeout)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 PgException (io.vertx.pgclient.PgException)1 Map (java.util.Map)1 CompletionStage (java.util.concurrent.CompletionStage)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1 JdbcServicesImpl (org.hibernate.engine.jdbc.internal.JdbcServicesImpl)1 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)1 SqlStatementLogger (org.hibernate.engine.jdbc.spi.SqlStatementLogger)1 DatabaseConfiguration (org.hibernate.reactive.containers.DatabaseConfiguration)1 POSTGRESQL (org.hibernate.reactive.containers.DatabaseConfiguration.DBType.POSTGRESQL)1 DefaultSqlClientPool (org.hibernate.reactive.pool.impl.DefaultSqlClientPool)1