use of org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace in project controller by opendaylight.
the class SimpleConfigurationTest method testValidation.
private static void testValidation(final ConfigTransactionClient transaction) throws InstanceAlreadyExistsException, ReflectionException, InstanceNotFoundException, MBeanException, ConflictingVersionException {
ObjectName fixed1names = transaction.createModule(TestingFixedThreadPoolModuleFactory.NAME, FIXED1);
// call validate on config bean
try {
platformMBeanServer.invoke(fixed1names, "validate", new Object[0], new String[0]);
fail();
} catch (final MBeanException e) {
Exception targetException = e.getTargetException();
assertNotNull(targetException);
assertEquals(ValidationException.class, targetException.getClass());
}
// validate config bean
try {
transaction.validateBean(fixed1names);
fail();
} catch (final ValidationException e) {
for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e.getFailedValidations().entrySet()) {
for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception.getValue().entrySet()) {
assertEquals("Parameter 'threadCount' must be greater than 0", entry.getValue().getMessage());
}
}
}
// validate transaction
try {
transaction.validateConfig();
fail();
} catch (final ValidationException e) {
for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e.getFailedValidations().entrySet()) {
for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception.getValue().entrySet()) {
assertEquals("Parameter 'threadCount' must be greater than 0", entry.getValue().getMessage());
}
}
}
try {
transaction.commit();
} catch (final ValidationException e) {
for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e.getFailedValidations().entrySet()) {
for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception.getValue().entrySet()) {
assertEquals("Parameter 'threadCount' must be greater than 0", entry.getValue().getMessage());
}
}
}
}
use of org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace in project controller by opendaylight.
the class DependentWiringTest method testDependencies.
@Test
public void testDependencies() throws Exception {
ObjectName apspON;
{
ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
// create fixed1
ObjectName threadPoolTransactionON = createFixed1(transaction, TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
// create apsp-parallel
ObjectName apspNameTransactionON = createParallelAPSP(transaction, threadPoolTransactionON);
TestingParallelAPSPConfigMXBean parallelAPSPConfigProxy = transaction.newMXBeanProxy(apspNameTransactionON, TestingParallelAPSPConfigMXBean.class);
// trigger validation
parallelAPSPConfigProxy.setSomeParam("");
// failure
try {
transaction.validateConfig();
fail();
} catch (final ValidationException e) {
for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e.getFailedValidations().entrySet()) {
for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception.getValue().entrySet()) {
assertThat(entry.getValue().getMessage(), containsString("Parameter 'SomeParam' is blank"));
}
}
}
// try committing (validation fails)
try {
transaction.commit();
fail();
} catch (final ValidationException e) {
for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e.getFailedValidations().entrySet()) {
for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception.getValue().entrySet()) {
String err = entry.getValue().getMessage();
assertTrue("Unexpected error message: " + err, err.contains("Parameter 'SomeParam' is blank"));
}
}
}
// fix validation
parallelAPSPConfigProxy.setSomeParam("abc");
// failure
transaction.commit();
apspON = ObjectNameUtil.withoutTransactionName(apspNameTransactionON);
}
// test reported apsp number of threads
TestingParallelAPSPConfigMXBean parallelAPSPRuntimeProxy = configRegistryClient.newMXBeanProxy(apspON, TestingParallelAPSPConfigMXBean.class);
assertEquals((Integer) TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS, parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
// next transaction - recreate new thread pool
int newNumberOfThreads = TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS * 2;
{
// start new transaction
ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
ObjectName threadPoolNamesNewTx = transaction.lookupConfigBean(getThreadPoolImplementationName(), fixed1);
TestingFixedThreadPoolConfigMXBean fixedConfigTransactionProxy = transaction.newMXBeanProxy(threadPoolNamesNewTx, TestingFixedThreadPoolConfigMXBean.class);
fixedConfigTransactionProxy.setThreadCount(newNumberOfThreads);
transaction.commit();
}
// new reference should be copied to apsp-parallel
assertEquals((Integer) newNumberOfThreads, parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
}
Aggregations