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;
16 import javax.management.ObjectName;
17 import org.junit.After;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.controller.config.api.ValidationException;
21 import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace;
22 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
23 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
24 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPConfigMXBean;
25 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPImpl;
26 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPModuleFactory;
27 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
28 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPool;
29 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean;
30 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory;
31 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
33 public class DependentWiringTest extends AbstractParallelAPSPTest {
34 private final String fixed1 = "fixed1";
38 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,
39 new TestingFixedThreadPoolModuleFactory(),
40 new TestingParallelAPSPModuleFactory()));
44 public void tearDown() {
45 TestingFixedThreadPool.cleanUp();
49 protected String getThreadPoolImplementationName() {
50 return TestingFixedThreadPoolModuleFactory.NAME;
54 public void testDependencies() throws Exception {
57 ConfigTransactionJMXClient transaction = configRegistryClient
60 ObjectName threadPoolTransactionON = createFixed1(transaction,
61 TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
62 // create apsp-parallel
63 ObjectName apspNameTransactionON = createParallelAPSP(transaction,
64 threadPoolTransactionON);
65 TestingParallelAPSPConfigMXBean parallelAPSPConfigProxy = transaction
66 .newMXBeanProxy(apspNameTransactionON, TestingParallelAPSPConfigMXBean.class);
67 parallelAPSPConfigProxy.setSomeParam("");// trigger validation
70 transaction.validateConfig();
72 } catch (ValidationException e) {
73 for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
74 .getFailedValidations().entrySet()) {
75 for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
76 .getValue().entrySet()) {
78 entry.getValue().getMessage(),
79 containsString("Parameter 'SomeParam' is blank"));
84 // try committing (validation fails)
88 } catch (ValidationException e) {
89 for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
90 .getFailedValidations().entrySet()) {
91 for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
92 .getValue().entrySet()) {
93 String err = entry.getValue().getMessage();
94 assertTrue("Unexpected error message: " + err,
95 err.contains("Parameter 'SomeParam' is blank"));
100 parallelAPSPConfigProxy.setSomeParam("abc");// fix validation
102 transaction.commit();
103 apspON = ObjectNameUtil
104 .withoutTransactionName(apspNameTransactionON);
107 // test reported apsp number of threads
108 TestingParallelAPSPConfigMXBean parallelAPSPRuntimeProxy = configRegistryClient
109 .newMXBeanProxy(apspON, TestingParallelAPSPConfigMXBean.class);
111 (Integer) TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS,
112 parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
114 // next transaction - recreate new thread pool
115 int newNumberOfThreads = TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS * 2;
117 // start new transaction
118 ConfigTransactionJMXClient transaction = configRegistryClient
119 .createTransaction();
120 ObjectName threadPoolNames_newTx = transaction.lookupConfigBean(
121 getThreadPoolImplementationName(), fixed1);
122 TestingFixedThreadPoolConfigMXBean fixedConfigTransactionProxy = transaction
123 .newMXBeanProxy(threadPoolNames_newTx, TestingFixedThreadPoolConfigMXBean.class);
124 fixedConfigTransactionProxy.setThreadCount(newNumberOfThreads);
126 transaction.commit();
128 // new reference should be copied to apsp-parallel
129 assertEquals((Integer) newNumberOfThreads,
130 parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
135 public void testUsingServiceReferences() throws Exception {
136 ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
137 ObjectName threadPoolON = createFixed1(transaction, 10);
138 transaction.lookupConfigBean(getThreadPoolImplementationName(), fixed1);
139 String refName = "ref";
140 ObjectName serviceReferenceON = transaction.saveServiceReference(TestingThreadPoolServiceInterface.QNAME, refName,
142 createParallelAPSP(transaction, serviceReferenceON);
143 transaction.commit();