2 * Copyright (c) 2016 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
9 package org.opendaylight.openflowplugin.impl;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.eq;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.when;
16 import com.google.common.collect.Lists;
17 import com.google.common.util.concurrent.Futures;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.runners.MockitoJUnitRunner;
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
24 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
25 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
26 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
27 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
28 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
29 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
30 import org.opendaylight.infrautils.diagstatus.DiagStatusService;
31 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
32 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
33 import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider;
34 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty;
35 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
36 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService;
39 @RunWith(MockitoJUnitRunner.class)
40 public class OpenFlowPluginProviderImplTest {
43 DataBroker dataBroker;
46 RpcProviderRegistry rpcProviderRegistry;
49 NotificationPublishService notificationPublishService;
52 DiagStatusService diagStatusService;
55 WriteTransaction writeTransaction;
58 EntityOwnershipService entityOwnershipService;
61 EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
64 BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
67 SwitchConnectionProvider switchConnectionProvider;
70 ClusterSingletonServiceProvider clusterSingletonServiceProvider;
73 ConfigurationService configurationService;
76 MastershipChangeServiceManager mastershipChangeServiceManager;
78 private static final int RPC_REQUESTS_QUOTA = 500;
79 private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
80 private static final int THREAD_POOL_MIN_THREADS = 1;
81 private static final int THREAD_POOL_MAX_THREADS = 32000;
82 private static final long THREAD_POOL_TIMEOUT = 60;
83 private static final long BASIC_TIMER_DELAY = 1L;
84 private static final boolean USE_SINGLE_LAYER_SERIALIZATION = false;
87 public void setUp() throws Exception {
88 when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
89 when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
90 when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
91 when(rpcProviderRegistry.addRpcImplementation(eq(StatisticsManagerControlService.class), any()))
92 .thenReturn(controlServiceRegistration);
93 when(switchConnectionProvider.startup()).thenReturn(Futures.immediateFuture(true));
94 when(switchConnectionProvider.shutdown()).thenReturn(Futures.immediateFuture(true));
95 when(configurationService.getProperty(eq(ConfigurationProperty.USE_SINGLE_LAYER_SERIALIZATION.toString()),
96 any())).thenReturn(USE_SINGLE_LAYER_SERIALIZATION);
97 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString()), any()))
98 .thenReturn(THREAD_POOL_MIN_THREADS);
99 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString()), any()))
100 .thenReturn(THREAD_POOL_MAX_THREADS);
101 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_TIMEOUT.toString()), any()))
102 .thenReturn(THREAD_POOL_TIMEOUT);
103 when(configurationService.getProperty(eq(ConfigurationProperty.RPC_REQUESTS_QUOTA.toString()), any()))
104 .thenReturn(RPC_REQUESTS_QUOTA);
105 when(configurationService.getProperty(eq(ConfigurationProperty.GLOBAL_NOTIFICATION_QUOTA.toString()), any()))
106 .thenReturn(GLOBAL_NOTIFICATION_QUOTA);
107 when(configurationService.getProperty(eq(ConfigurationProperty.BASIC_TIMER_DELAY.toString()), any()))
108 .thenReturn(BASIC_TIMER_DELAY);
112 public void testInitializeAndClose() throws Exception {
113 final OpenFlowPluginProvider provider = new OpenFlowPluginProviderFactoryImpl().newInstance(
114 configurationService,
117 notificationPublishService,
118 entityOwnershipService,
119 Lists.newArrayList(switchConnectionProvider),
120 clusterSingletonServiceProvider,
121 mastershipChangeServiceManager,
124 verify(switchConnectionProvider).startup();
126 verify(switchConnectionProvider).shutdown();