2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.config.threadpool.scheduled;
\r
10 import com.google.common.util.concurrent.ListenableFutureTask;
\r
11 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
\r
12 import org.opendaylight.controller.config.api.ModuleIdentifier;
\r
13 import org.opendaylight.controller.config.manager.impl.AbstractMockedModule;
\r
14 import org.opendaylight.controller.config.spi.Module;
\r
15 import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;
\r
16 import org.opendaylight.controller.config.yang.threadpool.ScheduledThreadPoolServiceInterface;
\r
17 import org.opendaylight.controller.config.yang.threadpool.impl.scheduled.ScheduledThreadPoolModuleMXBean;
\r
19 import javax.management.ObjectName;
\r
20 import java.util.concurrent.ScheduledExecutorService;
\r
21 import java.util.concurrent.ScheduledFuture;
\r
22 import java.util.concurrent.TimeUnit;
\r
24 import static org.mockito.Matchers.any;
\r
25 import static org.mockito.Matchers.anyBoolean;
\r
26 import static org.mockito.Matchers.anyLong;
\r
27 import static org.mockito.Mockito.doNothing;
\r
28 import static org.mockito.Mockito.doReturn;
\r
29 import static org.mockito.Mockito.mock;
\r
31 public class TestingScheduledThreadPoolModule extends AbstractMockedModule implements
\r
32 ScheduledThreadPoolServiceInterface, Module, ScheduledThreadPoolModuleMXBean {
\r
34 public TestingScheduledThreadPoolModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {
\r
39 protected AutoCloseable prepareMockedInstance() throws Exception {
\r
40 ScheduledThreadPoolWrapper instance = mock(ScheduledThreadPoolWrapper.class);
\r
41 ScheduledExecutorService ses = mock(ScheduledExecutorService.class);
\r
43 ScheduledFuture<?> future = mock(ScheduledFuture.class);
\r
44 doReturn(false).when(future).cancel(anyBoolean());
\r
46 doReturn(mock(Object.class)).when(future).get();
\r
47 } catch (Exception e) {
\r
48 throw new RuntimeException(e);
\r
50 doReturn(future).when(ses).schedule(any(Runnable.class), any(Long.class), any(TimeUnit.class));
\r
51 doReturn(future).when(ses).scheduleWithFixedDelay(any(Runnable.class), anyLong(), anyLong(),
\r
52 any(TimeUnit.class));
\r
55 doNothing().when(ses).execute(any(Runnable.class));
\r
56 doNothing().when(ses).execute(any(ListenableFutureTask.class));
\r
57 doReturn(ses).when(instance).getExecutor();
\r
58 doNothing().when(instance).close();
\r
60 doReturn(1).when(instance).getMaxThreadCount();
\r
65 public ObjectName getThreadFactory() {
\r
66 return any(ObjectName.class);
\r
70 public void setThreadFactory(ObjectName threadFactory) {
\r
74 public Integer getMaxThreadCount() {
\r
79 public void setMaxThreadCount(Integer maxThreadCount) {
\r