2 * Copyright (c) 2015 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.api.openflow.device;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.times;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.when;
16 import java.util.concurrent.ExecutionException;
17 import java.util.concurrent.Future;
18 import org.junit.Test;
19 import org.mockito.Matchers;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
21 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
22 import org.opendaylight.openflowplugin.impl.rpc.RpcContextImpl;
23 import org.opendaylight.openflowplugin.impl.rpc.RpcManagerImpl;
24 import org.opendaylight.openflowplugin.impl.services.SalFlowServiceImpl;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
29 import org.opendaylight.yangtools.yang.binding.RpcService;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
32 public class RpcManagerImplTest {
34 private static final int AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC = 12;
36 private static final int AWAITED_NUM_OF_CALL_ADD_NEW_REQUEST = 1;
38 final ProviderContext mockedProviderContext = mock(ProviderContext.class);
39 final RpcManagerImpl rpcManager = new RpcManagerImpl(mockedProviderContext);
40 final DeviceContext mockedRequestContext = mock(DeviceContext.class);
43 public void deviceConnectedTest() {
45 rpcManager.deviceConnected(mockedRequestContext);
47 verify(mockedProviderContext, times(AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC)).addRoutedRpcImplementation(
48 Matchers.any(Class.class), Matchers.any(RpcService.class));
51 final RpcContext mockedRpcContext = mock(RpcContext.class);
52 final AddFlowInput mockedFlowInput = prepareTestingAddFlow();
53 final DeviceContext mockedDeviceContext = mock(DeviceContext.class);
56 * Tests behavior of RpcContextImpl when calling rpc from MD-SAL
59 public void invokeRpcTestExistsCapacityTest() throws InterruptedException, ExecutionException {
60 invokeRpcTestExistsCapacity(10, true);
61 invokeRpcTestExistsCapacity(0, false);
64 private void invokeRpcTestExistsCapacity(final int capacity, final boolean result) throws InterruptedException,
66 // TODO: how to invoke service remotely?
67 final RpcContextImpl rpcContext = new RpcContextImpl(mockedProviderContext, mockedDeviceContext);
68 when(mockedProviderContext.getRpcService(SalFlowService.class)).thenReturn(new SalFlowServiceImpl(rpcContext));
69 rpcContext.setRequestContextQuota(capacity);
71 final SalFlowService salFlowService = mockedProviderContext.getRpcService(SalFlowService.class);
72 final Future<RpcResult<AddFlowOutput>> addedFlow = salFlowService.addFlow(prepareTestingAddFlow());
78 private AddFlowInput prepareTestingAddFlow() {
79 final AddFlowInputBuilder builder = new AddFlowInputBuilder();
80 builder.setFlowName("dummy flow");
81 builder.setHardTimeout(10000);
83 return builder.build();