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.Before;
11 import org.junit.Test;
12 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
13 import org.opendaylight.controller.config.api.ModuleIdentifier;
14 import org.opendaylight.controller.config.manager.impl.ClassBasedModuleFactory;
15 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
16 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPImpl;
17 import org.opendaylight.controller.config.manager.testingservices.parallelapsp.TestingParallelAPSPModuleFactory;
18 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
19 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolConfigMXBean;
20 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolIfc;
21 import org.opendaylight.controller.config.spi.Module;
22 import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
24 import javax.management.ObjectName;
25 import java.io.Closeable;
26 import java.io.IOException;
27 import java.util.concurrent.Executor;
29 public class MockedDependenciesTest extends AbstractParallelAPSPTest {
30 private final String threadPoolImplementationName = "mockedthreadpool";
35 ClassBasedModuleFactory mockedThreadPoolConfigFactory = new ClassBasedModuleFactory(
36 threadPoolImplementationName, MockedThreadPoolModule.class);
38 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,
39 new TestingParallelAPSPModuleFactory(),
40 mockedThreadPoolConfigFactory));
43 public static interface MockedTestingThreadPoolConfigMXBean extends
44 TestingThreadPoolConfigMXBean {
45 public void setThreadCount(int threadCount);
48 public static class MockedThreadPoolModule implements Module,
49 MockedTestingThreadPoolConfigMXBean,
50 TestingThreadPoolServiceInterface {
52 private final ModuleIdentifier moduleIdentifier;
56 public MockedThreadPoolModule(
57 DynamicMBeanWithInstance dynamicMBeanWithInstance, ModuleIdentifier moduleIdentifier) {
58 // no reconfiguration / reuse is supported
59 this.moduleIdentifier = moduleIdentifier;
63 public int getThreadCount() {
68 public void setThreadCount(int threadCount) {
69 this.threadCount = threadCount;
73 public void validate() {
78 public Closeable getInstance() {
79 return new MockedThreadPool(threadCount);
83 public ModuleIdentifier getIdentifier() {
84 return moduleIdentifier;
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 protected 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();