Search in sources :

Example 31 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcConnectionPoolValidatorTest method createMock.

private JdbcConnectionPool createMock() {
    final JdbcConnectionPool pool = createNiceMock(JdbcConnectionPool.class);
    expect(pool.getName()).andStubReturn("MyPoolName");
    expect(pool.getWrapJdbcObjects()).andStubReturn("true");
    // fictive wrapper, validator does not check if it can work
    expect(pool.getSqlTraceListeners()).andStubReturn(SQLTraceListener.class.getName());
    expect(pool.getStatementCacheSize()).andStubReturn("10");
    expect(pool.getStatementLeakTimeoutInSeconds()).andStubReturn("30");
    expect(pool.getStatementLeakReclaim()).andStubReturn("true");
    expect(pool.getSteadyPoolSize()).andStubReturn("0");
    expect(pool.getMaxPoolSize()).andStubReturn("16");
    expect(pool.getIsConnectionValidationRequired()).andStubReturn("false");
    expect(pool.getConnectionValidationMethod()).andStubReturn(null);
    expect(pool.getValidationTableName()).andStubReturn(null);
    expect(pool.getValidationClassname()).andStubReturn(null);
    expect(pool.getResType()).andStubReturn(DataSource.class.getName());
    // fictive, validator does not check if it is a really usable impl
    expect(pool.getDatasourceClassname()).andStubReturn(DataSource.class.getName());
    expect(pool.getDriverClassname()).andStubReturn(null);
    replay(pool);
    return pool;
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) SQLTraceListener(org.glassfish.api.jdbc.SQLTraceListener) XADataSource(javax.sql.XADataSource) DataSource(javax.sql.DataSource) ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource)

Example 32 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcConnectionPoolValidatorTest method tableNameConnectionValidation.

@Test
public void tableNameConnectionValidation() {
    this.validator.initialize(createAnnotation(TABLE_NAME_MANDATORY));
    final JdbcConnectionPool pool = createMock();
    assertTrue("everything OK", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getIsConnectionValidationRequired()).andStubReturn("true");
        expect(p.getConnectionValidationMethod()).andStubReturn("table");
        expect(p.getValidationTableName()).andStubReturn("MY-TABLE");
    });
    assertTrue("validation by table enabled, everything is set", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getIsConnectionValidationRequired()).andStubReturn("true");
        // is this alright?
        expect(p.getConnectionValidationMethod()).andStubReturn("somethingelse");
        expect(p.getValidationTableName()).andStubReturn(null);
    });
    assertTrue("validation by table is not set", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getIsConnectionValidationRequired()).andStubReturn("true");
        expect(p.getConnectionValidationMethod()).andStubReturn("table");
        expect(p.getValidationTableName()).andStubReturn(null);
    });
    assertFalse("validation by table set, but no table name", this.validator.isValid(pool, null));
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Test(org.junit.Test)

Aggregations

JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)32 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)10 JdbcResource (org.glassfish.jdbc.config.JdbcResource)7 Test (org.junit.Test)7 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)5 Resources (com.sun.enterprise.config.serverbeans.Resources)4 Resource (com.sun.enterprise.config.serverbeans.Resource)3 ActionReport (org.glassfish.api.ActionReport)3 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)2 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)2 DataSourceDefinitionDescriptor (com.sun.enterprise.deployment.DataSourceDefinitionDescriptor)2 ArrayList (java.util.ArrayList)2 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)2 DataSource (javax.sql.DataSource)2 XADataSource (javax.sql.XADataSource)2 ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)2 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)2 Property (org.jvnet.hk2.config.types.Property)2