1 package org.opendaylight.controller.config.threadpool.scheduled;
\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
10 import java.util.concurrent.ScheduledExecutorService;
\r
11 import java.util.concurrent.ScheduledFuture;
\r
12 import java.util.concurrent.TimeUnit;
\r
14 import javax.management.ObjectName;
\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
24 import com.google.common.util.concurrent.ListenableFutureTask;
\r
26 public class TestingScheduledThreadPoolModule extends AbstractMockedModule implements
\r
27 ScheduledThreadPoolServiceInterface, Module, ScheduledThreadPoolModuleMXBean {
\r
29 public TestingScheduledThreadPoolModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {
\r
34 protected AutoCloseable prepareMockedInstance() throws Exception {
\r
35 ScheduledThreadPoolWrapper instance = mock(ScheduledThreadPoolWrapper.class);
\r
36 ScheduledExecutorService ses = mock(ScheduledExecutorService.class);
\r
38 ScheduledFuture<?> future = mock(ScheduledFuture.class);
\r
39 doReturn(false).when(future).cancel(anyBoolean());
\r
41 doReturn(mock(Object.class)).when(future).get();
\r
42 } catch (Exception e) {
\r
43 throw new RuntimeException(e);
\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
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
55 doReturn(1).when(instance).getMaxThreadCount();
\r
60 public ObjectName getThreadFactory() {
\r
61 return any(ObjectName.class);
\r
65 public void setThreadFactory(ObjectName threadFactory) {
\r
69 public Integer getMaxThreadCount() {
\r
74 public void setMaxThreadCount(Integer maxThreadCount) {
\r