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 java.io.Closeable;
11 import java.io.IOException;
12 import java.util.concurrent.Executor;
14 import javax.management.ObjectName;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
19 import org.opendaylight.controller.config.api.ModuleIdentifier;
20 import org.opendaylight.controller.config.manager.impl.ClassBasedModuleFactory;
21 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
22 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPImpl;
23 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPModuleFactory;
24 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
25 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolConfigMXBean;
26 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolIfc;
27 import org.opendaylight.controller.config.spi.Module;
28 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
30 public class MockedDependenciesTest extends AbstractParallelAPSPTest {
31 private final String threadPoolImplementationName = "mockedthreadpool";
36 ClassBasedModuleFactory mockedThreadPoolConfigFactory = new ClassBasedModuleFactory(
37 threadPoolImplementationName, MockedThreadPoolModule.class);
39 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
40 new TestingParallelAPSPModuleFactory(),
41 mockedThreadPoolConfigFactory));
44 public static interface MockedTestingThreadPoolConfigMXBean extends
45 TestingThreadPoolConfigMXBean {
46 public void setThreadCount(int threadCount);
49 public static class MockedThreadPoolModule implements Module,
50 MockedTestingThreadPoolConfigMXBean,
51 TestingThreadPoolServiceInterface {
54 public MockedThreadPoolModule() {
57 public MockedThreadPoolModule(
58 DynamicMBeanWithInstance dynamicMBeanWithInstance) {
59 // no reconfiguration / reuse is supported
63 public ModuleIdentifier getName() {
64 return new ModuleIdentifier("a", "b");
68 public int getThreadCount() {
73 public void setThreadCount(int threadCount) {
74 this.threadCount = threadCount;
78 public void validate() {
83 public Closeable getInstance() {
84 return new MockedThreadPool(threadCount);
88 public static class MockedThreadPool implements TestingThreadPoolIfc,
90 private final int threadCount;
92 public MockedThreadPool(int threadCount) {
93 this.threadCount = threadCount;
97 public Executor getExecutor() {
102 public int getMaxNumberOfThreads() {
107 public void close() throws IOException {
113 String getThreadPoolImplementationName() {
114 return threadPoolImplementationName;
118 public void testDependencies() throws Exception {
119 ConfigTransactionJMXClient transaction = configRegistryClient
120 .createTransaction();
122 ObjectName threadPoolTransactionON = createFixed1(transaction,
123 TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
124 // create apsp-parallel
125 createParallelAPSP(transaction, threadPoolTransactionON);
127 transaction.commit();