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());
}
Aggregations