1 package org.opendaylight.controller.config.yang.config.netconf.client.dispatcher;
3 import javax.management.InstanceAlreadyExistsException;
4 import javax.management.InstanceNotFoundException;
5 import javax.management.ObjectName;
6 import org.junit.Before;
8 import org.opendaylight.controller.config.api.ConflictingVersionException;
9 import org.opendaylight.controller.config.api.ValidationException;
10 import org.opendaylight.controller.config.api.jmx.CommitStatus;
11 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
12 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
13 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
14 import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleFactory;
15 import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleMXBean;
16 import org.opendaylight.controller.config.yang.netty.timer.HashedWheelTimerModuleFactory;
18 public class NetconfClientDispatcherModuleTest extends AbstractConfigTest{
20 private NetconfClientDispatcherModuleFactory factory;
21 private final String instanceName = "dispatch";
25 factory = new NetconfClientDispatcherModuleFactory();
26 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,factory,
27 new NettyThreadgroupModuleFactory(),
28 new HashedWheelTimerModuleFactory()));
32 public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException {
33 ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
35 createInstance(transaction, instanceName, "timer", "thGroup");
36 createInstance(transaction, instanceName + 2, "timer2", "thGroup2");
37 transaction.validateConfig();
38 CommitStatus status = transaction.commit();
40 assertBeanCount(2, factory.getImplementationName());
41 assertStatus(status, 2 + 4, 0, 0);
45 public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException, ValidationException {
47 ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
48 createInstance(transaction, instanceName, "timer", "thGroup");
52 transaction = configRegistryClient.createTransaction();
53 assertBeanCount(1, factory.getImplementationName());
54 CommitStatus status = transaction.commit();
56 assertBeanCount(1, factory.getImplementationName());
57 assertStatus(status, 0, 0, 3);
61 public void testReconfigure() throws InstanceAlreadyExistsException, ConflictingVersionException,
62 ValidationException, InstanceNotFoundException {
64 ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
65 createInstance(transaction, instanceName, "timer", "thGroup");
69 transaction = configRegistryClient.createTransaction();
70 assertBeanCount(1, factory.getImplementationName());
71 NetconfClientDispatcherModuleMXBean mxBean = transaction.newMBeanProxy(
72 transaction.lookupConfigBean(NetconfClientDispatcherModuleFactory.NAME, instanceName),
73 NetconfClientDispatcherModuleMXBean.class);
74 mxBean.setBossThreadGroup(getThreadGroup(transaction, "group2"));
75 CommitStatus status = transaction.commit();
77 assertBeanCount(1, factory.getImplementationName());
78 assertStatus(status, 1, 1, 2);
81 private ObjectName createInstance(ConfigTransactionJMXClient transaction, String instanceName, String timerName, String threadGroupName)
82 throws InstanceAlreadyExistsException {
83 ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);
84 NetconfClientDispatcherModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated, NetconfClientDispatcherModuleMXBean.class);
85 ObjectName thGroup = getThreadGroup(transaction, threadGroupName);
86 mxBean.setBossThreadGroup(thGroup);
87 mxBean.setWorkerThreadGroup(thGroup);
88 mxBean.setTimer(getTimer(transaction, timerName));
92 private ObjectName getTimer(ConfigTransactionJMXClient transaction, String name) throws InstanceAlreadyExistsException {
93 return transaction.createModule(HashedWheelTimerModuleFactory.NAME, name);
96 private ObjectName getThreadGroup(ConfigTransactionJMXClient transaction, String name) throws InstanceAlreadyExistsException {
97 ObjectName nameCreated = transaction.createModule(NettyThreadgroupModuleFactory.NAME, name);
98 NettyThreadgroupModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, NettyThreadgroupModuleMXBean.class);
99 mxBean.setThreadCount(1);