Search in sources :

Example 11 with ConfigTransactionJMXClient

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

the class AbstractConfigTest method destroyAllConfigBeans.

/**
 * Can be called in @After of tests if some other cleanup is needed that would
 * be discarded by closing config beans in this method.
 */
protected void destroyAllConfigBeans() throws Exception {
    final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
    Set<ObjectName> all = transaction.lookupConfigBeans();
    // workaround for getting same Module more times
    while (all.size() > 0) {
        transaction.destroyModule(all.iterator().next());
        all = transaction.lookupConfigBeans();
    }
    transaction.commit();
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) ObjectName(javax.management.ObjectName)

Example 12 with ConfigTransactionJMXClient

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

the class ConfigTransactionManagerImplTest method testRemoteCallsUsingJMX.

@Test
public void testRemoteCallsUsingJMX() throws Exception {
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    transaction.commit();
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) Test(org.junit.Test)

Example 13 with ConfigTransactionJMXClient

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

the class ServiceReferenceRegistryImplTest method test.

@Test
public void test() throws Exception {
    ConfigTransactionJMXClient transaction1 = configRegistryClient.createTransaction();
    // create fixed1
    int fixedNrOfThreads = 20;
    int scheduledNrOfThreads = 30;
    ObjectName fixedTPTransactionON = transaction1.createModule(getThreadPoolImplementationName(), fixed1);
    platformMBeanServer.setAttribute(fixedTPTransactionON, new Attribute("ThreadCount", fixedNrOfThreads));
    ObjectName scheduledTPTransactionON = transaction1.createModule(TestingScheduledThreadPoolModuleFactory.NAME, "scheduled1");
    platformMBeanServer.setAttribute(scheduledTPTransactionON, new Attribute("ThreadCount", scheduledNrOfThreads));
    String refName = "ref";
    ObjectName serviceReference = transaction1.saveServiceReference(TestingThreadPoolServiceInterface.QNAME, refName, fixedTPTransactionON);
    // create apsp-parallel
    createParallelAPSP(transaction1, serviceReference);
    transaction1.commit();
    // check fixed1 is used
    ServiceReferenceMXBean serviceReferenceMXBean = JMX.newMXBeanProxy(platformMBeanServer, withoutTransactionName(serviceReference), ServiceReferenceMXBean.class);
    assertEquals(withoutTransactionName(fixedTPTransactionON), serviceReferenceMXBean.getCurrentImplementation());
    checkApspThreadCount(fixedNrOfThreads);
    // check OSGi SR
    List<RegistrationHolder> registrations = ((RecordingBundleContextServiceRegistrationHandler) currentBundleContextServiceRegistrationHandler).getRegistrations();
    assertEquals(1, registrations.size());
    RegistrationHolder record = registrations.get(0);
    assertEquals(TestingThreadPoolIfc.class, record.clazz);
    assertEquals(ImmutableMap.of("name", "ref"), record.props);
    // switch reference to scheduled
    ConfigTransactionJMXClient transaction2 = configRegistryClient.createTransaction();
    transaction2.saveServiceReference(TestingThreadPoolServiceInterface.QNAME, refName, ObjectNameUtil.withTransactionName(scheduledTPTransactionON, transaction2.getTransactionName()));
    transaction2.commit();
    // check scheduled is used
    checkApspThreadCount(scheduledNrOfThreads);
    // check that dummy MXBean points to scheduled
    assertEquals(withoutTransactionName(scheduledTPTransactionON), serviceReferenceMXBean.getCurrentImplementation());
    // empty transaction
    configRegistryClient.createTransaction().commit();
    // get service mapping
    Map<String, Map<String, ObjectName>> serviceMapping = configRegistryClient.getServiceMapping();
    Map<String, Map<String, ObjectName>> expectedMapping = ImmutableMap.of(TestingThreadPoolServiceInterface.QNAME, (Map<String, ObjectName>) ImmutableMap.of(refName, withoutTransactionName(scheduledTPTransactionON)));
    assertEquals(expectedMapping, serviceMapping);
    // destroy all
    ConfigTransactionJMXClient transaction4 = configRegistryClient.createTransaction();
    Set<ObjectName> objectNames = transaction4.lookupConfigBeans();
    for (ObjectName on : objectNames) {
        transaction4.destroyModule(on);
    }
    transaction4.commit();
    serviceMapping = configRegistryClient.getServiceMapping();
    assertTrue(serviceMapping.isEmpty());
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) RegistrationHolder(org.opendaylight.controller.config.manager.impl.AbstractConfigTest.RecordingBundleContextServiceRegistrationHandler.RegistrationHolder) Attribute(javax.management.Attribute) ServiceReferenceMXBean(org.opendaylight.controller.config.api.jmx.ServiceReferenceMXBean) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectName(javax.management.ObjectName) Test(org.junit.Test) AbstractParallelAPSPTest(org.opendaylight.controller.config.manager.testingservices.parallelapsp.test.AbstractParallelAPSPTest)

Example 14 with ConfigTransactionJMXClient

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

the class SimpleConfigurationTest method test_createThreadPool_changeNumberOfThreads.

@Test
public void test_createThreadPool_changeNumberOfThreads() throws Exception {
    firstCommit();
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    TestingFixedThreadPoolConfigMXBean fixedConfigProxy = startReconfiguringFixed1ThreadPool(transaction);
    assertEquals(NUMBER_OF_THREADS, fixedConfigProxy.getThreadCount());
    fixedConfigProxy.setThreadCount(NUMBER_OF_THREADS2);
    CommitStatus commitStatus = transaction.commit();
    checkThreadPools(1, NUMBER_OF_THREADS2);
    CommitStatus expected = new CommitStatus(EMPTYO_NS, FIXED1_LIST, EMPTYO_NS);
    assertEquals(expected, commitStatus);
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) TestingFixedThreadPoolConfigMXBean(org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean) CommitStatus(org.opendaylight.controller.config.api.jmx.CommitStatus) AbstractConfigTest(org.opendaylight.controller.config.manager.impl.AbstractConfigTest) Test(org.junit.Test)

Example 15 with ConfigTransactionJMXClient

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

the class SimpleConfigurationTest method test_createFixedThreadPool_destroyIt.

@Test
public void test_createFixedThreadPool_destroyIt() throws Exception {
    // 1, start transaction, create new fixed thread pool
    ObjectName fixed1name = firstCommit();
    // 2, check that configuration was copied to platform
    ObjectName on = ObjectNameUtil.withoutTransactionName(fixed1name);
    platformMBeanServer.getMBeanInfo(on);
    assertEquals(NUMBER_OF_THREADS, platformMBeanServer.getAttribute(on, "ThreadCount"));
    // 3, shutdown fixed1 in new transaction
    assertFalse(TestingFixedThreadPool.ALL_EXECUTORS.get(0).isShutdown());
    ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
    // check versions
    transaction.assertVersion(1, 2);
    // test that it was copied to new transaction
    ObjectName retrievedName = transaction.lookupConfigBean(TestingFixedThreadPoolModuleFactory.NAME, FIXED1);
    assertNotNull(retrievedName);
    // check that number of threads was copied from dynamic
    TestingFixedThreadPoolConfigMXBean fixedConfigProxy = transaction.newMXBeanProxy(retrievedName, TestingFixedThreadPoolConfigMXBean.class);
    assertEquals(NUMBER_OF_THREADS, fixedConfigProxy.getThreadCount());
    // destroy
    transaction.destroyModule(ObjectNameUtil.createTransactionModuleON(transaction.getTransactionName(), TestingFixedThreadPoolModuleFactory.NAME, FIXED1));
    transaction.commit();
    // 4, check
    assertEquals(2, configRegistryClient.getVersion());
    assertEquals(0, TestingFixedThreadPool.ALL_EXECUTORS.size());
    // dynamic config should be removed from platform
    try {
        platformMBeanServer.getMBeanInfo(on);
        fail();
    } catch (final ReflectionException | InstanceNotFoundException | IntrospectionException e) {
        assertTrue(e instanceof InstanceNotFoundException);
    }
}
Also used : ConfigTransactionJMXClient(org.opendaylight.controller.config.util.ConfigTransactionJMXClient) ReflectionException(javax.management.ReflectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) TestingFixedThreadPoolConfigMXBean(org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean) IntrospectionException(javax.management.IntrospectionException) ObjectName(javax.management.ObjectName) 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