Search in sources :

Example 36 with ConfigTransactionJMXClient

use of org.opendaylight.controller.config.util.ConfigTransactionJMXClient in project controller by opendaylight.

the class TwoInterfacesExportTest method testRegisteringAllIfcNames.

// --
@Test
public void testRegisteringAllIfcNames() throws Exception {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    transaction.createModule(TestingScheduledThreadPoolModuleFactory.NAME, SCHEDULED1);
    transaction.commit();
    assertExists(TestingScheduledThreadPoolModuleFactory.NAME, SCHEDULED1);
    // another transaction
    transaction = configRegistryClient.createTransaction();
    assertExists(transaction, TestingScheduledThreadPoolModuleFactory.NAME, SCHEDULED1);
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) Test(org.junit.Test)

Example 37 with ConfigTransactionJMXClient

use of org.opendaylight.controller.config.util.ConfigTransactionJMXClient in project controller by opendaylight.

the class TwoInterfacesExportTest method tryToRegisterThreadPoolWithSameName.

@Test
public void tryToRegisterThreadPoolWithSameName() throws InstanceAlreadyExistsException {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    transaction.createModule(TestingScheduledThreadPoolModuleFactory.NAME, SCHEDULED1);
    try {
        transaction.createModule(TestingScheduledThreadPoolModuleFactory.NAME, SCHEDULED1);
        fail();
    } catch (final InstanceAlreadyExistsException e) {
        assertThat(e.getMessage(), containsString("There is an instance registered with name " + "ModuleIdentifier{factoryName='scheduled', instanceName='scheduled1'}"));
    }
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) Test(org.junit.Test)

Example 38 with ConfigTransactionJMXClient

use of org.opendaylight.controller.config.util.ConfigTransactionJMXClient 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)

Example 39 with ConfigTransactionJMXClient

use of org.opendaylight.controller.config.util.ConfigTransactionJMXClient in project controller by opendaylight.

the class MockedDependenciesTest method testDependencies.

@Test
public void testDependencies() throws Exception {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    // create fixed1
    ObjectName threadPoolTransactionON = createFixed1(transaction, TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
    // create apsp-parallel
    createParallelAPSP(transaction, threadPoolTransactionON);
    transaction.commit();
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 40 with ConfigTransactionJMXClient

use of org.opendaylight.controller.config.util.ConfigTransactionJMXClient in project controller by opendaylight.

the class SimpleConfigurationTest method testOptimisticLock_ConfigRegistry.

@Test
public void testOptimisticLock_ConfigRegistry() throws Exception {
    ConfigTransactionJMXClient transaction1 = configRegistryClient.createTransaction();
    ConfigTransactionJMXClient transaction2 = configRegistryClient.createTransaction();
    transaction2.assertVersion(0, 2);
    transaction2.commit();
    try {
        configRegistryClient.commitConfig(transaction1.getObjectName());
        fail();
    } catch (final ConflictingVersionException e) {
        assertEquals("Optimistic lock failed. Expected parent version 2, was 0", e.getMessage());
    }
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) ConflictingVersionException(org.opendaylight.controller.config.api.ConflictingVersionException) AbstractConfigTest(org.opendaylight.controller.config.manager.impl.AbstractConfigTest) Test(org.junit.Test)

Aggregations

ConfigTransactionJMXClient (org.opendaylight.controller.config.util.ConfigTransactionJMXClient)43 Test (org.junit.Test)38 AbstractConfigTest (org.opendaylight.controller.config.manager.impl.AbstractConfigTest)26 ObjectName (javax.management.ObjectName)22 CommitStatus (org.opendaylight.controller.config.api.jmx.CommitStatus)15 TestingFixedThreadPoolConfigMXBean (org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 TestingParallelAPSPConfigMXBean (org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPConfigMXBean)3 Map (java.util.Map)2 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)2 ValidationException (org.opendaylight.controller.config.api.ValidationException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Attribute (javax.management.Attribute)1 IntrospectionException (javax.management.IntrospectionException)1 ReflectionException (javax.management.ReflectionException)1 Before (org.junit.Before)1 IdentityAttributeRef (org.opendaylight.controller.config.api.IdentityAttributeRef)1 ExceptionMessageWithStackTrace (org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace)1