X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fthreadpool-config-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fthreadpool%2Fscheduled%2FTestingScheduledThreadPoolModule.java;h=2ba1b3b20da023be13004a65c07fcae21474687b;hb=2585706cfb4d3fff8538535212032511388bee07;hp=0fe5b0d1834cd78f2e17804fa1e759805d22ced8;hpb=bedd5051e2605b9e03fbd89acfbeced9ab252287;p=controller.git diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/scheduled/TestingScheduledThreadPoolModule.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/scheduled/TestingScheduledThreadPoolModule.java index 0fe5b0d183..2ba1b3b20d 100644 --- a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/scheduled/TestingScheduledThreadPoolModule.java +++ b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/scheduled/TestingScheduledThreadPoolModule.java @@ -1,82 +1,82 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.config.threadpool.scheduled; - -import com.google.common.util.concurrent.ListenableFutureTask; -import org.opendaylight.controller.config.api.DynamicMBeanWithInstance; -import org.opendaylight.controller.config.api.ModuleIdentifier; -import org.opendaylight.controller.config.manager.impl.AbstractMockedModule; -import org.opendaylight.controller.config.spi.Module; -import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper; -import org.opendaylight.controller.config.yang.threadpool.ScheduledThreadPoolServiceInterface; -import org.opendaylight.controller.config.yang.threadpool.impl.scheduled.ScheduledThreadPoolModuleMXBean; - -import javax.management.ObjectName; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; - -public class TestingScheduledThreadPoolModule extends AbstractMockedModule implements - ScheduledThreadPoolServiceInterface, Module, ScheduledThreadPoolModuleMXBean { - - public TestingScheduledThreadPoolModule(DynamicMBeanWithInstance old, ModuleIdentifier id) { - super(old, id); - } - - @Override - protected AutoCloseable prepareMockedInstance() throws Exception { - ScheduledThreadPoolWrapper instance = mock(ScheduledThreadPoolWrapper.class); - ScheduledExecutorService ses = mock(ScheduledExecutorService.class); - {// mockFuture - ScheduledFuture future = mock(ScheduledFuture.class); - doReturn(false).when(future).cancel(anyBoolean()); - try { - doReturn(mock(Object.class)).when(future).get(); - } catch (Exception e) { - throw new RuntimeException(e); - } - doReturn(future).when(ses).schedule(any(Runnable.class), any(Long.class), any(TimeUnit.class)); - doReturn(future).when(ses).scheduleWithFixedDelay(any(Runnable.class), anyLong(), anyLong(), - any(TimeUnit.class)); - - } - doNothing().when(ses).execute(any(Runnable.class)); - doNothing().when(ses).execute(any(ListenableFutureTask.class)); - doReturn(ses).when(instance).getExecutor(); - doNothing().when(instance).close(); - - doReturn(1).when(instance).getMaxThreadCount(); - return instance; - } - - @Override - public ObjectName getThreadFactory() { - return any(ObjectName.class); - } - - @Override - public void setThreadFactory(ObjectName threadFactory) { - } - - @Override - public Integer getMaxThreadCount() { - return 1; - } - - @Override - public void setMaxThreadCount(Integer maxThreadCount) { - } - -} +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.threadpool.scheduled; + +import com.google.common.util.concurrent.ListenableFutureTask; +import org.opendaylight.controller.config.api.DynamicMBeanWithInstance; +import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.opendaylight.controller.config.manager.impl.AbstractMockedModule; +import org.opendaylight.controller.config.spi.Module; +import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper; +import org.opendaylight.controller.config.yang.threadpool.ScheduledThreadPoolServiceInterface; +import org.opendaylight.controller.config.yang.threadpool.impl.scheduled.ScheduledThreadPoolModuleMXBean; + +import javax.management.ObjectName; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.anyLong; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +public class TestingScheduledThreadPoolModule extends AbstractMockedModule implements + ScheduledThreadPoolServiceInterface, Module, ScheduledThreadPoolModuleMXBean { + + public TestingScheduledThreadPoolModule(DynamicMBeanWithInstance old, ModuleIdentifier id) { + super(old, id); + } + + @Override + protected AutoCloseable prepareMockedInstance() throws Exception { + ScheduledThreadPoolWrapper instance = mock(ScheduledThreadPoolWrapper.class); + ScheduledExecutorService ses = mock(ScheduledExecutorService.class); + {// mockFuture + ScheduledFuture future = mock(ScheduledFuture.class); + doReturn(false).when(future).cancel(anyBoolean()); + try { + doReturn(mock(Object.class)).when(future).get(); + } catch (Exception e) { + throw new RuntimeException(e); + } + doReturn(future).when(ses).schedule(any(Runnable.class), any(Long.class), any(TimeUnit.class)); + doReturn(future).when(ses).scheduleWithFixedDelay(any(Runnable.class), anyLong(), anyLong(), + any(TimeUnit.class)); + + } + doNothing().when(ses).execute(any(Runnable.class)); + doNothing().when(ses).execute(any(ListenableFutureTask.class)); + doReturn(ses).when(instance).getExecutor(); + doNothing().when(instance).close(); + + doReturn(1).when(instance).getMaxThreadCount(); + return instance; + } + + @Override + public ObjectName getThreadFactory() { + return any(ObjectName.class); + } + + @Override + public void setThreadFactory(ObjectName threadFactory) { + } + + @Override + public Integer getMaxThreadCount() { + return 1; + } + + @Override + public void setMaxThreadCount(Integer maxThreadCount) { + } + +}