use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.
the class JdbcConnectionPoolValidatorTest method wrappers.
@Test
public void wrappers() {
this.validator.initialize(createAnnotation(STMT_WRAPPING_DISABLED));
final JdbcConnectionPool pool = createMock();
assertTrue("everything OK", this.validator.isValid(pool, null));
updateMock(pool, p -> expect(p.getWrapJdbcObjects()).andStubReturn("false"));
assertTrue("wrapping disabled, all related settings ok", this.validator.isValid(pool, null));
updateMock(pool, p -> {
expect(p.getWrapJdbcObjects()).andStubReturn("false");
expect(p.getSqlTraceListeners()).andStubReturn(null);
expect(p.getStatementCacheSize()).andStubReturn("200");
});
assertFalse("wrapping disabled, but statement cache size set", this.validator.isValid(pool, null));
updateMock(pool, p -> {
expect(p.getWrapJdbcObjects()).andStubReturn(null);
expect(p.getStatementCacheSize()).andStubReturn("13");
expect(p.getStatementLeakTimeoutInSeconds()).andStubReturn("30");
});
assertFalse("wrapping disabled, but statement leak timeout set", this.validator.isValid(pool, null));
updateMock(pool, p -> {
expect(p.getWrapJdbcObjects()).andStubReturn(null);
expect(p.getStatementLeakTimeoutInSeconds()).andStubReturn(null);
expect(p.getStatementLeakReclaim()).andStubReturn("true");
});
assertFalse("wrapping disabled, but statement leak reclaim set", this.validator.isValid(pool, null));
updateMock(pool, p -> {
expect(p.getWrapJdbcObjects()).andStubReturn(null);
expect(p.getStatementLeakTimeoutInSeconds()).andStubReturn(null);
expect(p.getStatementLeakReclaim()).andStubReturn("false");
});
assertTrue("wrapping disabled, no conflicts", this.validator.isValid(pool, null));
}
use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.
the class JdbcConnectionPoolValidatorTest method poolSizeSteady.
@Test
public void poolSizeSteady() {
this.validator.initialize(createAnnotation(POOL_SIZE_STEADY));
final JdbcConnectionPool pool = createMock();
assertTrue("everything OK", this.validator.isValid(pool, null));
updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn(null));
assertTrue("steady pool size null", this.validator.isValid(pool, null));
updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn("-1"));
assertFalse("steady pool size negative", this.validator.isValid(pool, null));
updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn("${env.steadypoolsizeproperty}"));
assertFalse("undefined variable in steady pool size", this.validator.isValid(pool, null));
updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn("${ENV=steadypoolsizeproperty}"));
assertFalse("undefined variable in steady pool size", this.validator.isValid(pool, null));
updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn("${ENV=USER}"));
assertFalse("env.USER variable in steady pool size is not a number", this.validator.isValid(pool, null));
updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn("${MPCONFIG=USER}"));
try {
this.validator.isValid(pool, null);
fail("Expected exception, because we don't have any microprofile impl here.");
} catch (final Exception e) {
assertEquals("root cause.message", "No ConfigProviderResolver implementation found!", ExceptionUtil.getRootCause(e).getMessage());
}
updateMock(pool, p -> {
expect(p.getSteadyPoolSize()).andStubReturn("8");
expect(p.getMaxPoolSize()).andStubReturn("5");
});
assertTrue("this should not check the max pool size", this.validator.isValid(pool, null));
}
use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.
the class FlushConnectionPool method execute.
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
Resources resources = domain.getResources();
String scope = "";
if (moduleName != null) {
if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
return;
}
Application application = applications.getApplication(applicationName);
Module module = application.getModule(moduleName);
resources = module.getResources();
scope = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX;
} else if (applicationName != null) {
if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
return;
}
Application application = applications.getApplication(applicationName);
resources = application.getResources();
scope = ConnectorConstants.JAVA_APP_SCOPE_PREFIX;
}
if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
return;
}
boolean poolingEnabled = false;
ResourcePool pool = (ResourcePool) ConnectorsUtil.getResourceByName(resources, ResourcePool.class, poolName);
if (pool instanceof ConnectorConnectionPool) {
ConnectorConnectionPool ccp = (ConnectorConnectionPool) pool;
poolingEnabled = Boolean.valueOf(ccp.getPooling());
} else {
JdbcConnectionPool ccp = (JdbcConnectionPool) pool;
poolingEnabled = Boolean.valueOf(ccp.getPooling());
}
if (!poolingEnabled) {
String i18nMsg = localStrings.getLocalString("flush.connection.pool.pooling.disabled", "Attempt to Flush Connection Pool failed because Pooling is disabled for pool : {0}", poolName);
report.setMessage(i18nMsg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
_runtime.flushConnectionPool(poolInfo);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (ConnectorRuntimeException e) {
report.setMessage(localStrings.getLocalString("flush.connection.pool.fail", "Flush connection pool for {0} failed", poolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.
the class FlushConnectionPoolLocal method execute.
@Override
public void execute(AdminCommandContext context) {
final ActionReport report = context.getActionReport();
Resources resources = domain.getResources();
String scope = "";
if (moduleName != null) {
if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
return;
}
Application application = applications.getApplication(applicationName);
Module module = application.getModule(moduleName);
resources = module.getResources();
scope = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX;
} else if (applicationName != null) {
if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
return;
}
Application application = applications.getApplication(applicationName);
resources = application.getResources();
scope = ConnectorConstants.JAVA_APP_SCOPE_PREFIX;
}
if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
return;
}
boolean poolingEnabled = false;
ResourcePool pool = (ResourcePool) ConnectorsUtil.getResourceByName(resources, ResourcePool.class, poolName);
if (pool instanceof ConnectorConnectionPool) {
ConnectorConnectionPool ccp = (ConnectorConnectionPool) pool;
poolingEnabled = Boolean.valueOf(ccp.getPooling());
} else {
JdbcConnectionPool ccp = (JdbcConnectionPool) pool;
poolingEnabled = Boolean.valueOf(ccp.getPooling());
}
if (!poolingEnabled) {
String i18nMsg = localStrings.getLocalString("flush.connection.pool.pooling.disabled", "Attempt to Flush Connection Pool failed because Pooling is disabled for pool : {0}", poolName);
report.setMessage(i18nMsg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
_runtime.flushConnectionPool(poolInfo);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
Logger.getLogger("org.glassfish.connectors.admin.cli").log(Level.FINE, "Flush connection pool for {0} succeeded", poolName);
} catch (ConnectorRuntimeException e) {
report.setMessage(localStrings.getLocalString("flush.connection.pool.fail", "Flush connection pool for {0} failed", poolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
}
use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.
the class JdbcRuntimeExtension method getDeferredResourceConfig.
@Override
public DeferredResourceConfig getDeferredResourceConfig(Object resource, Object pool, String resType, String raName) throws ConnectorRuntimeException {
String resourceAdapterName;
DeferredResourceConfig resConfig = null;
// TODO V3 (not to hold specific resource types)
if (resource instanceof JdbcResource || pool instanceof JdbcConnectionPool) {
JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
JdbcResource jdbcResource = (JdbcResource) resource;
resourceAdapterName = getRANameofJdbcConnectionPool((JdbcConnectionPool) pool);
resConfig = new DeferredResourceConfig(resourceAdapterName, null, jdbcPool, jdbcResource, null);
Resource[] resourcesToload = new Resource[] { jdbcPool, jdbcResource };
resConfig.setResourcesToLoad(resourcesToload);
} else {
throw new ConnectorRuntimeException("unsupported resource type : " + resource);
}
return resConfig;
}
Aggregations