Added threadpool config tests.
[controller.git] / opendaylight / config / threadpool-config-impl / src / test / java / org / opendaylight / controller / config / threadpool / scheduled / TestingScheduledThreadPoolModule.java
1 package org.opendaylight.controller.config.threadpool.scheduled;\r
2 \r
3 import static org.mockito.Matchers.any;\r
4 import static org.mockito.Matchers.anyBoolean;\r
5 import static org.mockito.Matchers.anyLong;\r
6 import static org.mockito.Mockito.doNothing;\r
7 import static org.mockito.Mockito.doReturn;\r
8 import static org.mockito.Mockito.mock;\r
9 \r
10 import java.util.concurrent.ScheduledExecutorService;\r
11 import java.util.concurrent.ScheduledFuture;\r
12 import java.util.concurrent.TimeUnit;\r
13 \r
14 import javax.management.ObjectName;\r
15 \r
16 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;\r
17 import org.opendaylight.controller.config.api.ModuleIdentifier;\r
18 import org.opendaylight.controller.config.manager.impl.AbstractMockedModule;\r
19 import org.opendaylight.controller.config.spi.Module;\r
20 import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;\r
21 import org.opendaylight.controller.config.yang.threadpool.ScheduledThreadPoolServiceInterface;\r
22 import org.opendaylight.controller.config.yang.threadpool.impl.ScheduledThreadPoolModuleMXBean;\r
23 \r
24 import com.google.common.util.concurrent.ListenableFutureTask;\r
25 \r
26 public class TestingScheduledThreadPoolModule extends AbstractMockedModule implements\r
27         ScheduledThreadPoolServiceInterface, Module, ScheduledThreadPoolModuleMXBean {\r
28 \r
29     public TestingScheduledThreadPoolModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {\r
30         super(old, id);\r
31     }\r
32 \r
33     @Override\r
34     protected AutoCloseable prepareMockedInstance() throws Exception {\r
35         ScheduledThreadPoolWrapper instance = mock(ScheduledThreadPoolWrapper.class);\r
36         ScheduledExecutorService ses = mock(ScheduledExecutorService.class);\r
37         {// mockFuture\r
38             ScheduledFuture<?> future = mock(ScheduledFuture.class);\r
39             doReturn(false).when(future).cancel(anyBoolean());\r
40             try {\r
41                 doReturn(mock(Object.class)).when(future).get();\r
42             } catch (Exception e) {\r
43                 throw new RuntimeException(e);\r
44             }\r
45             doReturn(future).when(ses).schedule(any(Runnable.class), any(Long.class), any(TimeUnit.class));\r
46             doReturn(future).when(ses).scheduleWithFixedDelay(any(Runnable.class), anyLong(), anyLong(),\r
47                     any(TimeUnit.class));\r
48 \r
49         }\r
50         doNothing().when(ses).execute(any(Runnable.class));\r
51         doNothing().when(ses).execute(any(ListenableFutureTask.class));\r
52         doReturn(ses).when(instance).getExecutor();\r
53         doNothing().when(instance).close();\r
54 \r
55         doReturn(1).when(instance).getMaxThreadCount();\r
56         return instance;\r
57     }\r
58 \r
59     @Override\r
60     public ObjectName getThreadFactory() {\r
61         return any(ObjectName.class);\r
62     }\r
63 \r
64     @Override\r
65     public void setThreadFactory(ObjectName threadFactory) {\r
66     }\r
67 \r
68     @Override\r
69     public Integer getMaxThreadCount() {\r
70         return 1;\r
71     }\r
72 \r
73     @Override\r
74     public void setMaxThreadCount(Integer maxThreadCount) {\r
75     }\r
76 \r
77 }\r