Search in sources :

Example 1 with RegistrationHolder

use of org.opendaylight.controller.config.manager.impl.AbstractConfigTest.RecordingBundleContextServiceRegistrationHandler.RegistrationHolder 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)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 Attribute (javax.management.Attribute)1 ObjectName (javax.management.ObjectName)1 Test (org.junit.Test)1 ServiceReferenceMXBean (org.opendaylight.controller.config.api.jmx.ServiceReferenceMXBean)1 RegistrationHolder (org.opendaylight.controller.config.manager.impl.AbstractConfigTest.RecordingBundleContextServiceRegistrationHandler.RegistrationHolder)1 AbstractParallelAPSPTest (org.opendaylight.controller.config.manager.testingservices.parallelapsp.test.AbstractParallelAPSPTest)1 ConfigTransactionJMXClient (org.opendaylight.controller.config.util.ConfigTransactionJMXClient)1