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.manager.testingservices.parallelapsp.test;
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertThat;
13 import static org.junit.Assert.assertTrue;
14 import static org.junit.Assert.fail;
18 import javax.management.ObjectName;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.controller.config.api.ValidationException;
24 import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace;
25 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
26 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
27 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPConfigMXBean;
28 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPImpl;
29 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPModuleFactory;
30 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
31 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPool;
32 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean;
33 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory;
34 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
36 public class DependentWiringTest extends AbstractParallelAPSPTest {
37 private final String fixed1 = "fixed1";
38 private final String apsp1 = "apsp-parallel";
42 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,
43 new TestingFixedThreadPoolModuleFactory(),
44 new TestingParallelAPSPModuleFactory()));
48 public void tearDown() {
49 TestingFixedThreadPool.cleanUp();
53 protected String getThreadPoolImplementationName() {
54 return TestingFixedThreadPoolModuleFactory.NAME;
58 public void testDependencies() throws Exception {
61 ConfigTransactionJMXClient transaction = configRegistryClient
64 ObjectName threadPoolTransactionON = createFixed1(transaction,
65 TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
66 // create apsp-parallel
67 ObjectName apspNameTransactionON = createParallelAPSP(transaction,
68 threadPoolTransactionON);
69 TestingParallelAPSPConfigMXBean parallelAPSPConfigProxy = transaction
70 .newMXBeanProxy(apspNameTransactionON, TestingParallelAPSPConfigMXBean.class);
71 parallelAPSPConfigProxy.setSomeParam("");// trigger validation
74 transaction.validateConfig();
76 } catch (ValidationException e) {
77 for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
78 .getFailedValidations().entrySet()) {
79 for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
80 .getValue().entrySet()) {
82 entry.getValue().getMessage(),
83 containsString("Parameter 'SomeParam' is blank"));
88 // try committing (validation fails)
92 } catch (ValidationException e) {
93 for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
94 .getFailedValidations().entrySet()) {
95 for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
96 .getValue().entrySet()) {
97 String err = entry.getValue().getMessage();
98 assertTrue("Unexpected error message: " + err,
99 err.contains("Parameter 'SomeParam' is blank"));
104 parallelAPSPConfigProxy.setSomeParam("abc");// fix validation
106 transaction.commit();
107 apspON = ObjectNameUtil
108 .withoutTransactionName(apspNameTransactionON);
111 // test reported apsp number of threads
112 TestingParallelAPSPConfigMXBean parallelAPSPRuntimeProxy = configRegistryClient
113 .newMBeanProxy(apspON, TestingParallelAPSPConfigMXBean.class);
115 (Integer) TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS,
116 parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
118 // next transaction - recreate new thread pool
119 int newNumberOfThreads = TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS * 2;
121 // start new transaction
122 ConfigTransactionJMXClient transaction = configRegistryClient
123 .createTransaction();
124 ObjectName threadPoolNames_newTx = transaction.lookupConfigBean(
125 getThreadPoolImplementationName(), fixed1);
126 TestingFixedThreadPoolConfigMXBean fixedConfigTransactionProxy = transaction
127 .newMXBeanProxy(threadPoolNames_newTx, TestingFixedThreadPoolConfigMXBean.class);
128 fixedConfigTransactionProxy.setThreadCount(newNumberOfThreads);
130 transaction.commit();
132 // new reference should be copied to apsp-parallel
133 assertEquals((Integer) newNumberOfThreads,
134 parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
139 public void testUsingServiceReferences() throws Exception {
140 ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
141 ObjectName threadPoolON = createFixed1(transaction, 10);
142 transaction.lookupConfigBean(getThreadPoolImplementationName(), fixed1);
143 String refName = "ref";
144 ObjectName serviceReferenceON = transaction.saveServiceReference(TestingThreadPoolServiceInterface.QNAME, refName,
146 createParallelAPSP(transaction, serviceReferenceON);
147 transaction.commit();