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
8 package org.opendaylight.openflowplugin.impl;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.ArgumentMatchers.eq;
12 import static org.mockito.Mockito.doReturn;
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.junit.MockitoJUnitRunner;
23 import org.opendaylight.infrautils.ready.SystemReadyMonitor;
24 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
25 import org.opendaylight.mdsal.binding.api.RpcProviderService;
26 import org.opendaylight.mdsal.binding.api.WriteTransaction;
27 import org.opendaylight.mdsal.common.api.CommitInfo;
28 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListenerRegistration;
29 import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService;
30 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
31 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
32 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProviderList;
33 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty;
34 import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService;
35 import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService;
37 import org.opendaylight.yangtools.concepts.ObjectRegistration;
39 @RunWith(MockitoJUnitRunner.class)
40 public class OpenFlowPluginProviderImplTest {
43 PingPongDataBroker dataBroker;
46 RpcProviderService rpcProviderRegistry;
49 NotificationPublishService notificationPublishService;
52 OpenflowPluginDiagStatusProvider ofPluginDiagstatusProvider;
55 SystemReadyMonitor systemReadyMonitor;
58 WriteTransaction writeTransaction;
61 EntityOwnershipService entityOwnershipService;
64 EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
67 ObjectRegistration<StatisticsManagerControlService> controlServiceRegistration;
70 SwitchConnectionProvider switchConnectionProvider;
73 ClusterSingletonServiceProvider clusterSingletonServiceProvider;
76 ConfigurationService configurationService;
79 MastershipChangeServiceManager mastershipChangeServiceManager;
81 private static final int RPC_REQUESTS_QUOTA = 500;
82 private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
83 private static final int THREAD_POOL_MIN_THREADS = 1;
84 private static final int THREAD_POOL_MAX_THREADS = 32000;
85 private static final long THREAD_POOL_TIMEOUT = 60;
86 private static final long BASIC_TIMER_DELAY = 1L;
87 private static final boolean USE_SINGLE_LAYER_SERIALIZATION = false;
88 private static final int DEVICE_CONNECTION_RATE_LIMIT_PER_MIN = 0;
91 public void setUp() throws Exception {
92 when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
93 doReturn(CommitInfo.emptyFluentFuture()).when(writeTransaction).commit();
94 when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
95 when(rpcProviderRegistry.registerRpcImplementation(eq(StatisticsManagerControlService.class), any()))
96 .thenReturn(controlServiceRegistration);
97 when(switchConnectionProvider.startup()).thenReturn(Futures.immediateFuture(true));
98 when(switchConnectionProvider.shutdown()).thenReturn(Futures.immediateFuture(true));
99 when(configurationService.getProperty(eq(ConfigurationProperty.USE_SINGLE_LAYER_SERIALIZATION.toString()),
100 any())).thenReturn(USE_SINGLE_LAYER_SERIALIZATION);
101 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MIN_THREADS.toString()), any()))
102 .thenReturn(THREAD_POOL_MIN_THREADS);
103 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_MAX_THREADS.toString()), any()))
104 .thenReturn(THREAD_POOL_MAX_THREADS);
105 when(configurationService.getProperty(eq(ConfigurationProperty.THREAD_POOL_TIMEOUT.toString()), any()))
106 .thenReturn(THREAD_POOL_TIMEOUT);
107 when(configurationService.getProperty(eq(ConfigurationProperty.DEVICE_CONNECTION_RATE_LIMIT_PER_MIN.toString()),
108 any())).thenReturn(DEVICE_CONNECTION_RATE_LIMIT_PER_MIN);
112 public void testInitializeAndClose() throws Exception {
113 final OpenFlowPluginProviderImpl provider = new OpenFlowPluginProviderImpl(
114 configurationService,
115 new SwitchConnectionProviderList(Lists.newArrayList(switchConnectionProvider)),
118 notificationPublishService,
119 clusterSingletonServiceProvider,
120 entityOwnershipService,
121 mastershipChangeServiceManager,
122 ofPluginDiagstatusProvider,
125 provider.initialize();
126 // Calling the onSystemBootReady() callback
127 provider.onSystemBootReady();
128 verify(switchConnectionProvider).startup();
130 verify(switchConnectionProvider).shutdown();