Simplify method isMutualExclusive in Subnet.
[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
14 import javax.management.ObjectName;
15
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;
29
30 public class MockedDependenciesTest extends AbstractParallelAPSPTest {
31     private final String threadPoolImplementationName = "mockedthreadpool";
32
33     @Before
34     public void setUp() {
35
36         ClassBasedModuleFactory mockedThreadPoolConfigFactory = new ClassBasedModuleFactory(
37                 threadPoolImplementationName, MockedThreadPoolModule.class);
38
39         super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(
40                 new TestingParallelAPSPModuleFactory(),
41                 mockedThreadPoolConfigFactory));
42     }
43
44     public static interface MockedTestingThreadPoolConfigMXBean extends
45             TestingThreadPoolConfigMXBean {
46         public void setThreadCount(int threadCount);
47     }
48
49     public static class MockedThreadPoolModule implements Module,
50             MockedTestingThreadPoolConfigMXBean,
51             TestingThreadPoolServiceInterface {
52
53         private final ModuleIdentifier moduleIdentifier;
54
55         int threadCount;
56
57         public MockedThreadPoolModule(
58                 DynamicMBeanWithInstance dynamicMBeanWithInstance, ModuleIdentifier moduleIdentifier) {
59             // no reconfiguration / reuse is supported
60             this.moduleIdentifier = moduleIdentifier;
61         }
62
63         @Override
64         public int getThreadCount() {
65             return threadCount;
66         }
67
68         @Override
69         public void setThreadCount(int threadCount) {
70             this.threadCount = threadCount;
71         }
72
73         @Override
74         public void validate() {
75
76         }
77
78         @Override
79         public Closeable getInstance() {
80             return new MockedThreadPool(threadCount);
81         }
82
83         @Override
84         public ModuleIdentifier getIdentifier() {
85             return moduleIdentifier;
86         }
87     }
88
89     public static class MockedThreadPool implements TestingThreadPoolIfc,
90             Closeable {
91         private final int threadCount;
92
93         public MockedThreadPool(int threadCount) {
94             this.threadCount = threadCount;
95         }
96
97         @Override
98         public Executor getExecutor() {
99             return null;
100         }
101
102         @Override
103         public int getMaxNumberOfThreads() {
104             return threadCount;
105         }
106
107         @Override
108         public void close() throws IOException {
109
110         }
111     }
112
113     @Override
114     String getThreadPoolImplementationName() {
115         return threadPoolImplementationName;
116     }
117
118     @Test
119     public void testDependencies() throws Exception {
120         ConfigTransactionJMXClient transaction = configRegistryClient
121                 .createTransaction();
122         // create fixed1
123         ObjectName threadPoolTransactionON = createFixed1(transaction,
124                 TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
125         // create apsp-parallel
126         createParallelAPSP(transaction, threadPoolTransactionON);
127
128         transaction.commit();
129     }
130
131 }