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;
13 import javax.management.ObjectName;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
17 import org.opendaylight.controller.config.api.ModuleIdentifier;
18 import org.opendaylight.controller.config.manager.impl.ClassBasedModuleFactory;
19 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
20 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPImpl;
21 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPModuleFactory;
22 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
23 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolConfigMXBean;
24 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolIfc;
25 import org.opendaylight.controller.config.spi.Module;
26 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
28 public class MockedDependenciesTest extends AbstractParallelAPSPTest {
29 private final String threadPoolImplementationName = "mockedthreadpool";
34 ClassBasedModuleFactory mockedThreadPoolConfigFactory = new ClassBasedModuleFactory(
35 threadPoolImplementationName, MockedThreadPoolModule.class);
37 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,
38 new TestingParallelAPSPModuleFactory(),
39 mockedThreadPoolConfigFactory));
42 public static interface MockedTestingThreadPoolConfigMXBean extends
43 TestingThreadPoolConfigMXBean {
44 public void setThreadCount(int threadCount);
47 public static class MockedThreadPoolModule implements Module,
48 MockedTestingThreadPoolConfigMXBean,
49 TestingThreadPoolServiceInterface {
51 private final ModuleIdentifier moduleIdentifier;
55 public MockedThreadPoolModule(
56 DynamicMBeanWithInstance dynamicMBeanWithInstance, ModuleIdentifier moduleIdentifier) {
57 // no reconfiguration / reuse is supported
58 this.moduleIdentifier = moduleIdentifier;
62 public int getThreadCount() {
67 public void setThreadCount(int threadCount) {
68 this.threadCount = threadCount;
72 public void validate() {
77 public Closeable getInstance() {
78 return new MockedThreadPool(threadCount);
82 public ModuleIdentifier getIdentifier() {
83 return moduleIdentifier;
87 public static class MockedThreadPool implements TestingThreadPoolIfc,
89 private final int threadCount;
91 public MockedThreadPool(int threadCount) {
92 this.threadCount = threadCount;
96 public Executor getExecutor() {
101 public int getMaxNumberOfThreads() {
106 public void close() throws IOException {
112 protected String getThreadPoolImplementationName() {
113 return threadPoolImplementationName;
117 public void testDependencies() throws Exception {
118 ConfigTransactionJMXClient transaction = configRegistryClient
119 .createTransaction();
121 ObjectName threadPoolTransactionON = createFixed1(transaction,
122 TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
123 // create apsp-parallel
124 createParallelAPSP(transaction, threadPoolTransactionON);
126 transaction.commit();