2 * Copyright (c) 2013, 2017 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;
17 import javax.management.ObjectName;
18 import org.junit.After;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.controller.config.api.ValidationException;
22 import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace;
23 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
24 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
25 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPConfigMXBean;
26 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPImpl;
27 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPModuleFactory;
28 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
29 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPool;
30 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean;
31 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory;
32 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
34 public class DependentWiringTest extends AbstractParallelAPSPTest {
35 private final String fixed1 = "fixed1";
39 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,
40 new TestingFixedThreadPoolModuleFactory(), 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.createTransaction();
59 ObjectName threadPoolTransactionON = createFixed1(transaction,
60 TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
61 // create apsp-parallel
62 ObjectName apspNameTransactionON = createParallelAPSP(transaction, threadPoolTransactionON);
63 TestingParallelAPSPConfigMXBean parallelAPSPConfigProxy = transaction.newMXBeanProxy(apspNameTransactionON,
64 TestingParallelAPSPConfigMXBean.class);
65 parallelAPSPConfigProxy.setSomeParam("");// trigger validation
68 transaction.validateConfig();
70 } catch (final ValidationException e) {
71 for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e.getFailedValidations()
73 for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception.getValue().entrySet()) {
74 assertThat(entry.getValue().getMessage(), containsString("Parameter 'SomeParam' is blank"));
79 // try committing (validation fails)
83 } catch (final ValidationException e) {
84 for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e.getFailedValidations()
86 for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception.getValue().entrySet()) {
87 String err = entry.getValue().getMessage();
88 assertTrue("Unexpected error message: " + err, err.contains("Parameter 'SomeParam' is blank"));
93 parallelAPSPConfigProxy.setSomeParam("abc");// fix validation
96 apspON = ObjectNameUtil.withoutTransactionName(apspNameTransactionON);
99 // test reported apsp number of threads
100 TestingParallelAPSPConfigMXBean parallelAPSPRuntimeProxy = configRegistryClient.newMXBeanProxy(apspON,
101 TestingParallelAPSPConfigMXBean.class);
102 assertEquals((Integer) TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS,
103 parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
105 // next transaction - recreate new thread pool
106 int newNumberOfThreads = TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS * 2;
108 // start new transaction
109 ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
110 ObjectName threadPoolNamesNewTx =
111 transaction.lookupConfigBean(getThreadPoolImplementationName(), fixed1);
112 TestingFixedThreadPoolConfigMXBean fixedConfigTransactionProxy = transaction
113 .newMXBeanProxy(threadPoolNamesNewTx, TestingFixedThreadPoolConfigMXBean.class);
114 fixedConfigTransactionProxy.setThreadCount(newNumberOfThreads);
116 transaction.commit();
118 // new reference should be copied to apsp-parallel
119 assertEquals((Integer) newNumberOfThreads, parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
123 public void testUsingServiceReferences() throws Exception {
124 ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
125 ObjectName threadPoolON = createFixed1(transaction, 10);
126 transaction.lookupConfigBean(getThreadPoolImplementationName(), fixed1);
127 String refName = "ref";
128 ObjectName serviceReferenceON = transaction.saveServiceReference(TestingThreadPoolServiceInterface.QNAME,
129 refName, threadPoolON);
130 createParallelAPSP(transaction, serviceReferenceON);
131 transaction.commit();