2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.config.yang.pcep.impl;
10 import static org.junit.Assert.assertTrue;
11 import static org.junit.Assert.fail;
13 import javax.management.InstanceAlreadyExistsException;
14 import javax.management.ObjectName;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.controller.config.api.ValidationException;
18 import org.opendaylight.controller.config.api.jmx.CommitStatus;
19 import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
20 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
21 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
22 import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleFactory;
23 import org.opendaylight.controller.config.yang.netty.threadgroup.NettyThreadgroupModuleMXBean;
24 import org.opendaylight.controller.config.yang.pcep.spi.SimplePCEPExtensionProviderContextModuleFactory;
25 import org.opendaylight.controller.config.yang.pcep.spi.SimplePCEPExtensionProviderContextModuleMXBean;
27 public class PCEPDispatcherImplModuleTest extends AbstractConfigTest {
29 private static final String INSTANCE_NAME = "pcep-dispatcher-impl";
30 private static final String FACTORY_NAME = PCEPDispatcherImplModuleFactory.NAME;
32 private static final String THREADGROUP_FACTORY_NAME = NettyThreadgroupModuleFactory.NAME;
33 private static final String BOSS_TG_INSTANCE_NAME = "boss-group";
34 private static final String WORKER_TG_INSTANCE_NAME = "worker-group";
36 private static final String EXTENSION_INSTANCE_NAME = "pcep-extension-privider";
37 private static final String EXTENSION_FACTORYNAME = SimplePCEPExtensionProviderContextModuleFactory.NAME;
40 public void setUp() throws Exception {
41 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(this.mockedContext, new PCEPDispatcherImplModuleFactory(), new PCEPSessionProposalFactoryImplModuleFactory(), new NettyThreadgroupModuleFactory(), new SimplePCEPExtensionProviderContextModuleFactory()));
45 public void testValidationExceptionMaxUnknownMessagesNotSet() throws Exception {
47 createDispatcherInstance(null);
49 } catch (final ValidationException e) {
50 assertTrue(e.getMessage().contains("MaxUnknownMessages value is not set"));
55 public void testValidationExceptionMaxUnknownMessagesMinValue() throws Exception {
57 createDispatcherInstance(0);
59 } catch (final ValidationException e) {
60 assertTrue(e.getMessage().contains("must be greater than 0"));
65 public void testCreateBean() throws Exception {
66 final CommitStatus status = createDispatcherInstance(5);
67 assertBeanCount(1, FACTORY_NAME);
68 assertStatus(status, 5, 0, 0);
72 public void testReusingOldInstance() throws Exception {
73 createDispatcherInstance(5);
74 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
75 assertBeanCount(1, FACTORY_NAME);
76 final CommitStatus status = transaction.commit();
77 assertBeanCount(1, FACTORY_NAME);
78 assertStatus(status, 0, 0, 5);
82 public void testReconfigure() throws Exception {
83 createDispatcherInstance(5);
84 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
85 assertBeanCount(1, FACTORY_NAME);
86 final PCEPDispatcherImplModuleMXBean mxBean = transaction.newMXBeanProxy(transaction.lookupConfigBean(FACTORY_NAME, INSTANCE_NAME),
87 PCEPDispatcherImplModuleMXBean.class);
88 mxBean.setMaxUnknownMessages(10);
89 final CommitStatus status = transaction.commit();
90 assertBeanCount(1, FACTORY_NAME);
91 assertStatus(status, 0, 1, 4);
94 private CommitStatus createDispatcherInstance(final Integer maxUnknownMessages) throws Exception {
95 final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction();
96 createDispatcherInstance(transaction, maxUnknownMessages);
97 return transaction.commit();
100 public static ObjectName createDispatcherInstance(final ConfigTransactionJMXClient transaction, final Integer maxUnknownMessages)
102 final ObjectName nameCreated = transaction.createModule(FACTORY_NAME, INSTANCE_NAME);
103 final PCEPDispatcherImplModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, PCEPDispatcherImplModuleMXBean.class);
104 mxBean.setPcepSessionProposalFactory(PCEPSessionProposalFactoryImplModuleTest.createSessionInstance(transaction));
105 mxBean.setMaxUnknownMessages(maxUnknownMessages);
106 mxBean.setBossGroup(createThreadGroupInstance(transaction, 10, BOSS_TG_INSTANCE_NAME));
107 mxBean.setWorkerGroup(createThreadGroupInstance(transaction, 10, WORKER_TG_INSTANCE_NAME));
108 mxBean.setPcepExtensions(createExtensionsInstance(transaction));
112 private static ObjectName createExtensionsInstance(final ConfigTransactionJMXClient transaction) throws InstanceAlreadyExistsException {
113 final ObjectName nameCreated = transaction.createModule(EXTENSION_FACTORYNAME, EXTENSION_INSTANCE_NAME);
114 transaction.newMXBeanProxy(nameCreated, SimplePCEPExtensionProviderContextModuleMXBean.class);
119 private static ObjectName createThreadGroupInstance(final ConfigTransactionJMXClient transaction, final Integer threadCount,
120 final String instanceName) throws InstanceAlreadyExistsException {
121 final ObjectName nameCreated = transaction.createModule(THREADGROUP_FACTORY_NAME, instanceName);
122 final NettyThreadgroupModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, NettyThreadgroupModuleMXBean.class);
123 mxBean.setThreadCount(threadCount);