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.times;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.when;
17 import com.google.common.collect.Lists;
18 import com.google.common.util.concurrent.Futures;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.mockito.Mock;
24 import org.mockito.runners.MockitoJUnitRunner;
25 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
26 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
27 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
28 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
29 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
30 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
31 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
32 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
33 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService;
36 @RunWith(MockitoJUnitRunner.class)
37 public class OpenFlowPluginProviderImplTest {
40 DataBroker dataBroker;
43 RpcProviderRegistry rpcProviderRegistry;
46 NotificationService notificationService;
49 WriteTransaction writeTransaction;
52 EntityOwnershipService entityOwnershipService;
55 EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
58 BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
61 SwitchConnectionProvider switchConnectionProvider;
64 ClusterSingletonServiceProvider clusterSingletonServiceProvider;
66 private static final long RPC_REQUESTS_QUOTA = 500;
67 private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
68 private static final int THREAD_POOL_MIN_THREADS = 1;
69 private static final int THREAD_POOL_MAX_THREADS = 32000;
70 private static final long THREAD_POOL_TIMEOUT = 60;
72 private OpenFlowPluginProviderImpl provider;
75 public void setUp() throws Exception {
76 when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
77 when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
78 when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
79 when(rpcProviderRegistry.addRpcImplementation(eq(StatisticsManagerControlService.class), any())).thenReturn(controlServiceRegistration);
80 when(switchConnectionProvider.startup()).thenReturn(Futures.immediateCheckedFuture(null));
82 provider = new OpenFlowPluginProviderImpl(
84 GLOBAL_NOTIFICATION_QUOTA,
85 THREAD_POOL_MIN_THREADS,
86 THREAD_POOL_MAX_THREADS,
89 provider.setDataBroker(dataBroker);
90 provider.setRpcProviderRegistry(rpcProviderRegistry);
91 provider.setNotificationProviderService(notificationService);
92 provider.setEntityOwnershipService(entityOwnershipService);
93 provider.setSwitchConnectionProviders(Lists.newArrayList(switchConnectionProvider));
94 provider.setClusteringSingletonServicesProvider(clusterSingletonServiceProvider);
98 public void tearDown() throws Exception {
103 public void testInitializeAndClose() throws Exception {
104 provider.initialize();
105 verify(switchConnectionProvider).startup();