Merge "Remove raw references to Map in XSQL"
[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 Closeable getInstance() {
78             return new MockedThreadPool(threadCount);
79         }
80
81         @Override
82         public ModuleIdentifier getIdentifier() {
83             return moduleIdentifier;
84         }
85     }
86
87     public static class MockedThreadPool implements TestingThreadPoolIfc,
88             Closeable {
89         private final int threadCount;
90
91         public MockedThreadPool(int threadCount) {
92             this.threadCount = threadCount;
93         }
94
95         @Override
96         public Executor getExecutor() {
97             return null;
98         }
99
100         @Override
101         public int getMaxNumberOfThreads() {
102             return threadCount;
103         }
104
105         @Override
106         public void close() throws IOException {
107
108         }
109     }
110
111     @Override
112     protected String getThreadPoolImplementationName() {
113         return threadPoolImplementationName;
114     }
115
116     @Test
117     public void testDependencies() throws Exception {
118         ConfigTransactionJMXClient transaction = configRegistryClient
119                 .createTransaction();
120         // create fixed1
121         ObjectName threadPoolTransactionON = createFixed1(transaction,
122                 TestingParallelAPSPImpl.MINIMAL_NUMBER_OF_THREADS);
123         // create apsp-parallel
124         createParallelAPSP(transaction, threadPoolTransactionON);
125
126         transaction.commit();
127     }
128
129 }