package org.opendaylight.openflowplugin.impl.rpc;
import com.google.common.util.concurrent.SettableFuture;
+import java.util.concurrent.Future;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import java.util.concurrent.Future;
/**
* @author joe
private final RpcContext rpcContext;
private SettableFuture<RpcResult<T>> rpcResultFuture;
- public RequestContextImpl(RpcContext rpcContext) {
+ public RequestContextImpl(final RpcContext rpcContext) {
this.rpcContext = rpcContext;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.opendaylight.openflowplugin.api.openflow.device.RequestContext#createRequestFuture(org.opendaylight.yangtools
+ * .yang.binding.DataObject)
+ */
@Override
public Future<RpcResult<T>> createRequestFuture(final DataObject dataObject) {
rpcResultFuture = SettableFuture.create();
return rpcResultFuture;
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.opendaylight.openflowplugin.api.openflow.device.RequestContext#requestSucceeded()
+ */
@Override
public void requestSucceeded() {
-
+ // TODO Auto-generated method stub
+
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.opendaylight.openflowplugin.api.openflow.device.RequestContext#requestFailed(java.lang.String)
+ */
@Override
public void requestFailed(final String exception) {
+ // TODO Auto-generated method stub
}
}
/**
* Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
+ *
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
/**
* @author joe
- *
*/
public class MdSalRegistratorUtils {
}
public static void registerServices(final RpcContext rpcContext) {
- rpcContext.registerRpcServiceImplementation(SalFlowService.class, new SalFlowServiceImpl(rpcContext));
rpcContext.registerRpcServiceImplementation(SalFlowService.class, new SalFlowServiceImpl(rpcContext));
rpcContext.registerRpcServiceImplementation(SalMeterService.class, new SalMeterServiceImpl(rpcContext));
rpcContext.registerRpcServiceImplementation(SalGroupService.class, new SalGroupServiceImpl(rpcContext));
rpcContext.registerRpcServiceImplementation(OpendaylightQueueStatisticsService.class,
new OpendaylightQueueStatisticsServiceImpl(rpcContext));
}
-
}
*/
package org.opendaylight.openflowplugin.api.openflow.device;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
import org.junit.Test;
import org.mockito.Matchers;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import org.opendaylight.openflowplugin.impl.rpc.RpcContextImpl;
import org.opendaylight.openflowplugin.impl.rpc.RpcManagerImpl;
+import org.opendaylight.openflowplugin.impl.services.SalFlowServiceImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.opendaylight.yangtools.yang.common.RpcResult;
public class RpcManagerImplTest {
- private static final int AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC = 13;
+ private static final int AWAITED_NUM_OF_CALL_ADD_ROUTED_RPC = 12;
+
+ private static final int AWAITED_NUM_OF_CALL_ADD_NEW_REQUEST = 1;
final ProviderContext mockedProviderContext = mock(ProviderContext.class);
final RpcManagerImpl rpcManager = new RpcManagerImpl(mockedProviderContext);
Matchers.any(Class.class), Matchers.any(RpcService.class));
}
+ final RpcContext mockedRpcContext = mock(RpcContext.class);
+ final AddFlowInput mockedFlowInput = prepareTestingAddFlow();
+ final DeviceContext mockedDeviceContext = mock(DeviceContext.class);
+
/**
* Tests behavior of RpcContextImpl when calling rpc from MD-SAL
*/
@Test
- public void invokeRpcTest() {
-
- rpcManager.deviceConnected(mockedRequestContext);
-// when(mockedProviderContext.getRpcService(SalFlowService.class)).thenReturn(value);
+ public void invokeRpcTestExistsCapacityTest() throws InterruptedException, ExecutionException {
+ invokeRpcTestExistsCapacity(10, true);
+ invokeRpcTestExistsCapacity(0, false);
+ }
+
+ private void invokeRpcTestExistsCapacity(final int capacity, final boolean result) throws InterruptedException,
+ ExecutionException {
+ // TODO: how to invoke service remotely?
+ final RpcContextImpl rpcContext = new RpcContextImpl(mockedProviderContext, mockedDeviceContext);
+ when(mockedProviderContext.getRpcService(SalFlowService.class)).thenReturn(new SalFlowServiceImpl(rpcContext));
+ rpcContext.setRequestContextQuota(capacity);
+
final SalFlowService salFlowService = mockedProviderContext.getRpcService(SalFlowService.class);
+ final Future<RpcResult<AddFlowOutput>> addedFlow = salFlowService.addFlow(prepareTestingAddFlow());
+ }
+
+ /**
+ * @return
+ */
+ private AddFlowInput prepareTestingAddFlow() {
+ final AddFlowInputBuilder builder = new AddFlowInputBuilder();
+ builder.setFlowName("dummy flow");
+ builder.setHardTimeout(10000);
+ return builder.build();
}
}