2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.threadpool.scheduled;
10 import com.google.common.util.concurrent.ListenableFutureTask;
11 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
12 import org.opendaylight.controller.config.api.ModuleIdentifier;
13 import org.opendaylight.controller.config.manager.impl.AbstractMockedModule;
14 import org.opendaylight.controller.config.spi.Module;
15 import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;
16 import org.opendaylight.controller.config.yang.threadpool.ScheduledThreadPoolServiceInterface;
17 import org.opendaylight.controller.config.yang.threadpool.impl.scheduled.ScheduledThreadPoolModuleMXBean;
19 import javax.management.ObjectName;
20 import java.util.concurrent.ScheduledExecutorService;
21 import java.util.concurrent.ScheduledFuture;
22 import java.util.concurrent.TimeUnit;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Matchers.anyBoolean;
26 import static org.mockito.Matchers.anyLong;
27 import static org.mockito.Mockito.doNothing;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.mock;
31 public class TestingScheduledThreadPoolModule extends AbstractMockedModule implements
32 ScheduledThreadPoolServiceInterface, Module, ScheduledThreadPoolModuleMXBean {
34 public TestingScheduledThreadPoolModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {
39 protected AutoCloseable prepareMockedInstance() throws Exception {
40 ScheduledThreadPoolWrapper instance = mock(ScheduledThreadPoolWrapper.class);
41 ScheduledExecutorService ses = mock(ScheduledExecutorService.class);
43 ScheduledFuture<?> future = mock(ScheduledFuture.class);
44 doReturn(false).when(future).cancel(anyBoolean());
46 doReturn(mock(Object.class)).when(future).get();
47 } catch (Exception e) {
48 throw new RuntimeException(e);
50 doReturn(future).when(ses).schedule(any(Runnable.class), any(Long.class), any(TimeUnit.class));
51 doReturn(future).when(ses).scheduleWithFixedDelay(any(Runnable.class), anyLong(), anyLong(),
55 doNothing().when(ses).execute(any(Runnable.class));
56 doNothing().when(ses).execute(any(ListenableFutureTask.class));
57 doReturn(ses).when(instance).getExecutor();
58 doNothing().when(instance).close();
60 doReturn(1).when(instance).getMaxThreadCount();
65 public ObjectName getThreadFactory() {
66 return any(ObjectName.class);
70 public void setThreadFactory(ObjectName threadFactory) {
74 public Integer getMaxThreadCount() {
79 public void setMaxThreadCount(Integer maxThreadCount) {