Java Code Examples for io.agroal.api.AgroalDataSource#getConnection()

The following examples show how to use io.agroal.api.AgroalDataSource#getConnection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NamedDataSourceConfigTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void dataSourceAssert(String dataSourceName, AgroalDataSource dataSource, String jdbcUrl, String username,
        int minSize, int maxSize)
        throws SQLException {
    AgroalConnectionPoolConfiguration configuration = null;

    try {
        configuration = dataSource.getConfiguration().connectionPoolConfiguration();
    } catch (NullPointerException e) {
        // we catch the NPE here as we have a proxy and we can't test dataSource directly
        fail("Datasource " + dataSourceName + " should not be null");
    }
    assertEquals(jdbcUrl, configuration.connectionFactoryConfiguration().jdbcUrl());
    assertEquals(username, configuration.connectionFactoryConfiguration().principal().getName());
    assertEquals(minSize, configuration.minSize());
    assertEquals(maxSize, configuration.maxSize());
    assertFalse(dataSource.getConfiguration().metricsEnabled()); // metrics not enabled by default

    try (Connection connection = dataSource.getConnection()) {
    }
}
 
Example 2
Source File: UnknownDriverConfigTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void testDataSource(AgroalDataSource dataSource, String username, int minSize, int maxSize,
        int initialSize, Duration backgroundValidationInterval, Duration acquisitionTimeout, Duration leakDetectionInterval,
        Duration idleRemovalInterval, Duration maxLifetime, String newConnectionSql) throws SQLException {
    AgroalConnectionPoolConfiguration configuration = dataSource.getConfiguration().connectionPoolConfiguration();
    AgroalConnectionFactoryConfiguration agroalConnectionFactoryConfiguration = configuration
            .connectionFactoryConfiguration();

    assertEquals("jdbc:h2:tcp://localhost/mem:default", agroalConnectionFactoryConfiguration.jdbcUrl());
    assertEquals(username, agroalConnectionFactoryConfiguration.principal().getName());
    assertEquals(minSize, configuration.minSize());
    assertEquals(maxSize, configuration.maxSize());
    assertEquals(initialSize, configuration.initialSize());
    assertEquals(backgroundValidationInterval, configuration.validationTimeout());
    assertEquals(acquisitionTimeout, configuration.acquisitionTimeout());
    assertEquals(leakDetectionInterval, configuration.leakTimeout());
    assertEquals(idleRemovalInterval, configuration.reapTimeout());
    assertEquals(maxLifetime, configuration.maxLifetime());
    assertTrue(configuration.transactionIntegration() instanceof NarayanaTransactionIntegration);
    assertEquals(AgroalConnectionFactoryConfiguration.TransactionIsolation.SERIALIZABLE,
            agroalConnectionFactoryConfiguration.jdbcTransactionIsolation());
    assertTrue(agroalConnectionFactoryConfiguration.trackJdbcResources());
    assertTrue(dataSource.getConfiguration().metricsEnabled());
    assertEquals(newConnectionSql, agroalConnectionFactoryConfiguration.initialSql());
    try (Connection connection = dataSource.getConnection()) {
    }
}
 
Example 3
Source File: MultipleDataSourcesTestUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
static void testDataSource(String dataSourceName, AgroalDataSource dataSource, String jdbcUrl, String username,
        int minSize, int maxSize)
        throws SQLException {
    AgroalConnectionPoolConfiguration configuration = null;

    try {
        configuration = dataSource.getConfiguration().connectionPoolConfiguration();
    } catch (NullPointerException e) {
        // we catch the NPE here as we have a proxy and we can't test dataSource directly
        fail("Datasource " + dataSourceName + " should not be null");
    }
    assertEquals(jdbcUrl, configuration.connectionFactoryConfiguration().jdbcUrl());
    assertEquals(username, configuration.connectionFactoryConfiguration().principal().getName());
    assertEquals(minSize, configuration.minSize());
    assertEquals(maxSize, configuration.maxSize());

    try (Connection connection = dataSource.getConnection()) {
    }
}
 
Example 4
Source File: LegacyMultipleDataSourcesConfigTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void testDataSource(String dataSourceName, AgroalDataSource dataSource, String jdbcUrl, String username,
        int minSize, int maxSize)
        throws SQLException {
    AgroalConnectionPoolConfiguration configuration = null;

    try {
        configuration = dataSource.getConfiguration().connectionPoolConfiguration();
    } catch (NullPointerException e) {
        // we catch the NPE here as we have a proxy and we can't test dataSource directly
        fail("Datasource " + dataSourceName + " should not be null");
    }
    assertEquals(jdbcUrl, configuration.connectionFactoryConfiguration().jdbcUrl());
    assertEquals(username, configuration.connectionFactoryConfiguration().principal().getName());
    assertEquals(minSize, configuration.minSize());
    assertEquals(maxSize, configuration.maxSize());

    try (Connection connection = dataSource.getConnection()) {
    }
}
 
Example 5
Source File: LegacyDefaultDataSourceConfigTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void testDataSource(AgroalDataSource dataSource, String username, int minSize, int maxSize,
        int initialSize, Duration backgroundValidationInterval, Duration acquisitionTimeout, Duration leakDetectionInterval,
        Duration idleRemovalInterval, Duration maxLifetime, String newConnectionSql) throws SQLException {
    AgroalConnectionPoolConfiguration configuration = dataSource.getConfiguration().connectionPoolConfiguration();
    AgroalConnectionFactoryConfiguration agroalConnectionFactoryConfiguration = configuration
            .connectionFactoryConfiguration();

    assertEquals("jdbc:h2:tcp://localhost/mem:default", agroalConnectionFactoryConfiguration.jdbcUrl());
    assertEquals(username, agroalConnectionFactoryConfiguration.principal().getName());
    assertEquals(minSize, configuration.minSize());
    assertEquals(maxSize, configuration.maxSize());
    assertEquals(initialSize, configuration.initialSize());
    assertEquals(backgroundValidationInterval, configuration.validationTimeout());
    assertEquals(acquisitionTimeout, configuration.acquisitionTimeout());
    assertEquals(leakDetectionInterval, configuration.leakTimeout());
    assertEquals(idleRemovalInterval, configuration.reapTimeout());
    assertEquals(maxLifetime, configuration.maxLifetime());
    assertTrue(configuration.transactionIntegration() instanceof NarayanaTransactionIntegration);
    assertEquals(AgroalConnectionFactoryConfiguration.TransactionIsolation.SERIALIZABLE,
            agroalConnectionFactoryConfiguration.jdbcTransactionIsolation());
    assertTrue(agroalConnectionFactoryConfiguration.trackJdbcResources());
    assertTrue(dataSource.getConfiguration().metricsEnabled());
    assertEquals(newConnectionSql, agroalConnectionFactoryConfiguration.initialSql());
    try (Connection connection = dataSource.getConnection()) {
    }
}
 
Example 6
Source File: DefaultDataSourceConfigTest.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private static void testDataSource(AgroalDataSource dataSource, String username, int minSize, int maxSize,
        int initialSize, Duration backgroundValidationInterval, Duration acquisitionTimeout, Duration leakDetectionInterval,
        Duration idleRemovalInterval, Duration maxLifetime, String newConnectionSql) throws SQLException {
    AgroalConnectionPoolConfiguration configuration = dataSource.getConfiguration().connectionPoolConfiguration();
    AgroalConnectionFactoryConfiguration agroalConnectionFactoryConfiguration = configuration
            .connectionFactoryConfiguration();

    assertEquals("jdbc:h2:tcp://localhost/mem:default", agroalConnectionFactoryConfiguration.jdbcUrl());
    assertEquals(username, agroalConnectionFactoryConfiguration.principal().getName());
    assertEquals(minSize, configuration.minSize());
    assertEquals(maxSize, configuration.maxSize());
    assertEquals(initialSize, configuration.initialSize());
    assertEquals(backgroundValidationInterval, configuration.validationTimeout());
    assertEquals(acquisitionTimeout, configuration.acquisitionTimeout());
    assertEquals(leakDetectionInterval, configuration.leakTimeout());
    assertEquals(idleRemovalInterval, configuration.reapTimeout());
    assertEquals(maxLifetime, configuration.maxLifetime());
    assertTrue(configuration.transactionIntegration() instanceof NarayanaTransactionIntegration);
    assertEquals(AgroalConnectionFactoryConfiguration.TransactionIsolation.SERIALIZABLE,
            agroalConnectionFactoryConfiguration.jdbcTransactionIsolation());
    assertTrue(agroalConnectionFactoryConfiguration.trackJdbcResources());
    assertTrue(dataSource.getConfiguration().metricsEnabled());
    assertEquals(newConnectionSql, agroalConnectionFactoryConfiguration.initialSql());
    try (Connection connection = dataSource.getConnection()) {
    }
}