2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.lifecycle;
10 import com.google.common.util.concurrent.Futures;
11 import io.netty.util.HashedWheelTimer;
12 import java.util.concurrent.ExecutorService;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.runners.MockitoJUnitRunner;
20 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
21 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
22 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
23 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
24 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
25 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
26 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
27 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
28 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
29 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
31 @RunWith(MockitoJUnitRunner.class)
32 public class ContextChainHolderImplTest {
35 private HashedWheelTimer timer;
37 private StatisticsManager statisticsManager;
39 private RpcManager rpcManager;
41 private DeviceManager deviceManager;
43 private StatisticsContext statisticsContext;
45 private RpcContext rpcContext;
47 private DeviceContext deviceContext;
49 private ConnectionContext connectionContext;
51 private DeviceInfo deviceInfo;
53 private ClusterSingletonServiceProvider singletonServicesProvider;
55 private ExecutorService executorService;
57 private ClusterSingletonServiceRegistration clusterSingletonServiceRegistration;
59 private ContextChainHolderImpl contextChainHolder;
62 public void setUp() throws Exception {
63 Mockito.doAnswer(invocation -> {
64 invocation.getArgumentAt(0, Runnable.class).run();
66 }).when(executorService).submit(Mockito.<Runnable>any());
69 Mockito.when(connectionContext.getDeviceInfo()).thenReturn(deviceInfo);
70 Mockito.when(deviceManager.createContext(connectionContext)).thenReturn(deviceContext);
71 Mockito.when(rpcManager.createContext(
74 .thenReturn(rpcContext);
75 Mockito.when(statisticsManager.createContext(deviceContext)).thenReturn(statisticsContext);
76 Mockito.when(deviceContext.makeDeviceSlave()).thenReturn(Futures.immediateFuture(null));
77 Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
79 Mockito.when(singletonServicesProvider.registerClusterSingletonService(Mockito.any()))
80 .thenReturn(clusterSingletonServiceRegistration);
81 contextChainHolder = new ContextChainHolderImpl(timer, executorService);
82 contextChainHolder.addManager(statisticsManager);
83 contextChainHolder.addManager(rpcManager);
84 contextChainHolder.addManager(deviceManager);
85 contextChainHolder.addSingletonServicesProvider(singletonServicesProvider);
89 public void addManager() throws Exception {
90 Assert.assertTrue(contextChainHolder.checkAllManagers());
94 public void createContextChain() throws Exception {
95 contextChainHolder.createContextChain(connectionContext);
96 Mockito.verify(deviceManager).createContext(Mockito.any(ConnectionContext.class));
97 Mockito.verify(rpcManager).createContext(Mockito.any(DeviceInfo.class), Mockito.any(DeviceContext.class));
98 Mockito.verify(statisticsManager).createContext(Mockito.any(DeviceContext.class));
102 public void destroyContextChain() throws Exception {
107 public void pairConnection() throws Exception {
112 public void deviceConnected() throws Exception {
117 public void onNotAbleToStartMastership() throws Exception {
122 public void onMasterRoleAcquired() throws Exception {
127 public void onSlaveRoleAcquired() throws Exception {
132 public void onSlaveRoleNotAcquired() throws Exception {
137 public void onDeviceDisconnected() throws Exception {