Search in sources :

Example 1 with ExceptionMessageWithStackTrace

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());
            }
        }
    }
}
Also used : ExceptionMessageWithStackTrace(org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace) ValidationException(org.opendaylight.controller.config.api.ValidationException) MBeanException(javax.management.MBeanException) IntrospectionException(javax.management.IntrospectionException) ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) ValidationException(org.opendaylight.controller.config.api.ValidationException) MBeanException(javax.management.MBeanException) ObjectName(javax.management.ObjectName)

Example 2 with ExceptionMessageWithStackTrace

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());
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) ExceptionMessageWithStackTrace(org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace) ValidationException(org.opendaylight.controller.config.api.ValidationException) TestingFixedThreadPoolConfigMXBean(org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) ObjectName(javax.management.ObjectName) TestingParallelAPSPConfigMXBean(org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPConfigMXBean) Test(org.junit.Test)

Aggregations

ObjectName (javax.management.ObjectName)2 ValidationException (org.opendaylight.controller.config.api.ValidationException)2 ExceptionMessageWithStackTrace (org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace)2 Map (java.util.Map)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 IntrospectionException (javax.management.IntrospectionException)1 MBeanException (javax.management.MBeanException)1 ReflectionException (javax.management.ReflectionException)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)1 TestingParallelAPSPConfigMXBean (org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPConfigMXBean)1 TestingFixedThreadPoolConfigMXBean (org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean)1 ConfigTransactionJMXClient (org.opendaylight.controller.config.util.ConfigTransactionJMXClient)1