use of org.ow2.petals.component.framework.junit.rule.ComponentUnderTest in project petals-bc-gateway by petalslink.
the class AbstractComponentTest method ensureNoExchangeInProgress.
protected void ensureNoExchangeInProgress(final Component componentUnderTest) {
final BcGatewayComponent comp = (BcGatewayComponent) componentUnderTest.getComponentObject();
for (final ProviderDomain pd : comp.getServiceUnitManager().getProviderDomains()) {
@SuppressWarnings("unchecked") final Map<String, Exchange> exchangesInProgress = (Map<String, Exchange>) ReflectionHelper.getFieldValue(AbstractDomain.class, pd, "exchangesInProgress", false);
assertTrue(String.format("Exchange in progress is not empty for %s: %s", pd.getJPD().getId(), exchangesInProgress), exchangesInProgress.isEmpty());
}
for (final ConsumerDomain pd : comp.getServiceUnitManager().getConsumerDomains()) {
@SuppressWarnings("unchecked") final Map<String, Exchange> exchangesInProgress = (Map<String, Exchange>) ReflectionHelper.getFieldValue(AbstractDomain.class, pd, "exchangesInProgress", false);
assertTrue(String.format("Exchange in progress is not empty for %s: %s", pd.getJCD().getId(), exchangesInProgress), exchangesInProgress.isEmpty());
}
}
use of org.ow2.petals.component.framework.junit.rule.ComponentUnderTest in project petals-se-flowable by petalslink.
the class FlowableSEBootstrapTest method setValuesAreUsed.
/**
* Check that valid values set through the component bootstrap through JMX are correctly used by component.
*/
@Test
public void setValuesAreUsed() throws Throwable {
// To access the component bootstrap through JMX, the component has not to be installed, only loaded
final ComponentUnderTest componentUnderTest = new ComponentUnderTest(false, false).addLogHandler(IN_MEMORY_LOG_HANDLER.getHandler()).addEmbeddedJmxSrv(this.embeddedJmxSrvCon);
componentUnderTest.create();
try {
final AbstractComponent component = componentUnderTest.getComponentObject();
assertNotNull(component);
assertTrue(component instanceof FlowableSE);
final FlowableSE flowableComponent = (FlowableSE) component;
// Set values using the component bootstrap through JMX
final String databaseType = "h2";
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_DATABASE_TYPE, databaseType);
final String databaseSchemaUpdate = "create-drop";
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_DATABASE_SCHEMA_UPDATE, databaseSchemaUpdate);
final String jdbcDriver = Driver.class.getName();
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_JDBC_DRIVER, jdbcDriver);
final String jdbcUsername = "my-user";
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_JDBC_USERNAME, jdbcUsername);
final String jdbcPassword = "my-user-pwd";
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_JDBC_PASSWORD, jdbcPassword);
final File databaseFile = this.tempFolder.newFile("my-database.db");
final String jdbcUrl = String.format("jdbc:h2:%s", databaseFile.toURI().toURL().toExternalForm());
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_JDBC_URL, jdbcUrl);
final int jdbcMaxActiveConnections = 12;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_JDBC_MAX_ACTIVE_CONNECTIONS, Integer.valueOf(jdbcMaxActiveConnections));
final int jdbcMaxIdleConnections = 21;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_JDBC_MAX_IDLE_CONNECTIONS, Integer.valueOf(jdbcMaxIdleConnections));
final int jdbcMaxCheckoutTime = 1592;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_JDBC_MAX_CHECKOUT_TIME, Integer.valueOf(jdbcMaxCheckoutTime));
final int jdbcMaxWaitTime = 56842;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_JDBC_MAX_WAIT_TIME, Integer.valueOf(jdbcMaxWaitTime));
final boolean jobExecutorEnableJobExecutor = true;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_ENABLE_JOB_EXECUTOR, String.valueOf(jobExecutorEnableJobExecutor));
final int jobExecutorCorePoolSize = 27;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_JOB_EXECUTOR_COREPOOLSIZE, Integer.valueOf(jobExecutorCorePoolSize));
final int jobExecutorMaxPoolSize = 52;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_JOB_EXECUTOR_MAXPOOLSIZE, Integer.valueOf(jobExecutorMaxPoolSize));
final long jobExecutorKeepAliveTime = 559862;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_JOB_EXECUTOR_KEEPALIVETIME, Long.valueOf(jobExecutorKeepAliveTime));
final int jobExecutorQueueSize = 123;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_JOB_EXECUTOR_QUEUESIZE, Integer.valueOf(jobExecutorQueueSize));
final int jobExecutorMaxTimerJobsPerAcquisition = 682;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_JOB_EXECUTOR_MAXTIMERJOBSPERACQUISITION, Integer.valueOf(jobExecutorMaxTimerJobsPerAcquisition));
final int jobExecutorMaxAsyncJobsDuePerAcquisition = 357;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_JOB_EXECUTOR_MAXASYNCJOBSDUEPERACQUISITION, Integer.valueOf(jobExecutorMaxAsyncJobsDuePerAcquisition));
final int jobExecutorAsyncJobAcquireWaitTime = 623;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_JOB_EXECUTOR_ASYNCJOBACQUIREWAITTIME, Integer.valueOf(jobExecutorAsyncJobAcquireWaitTime));
final int jobExecutorTimerJobAcquireWaitTime = 51397;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_JOB_EXECUTOR_TIMERJOBACQUIREWAITTIME, Integer.valueOf(jobExecutorTimerJobAcquireWaitTime));
final int jobExecutorTimerLockTime = 26842;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_JOB_EXECUTOR_TIMERLOCKTIME, Integer.valueOf(jobExecutorTimerLockTime));
final int jobExecutorAsyncJobLockTime = 512;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_JOB_EXECUTOR_ASYNCJOBLOCKTIME, Integer.valueOf(jobExecutorAsyncJobLockTime));
final boolean engineEnableBpmnValidation = true;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_ENABLE_BPMN_VALIDATION, String.valueOf(engineEnableBpmnValidation));
final int defaultFailedJobWaitTime = 15;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_DEFAULT_FAILED_JOB_WAITTIME, Integer.valueOf(defaultFailedJobWaitTime));
final int asyncFailedJobWaitTime = 5;
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_ENGINE_ASYNC_FAILED_JOB_WAITTIME, Integer.valueOf(asyncFailedJobWaitTime));
final String idmEngineConfiguratorClass = FileIdmEngineConfigurator.class.getName();
this.jmxClient.setBootstrapAttribute(FlowableSEBootstrap.ATTR_NAME_IDM_ENGINE_CONFIGURATOR_CLASS_NAME, idmEngineConfiguratorClass);
// We continue component lifecycle to be able to check are correctly used
componentUnderTest.install();
componentUnderTest.start();
// Some parameter are set in the Flowable engine configuration
final ProcessEngine processEngine = flowableComponent.getProcessEngine();
assertNotNull(processEngine);
final ProcessEngineConfiguration pec = processEngine.getProcessEngineConfiguration();
assertNotNull(pec);
final AsyncExecutor asyncExecutor = pec.getAsyncExecutor();
assertTrue(asyncExecutor instanceof DefaultAsyncJobExecutor);
final DefaultAsyncJobExecutor defaultAsyncExecutor = (DefaultAsyncJobExecutor) asyncExecutor;
assertEquals(databaseType, pec.getDatabaseType());
assertEquals(databaseSchemaUpdate, pec.getDatabaseSchemaUpdate());
assertEquals(jdbcDriver, pec.getJdbcDriver());
assertEquals(jdbcUrl, pec.getJdbcUrl());
assertEquals(jdbcUsername, pec.getJdbcUsername());
assertEquals(jdbcPassword, pec.getJdbcPassword());
assertEquals(jdbcMaxActiveConnections, pec.getJdbcMaxActiveConnections());
assertEquals(jdbcMaxIdleConnections, pec.getJdbcMaxIdleConnections());
assertEquals(jdbcMaxCheckoutTime, pec.getJdbcMaxCheckoutTime());
assertEquals(jdbcMaxWaitTime, pec.getJdbcMaxWaitTime());
// Job executor is enable when a async executor exists at Flowable level. We use operator '!=' instead of
// '^' that is more human-readable and equivalent
// (https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.22.2)
assertTrue(jobExecutorEnableJobExecutor != (pec.getAsyncExecutor() == null));
assertTrue(defaultAsyncExecutor.getTaskExecutor() instanceof DefaultAsyncTaskExecutor);
final DefaultAsyncTaskExecutor defaultAsyncTaskExecutor = (DefaultAsyncTaskExecutor) defaultAsyncExecutor.getTaskExecutor();
assertEquals(jobExecutorCorePoolSize, defaultAsyncTaskExecutor.getCorePoolSize());
assertEquals(jobExecutorMaxPoolSize, defaultAsyncTaskExecutor.getMaxPoolSize());
assertEquals(jobExecutorKeepAliveTime, defaultAsyncTaskExecutor.getKeepAliveTime());
assertEquals(jobExecutorQueueSize, defaultAsyncTaskExecutor.getQueueSize());
assertEquals(jobExecutorMaxTimerJobsPerAcquisition, defaultAsyncExecutor.getMaxTimerJobsPerAcquisition());
assertEquals(jobExecutorMaxAsyncJobsDuePerAcquisition, defaultAsyncExecutor.getMaxAsyncJobsDuePerAcquisition());
assertEquals(jobExecutorAsyncJobAcquireWaitTime, defaultAsyncExecutor.getDefaultAsyncJobAcquireWaitTimeInMillis());
assertEquals(jobExecutorTimerJobAcquireWaitTime, defaultAsyncExecutor.getDefaultTimerJobAcquireWaitTimeInMillis());
assertEquals(jobExecutorTimerLockTime, defaultAsyncExecutor.getTimerLockTimeInMillis());
assertEquals(jobExecutorAsyncJobLockTime, defaultAsyncExecutor.getAsyncJobLockTimeInMillis());
assertEquals(engineEnableBpmnValidation, ReflectionHelper.getFieldValue(FlowableSuManager.class, (FlowableSuManager) flowableComponent.getServiceUnitManager(), "enableFlowableBpmnValidation", false));
assertEquals(defaultFailedJobWaitTime, pec.getDefaultFailedJobWaitTime());
assertEquals(asyncFailedJobWaitTime, pec.getAsyncFailedJobWaitTime());
} finally {
componentUnderTest.delete();
}
}
Aggregations