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.After;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.Mock;
23 import org.mockito.runners.MockitoJUnitRunner;
24 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
25 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
26 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
27 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
28 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
29 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
30 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
31 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
32 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService;
35 @RunWith(MockitoJUnitRunner.class)
36 public class OpenFlowPluginProviderImplTest {
39 DataBroker dataBroker;
42 RpcProviderRegistry rpcProviderRegistry;
45 NotificationService notificationService;
48 WriteTransaction writeTransaction;
51 EntityOwnershipService entityOwnershipService;
54 EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
57 BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
60 SwitchConnectionProvider switchConnectionProvider;
63 ClusterSingletonServiceProvider clusterSingletonServiceProvider;
65 private static final long RPC_REQUESTS_QUOTA = 500;
66 private static final long GLOBAL_NOTIFICATION_QUOTA = 131072;
67 private static final int THREAD_POOL_MIN_THREADS = 1;
68 private static final int THREAD_POOL_MAX_THREADS = 32000;
69 private static final long THREAD_POOL_TIMEOUT = 60;
71 private OpenFlowPluginProviderImpl provider;
74 public void setUp() throws Exception {
75 when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
76 when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
77 when(entityOwnershipService.registerListener(any(), any())).thenReturn(entityOwnershipListenerRegistration);
78 when(rpcProviderRegistry.addRpcImplementation(eq(StatisticsManagerControlService.class), any())).thenReturn(controlServiceRegistration);
79 when(switchConnectionProvider.startup()).thenReturn(Futures.immediateCheckedFuture(null));
81 provider = new OpenFlowPluginProviderImpl(
83 GLOBAL_NOTIFICATION_QUOTA,
84 THREAD_POOL_MIN_THREADS,
85 THREAD_POOL_MAX_THREADS,
88 provider.setDataBroker(dataBroker);
89 provider.setRpcProviderRegistry(rpcProviderRegistry);
90 provider.setNotificationProviderService(notificationService);
91 provider.setSwitchConnectionProviders(Lists.newArrayList(switchConnectionProvider));
92 provider.setClusteringSingletonServicesProvider(clusterSingletonServiceProvider);
96 public void tearDown() throws Exception {
101 public void testInitializeAndClose() throws Exception {
102 provider.initialize();
103 verify(switchConnectionProvider).startup();