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 interface MockedTestingThreadPoolConfigMXBean extends
43 TestingThreadPoolConfigMXBean {
44 void setThreadCount(int threadCount);
47 public static class MockedThreadPoolModule implements Module,
48 MockedTestingThreadPoolConfigMXBean,
49 TestingThreadPoolServiceInterface {
51 private final ModuleIdentifier moduleIdentifier;
55 public MockedThreadPoolModule(
56 final DynamicMBeanWithInstance dynamicMBeanWithInstance, final ModuleIdentifier moduleIdentifier) {
57 // no reconfiguration / reuse is supported
58 this.moduleIdentifier = moduleIdentifier;
62 public int getThreadCount() {
67 public void setThreadCount(final int threadCount) {
68 this.threadCount = threadCount;
72 public void validate() {
77 public boolean canReuse(final Module oldModule) {
82 public Closeable getInstance() {
83 return new MockedThreadPool(threadCount);
87 public ModuleIdentifier getIdentifier() {
88 return moduleIdentifier;
92 public static class MockedThreadPool implements TestingThreadPoolIfc,
94 private final int threadCount;
96 public MockedThreadPool(final int threadCount) {
97 this.threadCount = threadCount;
101 public Executor getExecutor() {
106 public int getMaxNumberOfThreads() {
111 public void close() throws IOException {
117 protected String getThreadPoolImplementationName() {
118 return threadPoolImplementationName;
122 public void testDependencies() throws Exception {
123 ConfigTransactionJMXClient transaction = configRegistryClient
124 .createTransaction();
126 ObjectName threadPoolTransactionON = createFixed1(transaction,
127 TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
128 // create apsp-parallel
129 createParallelAPSP(transaction, threadPoolTransactionON);
131 transaction.commit();