Merge "Remove unnecessary declaration of <prerequisites> in commons.parent"
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / testingservices / parallelapsp / test / MockedDependenciesTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.manager.testingservices.parallelapsp.test;
9
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;
27
28 public class MockedDependenciesTest extends AbstractParallelAPSPTest {
29     private final String threadPoolImplementationName = "mockedthreadpool";
30
31     @Before
32     public void setUp() {
33
34         ClassBasedModuleFactory mockedThreadPoolConfigFactory = new ClassBasedModuleFactory(
35                 threadPoolImplementationName, MockedThreadPoolModule.class);
36
37         super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,
38                 new TestingParallelAPSPModuleFactory(),
39                 mockedThreadPoolConfigFactory));
40     }
41
42     public static interface MockedTestingThreadPoolConfigMXBean extends
43             TestingThreadPoolConfigMXBean {
44         public void setThreadCount(int threadCount);
45     }
46
47     public static class MockedThreadPoolModule implements Module,
48             MockedTestingThreadPoolConfigMXBean,
49             TestingThreadPoolServiceInterface {
50
51         private final ModuleIdentifier moduleIdentifier;
52
53         int threadCount;
54
55         public MockedThreadPoolModule(
56                 DynamicMBeanWithInstance dynamicMBeanWithInstance, ModuleIdentifier moduleIdentifier) {
57             // no reconfiguration / reuse is supported
58             this.moduleIdentifier = moduleIdentifier;
59         }
60
61         @Override
62         public int getThreadCount() {
63             return threadCount;
64         }
65
66         @Override
67         public void setThreadCount(int threadCount) {
68             this.threadCount = threadCount;
69         }
70
71         @Override
72         public void validate() {
73
74         }
75
76         @Override
77         public boolean canReuse(Module oldModule) {
78             return false;
79         }
80
81         @Override
82         public Closeable getInstance() {
83             return new MockedThreadPool(threadCount);
84         }
85
86         @Override
87         public ModuleIdentifier getIdentifier() {
88             return moduleIdentifier;
89         }
90     }
91
92     public static class MockedThreadPool implements TestingThreadPoolIfc,
93             Closeable {
94         private final int threadCount;
95
96         public MockedThreadPool(int threadCount) {
97             this.threadCount = threadCount;
98         }
99
100         @Override
101         public Executor getExecutor() {
102             return null;
103         }
104
105         @Override
106         public int getMaxNumberOfThreads() {
107             return threadCount;
108         }
109
110         @Override
111         public void close() throws IOException {
112
113         }
114     }
115
116     @Override
117     protected String getThreadPoolImplementationName() {
118         return threadPoolImplementationName;
119     }
120
121     @Test
122     public void testDependencies() throws Exception {
123         ConfigTransactionJMXClient transaction = configRegistryClient
124                 .createTransaction();
125         // create fixed1
126         ObjectName threadPoolTransactionON = createFixed1(transaction,
127                 TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
128         // create apsp-parallel
129         createParallelAPSP(transaction, threadPoolTransactionON);
130
131         transaction.commit();
132     }
133
134 }