Implementation of Rpc interfaces 58/17058/10
authorMartin Bobak <mbobak@cisco.com>
Wed, 25 Mar 2015 15:16:20 +0000 (16:16 +0100)
committerMartin Bobak <mbobak@cisco.com>
Thu, 26 Mar 2015 17:10:34 +0000 (18:10 +0100)
Implementation classes were created for interfaces RequestContext, RpcContext, RpcManager.
MdSalRegistrationUtils class for registration of services

Change-Id: I8f1f7e7342e04f94f74f7900eeaede3515b37f73
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
Signed-off-by: Martin Bobak <mbobak@cisco.com>
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RequestContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistratorUtils.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/api/openflow/device/RpcManagerImplTest.java

index 383136be3986ebcec52e210c592da3b142e75aad..806b7310226c382794ce961d9a34aebd4f4b2a26 100644 (file)
@@ -8,11 +8,11 @@
 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
@@ -22,23 +22,42 @@ public class RequestContextImpl<T extends DataObject> implements RequestContext
     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
 
     }
 }
index 3e50333b5e2c877215b27fb5bfe557c38a605336..1d100cf4854d735018330bae0659092d0bd7c244 100644 (file)
@@ -86,6 +86,7 @@ public class RpcContextImpl implements RpcContext {
         return null;
     }
 
+
     /**
      * Unregisters all services.
      *
index 123b51f318f1098b28b0bef78061b1e364459102..d7ac34975e307a42ec426d6f639c1698530fb019 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 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
@@ -35,7 +35,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.Sal
 
 /**
  * @author joe
- * 
  */
 public class MdSalRegistratorUtils {
 
@@ -44,7 +43,6 @@ 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));
@@ -64,5 +62,4 @@ public class MdSalRegistratorUtils {
         rpcContext.registerRpcServiceImplementation(OpendaylightQueueStatisticsService.class,
                 new OpendaylightQueueStatisticsServiceImpl(rpcContext));
     }
-
 }
index d335c2b4a992d8047ed954fc737c03c02f8a6de6..6c0e8b3b9bdace48a93abbb6d82067ea262306ae 100644 (file)
@@ -7,21 +7,33 @@
  */
 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);
@@ -36,15 +48,38 @@ public class RpcManagerImplTest {
                 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();
     }
 }