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;
38 import org.opendaylight.yangtools.yang.common.Uint16;
39 import org.opendaylight.yangtools.yang.common.Uint32;
41 @RunWith(MockitoJUnitRunner.class)
42 public class OpenFlowPluginProviderImplTest {
45 PingPongDataBroker dataBroker;
48 RpcProviderService rpcProviderRegistry;
51 NotificationPublishService notificationPublishService;
54 DiagStatusProvider ofPluginDiagstatusProvider;
57 SystemReadyMonitor systemReadyMonitor;
60 WriteTransaction writeTransaction;
63 EntityOwnershipService entityOwnershipService;
66 EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
69 ObjectRegistration<StatisticsManagerControlService> controlServiceRegistration;
72 SwitchConnectionProvider switchConnectionProvider;
75 ClusterSingletonServiceProvider clusterSingletonServiceProvider;
78 ConfigurationService configurationService;
81 MastershipChangeServiceManager mastershipChangeServiceManager;
83 private static final Uint16 THREAD_POOL_MIN_THREADS = Uint16.ONE;
84 private static final Uint16 THREAD_POOL_MAX_THREADS = Uint16.valueOf(32000);
85 private static final Uint32 THREAD_POOL_TIMEOUT = Uint32.valueOf(60);
86 private static final boolean USE_SINGLE_LAYER_SERIALIZATION = false;
87 private static final Uint16 DEVICE_CONNECTION_RATE_LIMIT_PER_MIN = Uint16.ZERO;
88 private static final Uint16 DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS = Uint16.valueOf(60);
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);
109 when(configurationService.getProperty(
110 eq(ConfigurationProperty.DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS.toString()), any()))
111 .thenReturn(DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS);
115 public void testInitializeAndClose() {
116 final OpenFlowPluginProviderImpl provider = new OpenFlowPluginProviderImpl(
117 configurationService,
118 new SwitchConnectionProviderList(Lists.newArrayList(switchConnectionProvider)),
121 notificationPublishService,
122 clusterSingletonServiceProvider,
123 entityOwnershipService,
124 mastershipChangeServiceManager,
125 ofPluginDiagstatusProvider,
128 provider.initialize();
129 // Calling the onSystemBootReady() callback
130 provider.onSystemBootReady();
131 verify(switchConnectionProvider).startup();
133 verify(switchConnectionProvider).shutdown();