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 org.junit.After;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.opendaylight.controller.config.api.ValidationException;
14 import org.opendaylight.controller.config.api.ValidationException.ExceptionMessageWithStackTrace;
15 import org.opendaylight.controller.config.api.jmx.ObjectNameUtil;
16 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
17 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPConfigMXBean;
18 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPImpl;
19 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPModuleFactory;
20 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPool;
21 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolConfigMXBean;
22 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory;
23 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
25 import javax.management.ObjectName;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertThat;
30 import static org.junit.Assert.assertTrue;
31 import static org.junit.Assert.fail;
32 import static org.junit.internal.matchers.StringContains.containsString;
34 public class DependentWiringTest extends AbstractParallelAPSPTest {
35 private final String fixed1 = "fixed1";
36 private final String apsp1 = "apsp-parallel";
40 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
41 new TestingFixedThreadPoolModuleFactory(),
42 new TestingParallelAPSPModuleFactory()));
46 public void tearDown() {
47 TestingFixedThreadPool.cleanUp();
51 protected String getThreadPoolImplementationName() {
52 return TestingFixedThreadPoolModuleFactory.NAME;
56 public void testDependencies() throws Exception {
59 ConfigTransactionJMXClient transaction = configRegistryClient
62 ObjectName threadPoolTransactionON = createFixed1(transaction,
63 TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
64 // create apsp-parallel
65 ObjectName apspNameTransactionON = createParallelAPSP(transaction,
66 threadPoolTransactionON);
67 TestingParallelAPSPConfigMXBean parallelAPSPConfigProxy = transaction
68 .newMXBeanProxy(apspNameTransactionON, TestingParallelAPSPConfigMXBean.class);
69 parallelAPSPConfigProxy.setSomeParam("");// trigger validation
72 transaction.validateConfig();
74 } catch (ValidationException e) {
75 for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
76 .getFailedValidations().entrySet()) {
77 for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
78 .getValue().entrySet()) {
80 entry.getValue().getMessage(),
81 containsString("Parameter 'SomeParam' is blank"));
86 // try committing (validation fails)
90 } catch (ValidationException e) {
91 for (Map.Entry<String, Map<String, ExceptionMessageWithStackTrace>> exception : e
92 .getFailedValidations().entrySet()) {
93 for (Map.Entry<String, ExceptionMessageWithStackTrace> entry : exception
94 .getValue().entrySet()) {
95 String err = entry.getValue().getMessage();
96 assertTrue("Unexpected error message: " + err,
97 err.contains("Parameter 'SomeParam' is blank"));
102 parallelAPSPConfigProxy.setSomeParam("abc");// fix validation
104 transaction.commit();
105 apspON = ObjectNameUtil
106 .withoutTransactionName(apspNameTransactionON);
109 // test reported apsp number of threads
110 TestingParallelAPSPConfigMXBean parallelAPSPRuntimeProxy = configRegistryClient
111 .newMBeanProxy(apspON, TestingParallelAPSPConfigMXBean.class);
113 (Integer) TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS,
114 parallelAPSPRuntimeProxy.getMaxNumberOfThreads());
116 // next transaction - recreate new thread pool
117 int newNumberOfThreads = TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS * 2;
119 // start new transaction
120 ConfigTransactionJMXClient transaction = configRegistryClient
121 .createTransaction();
122 ObjectName threadPoolNames_newTx = transaction.lookupConfigBean(
123 getThreadPoolImplementationName(), fixed1);
124 TestingFixedThreadPoolConfigMXBean fixedConfigTransactionProxy = transaction
125 .newMXBeanProxy(threadPoolNames_newTx, TestingFixedThreadPoolConfigMXBean.class);
126 fixedConfigTransactionProxy.setThreadCount(newNumberOfThreads);
128 transaction.commit();
130 // new reference should be copied to apsp-parallel
131 assertEquals((Integer) newNumberOfThreads,
132 parallelAPSPRuntimeProxy.getMaxNumberOfThreads());