Fix UNSTABLE build issue led by unit tests 24/19124/37
authorYi Yang <[email protected]>
Mon, 27 Apr 2015 11:01:00 +0000 (19:01 +0800)
committerYi Yang <[email protected]>
Wed, 29 Apr 2015 14:30:39 +0000 (22:30 +0800)
- Correct *Funtion* to *Function* in file name and function name
- Catch NullPointerException to trace call stack
- Add LOG.debug for debugging
- Print SfcDataStoreAPI Transaction failed with caller info
- Modify Load Banlance scheduler
- Check if a ServiceFunction does exist in scheduler
- Add sleep after getPutAll in order to ensure they are really put
- Clean up all the objects in SFC data store and ensure they are deleted before unit test

Change-Id: Ic4df527b1abc0f84d392e0e024de87a449d6e8f5
Signed-off-by: Yi Yang <[email protected]>
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcDataStoreAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcProviderRenderedPathAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcServiceFunctionLoadBalanceSchedulerAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcServiceFunctionRandomSchedulerAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcServiceFunctionRoundRobinSchedulerAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcServiceFunctionSchedulerAPI.java
sfc-provider/src/main/java/org/opendaylight/sfc/provider/api/SfcServiceFunctionShortestPathSchedulerAPI.java
sfc-provider/src/test/java/org/opendaylight/sfc/provider/api/SfcProviderRenderedPathAPITest.java
sfc-provider/src/test/java/org/opendaylight/sfc/provider/api/SfcServiceFunctionLoadBalanceSchedulerAPITest.java
sfc-provider/src/test/java/org/opendaylight/sfc/provider/api/SfcServiceFunctionSchedulerAPITest.java [moved from sfc-provider/src/test/java/org/opendaylight/sfc/provider/api/SfcServiceFuntionSchedulerAPITest.java with 78% similarity]
sfc-provider/src/test/java/org/opendaylight/sfc/provider/api/SfcServiceFunctionShortestPathSchedulerAPITest.java

index 3a76cab87be16f00b12606cb0b04612e13aca081..00f54553fac69d695d66ca5d6c90d37aba663dd8 100644 (file)
@@ -52,7 +52,7 @@ public class SfcDataStoreAPI {
             submitFuture.checkedGet();
             ret = true;
         } catch (TransactionCommitFailedException e) {
-            LOG.error("Transaction failed. Message: {}", e.getMessage());
+            LOG.error("deleteTransactionAPI: Transaction failed. Message: {}", e.getMessage());
             ret = false;
         }
         return ret;
@@ -70,7 +70,7 @@ public class SfcDataStoreAPI {
             submitFuture.checkedGet();
             ret = true;
         } catch (TransactionCommitFailedException e) {
-            LOG.error("Transaction failed. Message: {}", e.getMessage());
+            LOG.error("writeMergeTransactionAPI: Transaction failed. Message: {}", e.getMessage());
             ret = false;
         }
         return ret;
@@ -86,7 +86,7 @@ public class SfcDataStoreAPI {
             submitFuture.checkedGet();
             ret = true;
         } catch (TransactionCommitFailedException e) {
-            LOG.error("Transaction failed. Message: {}", e.getMessage());
+            LOG.error("writePutTransactionAPI: Transaction failed. Message: {}", e.getMessage());
             ret = false;
         }
         return ret;
index 81048a5752271fc9348636d82db7bb25bae4aabe..f19f206b47c42e93849599ef11de345cecd3dd6c 100644 (file)
@@ -91,7 +91,7 @@ public class SfcProviderRenderedPathAPI extends SfcProviderAbstractAPI {
 
     private SfcServiceFunctionSchedulerAPI scheduler;
 
-    private void initServiceFuntionScheduler()
+    private void initServiceFunctionScheduler()
     {
         java.lang.Class<? extends org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.ServiceFunctionSchedulerTypeIdentity> serviceFunctionSchedulerType;
 
@@ -132,12 +132,12 @@ public class SfcProviderRenderedPathAPI extends SfcProviderAbstractAPI {
 
     SfcProviderRenderedPathAPI(Object[] params, String m) {
         super(params, m);
-        initServiceFuntionScheduler();
+        initServiceFunctionScheduler();
     }
 
     SfcProviderRenderedPathAPI(Object[] params, Class[] paramsTypes, String m) {
         super(params, paramsTypes, m);
-        initServiceFuntionScheduler();
+        initServiceFunctionScheduler();
     }
 
 
@@ -466,9 +466,9 @@ public class SfcProviderRenderedPathAPI extends SfcProviderAbstractAPI {
         serviceIndex = MAX_STARTING_INDEX;
 
         List<String> sfgNameList = getSfgNameList(serviceFunctionChain);
-        List<String> sfNameList = scheduler.scheduleServiceFuntions(serviceFunctionChain, serviceIndex);
+        List<String> sfNameList = scheduler.scheduleServiceFunctions(serviceFunctionChain, serviceIndex);
         if(sfNameList == null && sfgNameList == null) {
-            LOG.warn("createRenderedServicePathEntry scheduler.scheduleServiceFuntions() returned null list");
+            LOG.warn("createRenderedServicePathEntry scheduler.scheduleServiceFunctions() returned null list");
             return null;
         }
         List<RenderedServicePathHop> renderedServicePathHopArrayList = createRenderedServicePathHopList(sfNameList, sfgNameList, serviceIndex);
index 847514cc745e73adfdeddba3610ba11631762304..84a3f4c22af3e4c9eb2c3e5a3fd9183b44de3f3d 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev1407
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.service.function.types.service.function.type.SftServiceFunctionName;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunction;
 import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.yang.sfc.sfst.rev150312.LoadBalance;
+import org.opendaylight.yang.gen.v1.urn.intel.params.xml.ns.sf.desc.mon.rev141201.service.functions.state.service.function.state.SfcSfDescMon;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,36 +38,53 @@ public class SfcServiceFunctionLoadBalanceSchedulerAPI extends SfcServiceFunctio
     }
 
     private String getServiceFunctionByType(ServiceFunctionType serviceFunctionType) {
+        boolean ret = false;
         List<SftServiceFunctionName> sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
-        String sftServiceFunctionName = sftServiceFunctionNameList.get(0).getName();
+        String sfName = null;
+        String sftServiceFunctionName = null;
+        java.lang.Long preCPUUtilization = java.lang.Long.MAX_VALUE;
 
-        ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunctionExecutor(sftServiceFunctionName);
-        if (!SfcProviderServiceFunctionAPI.putServiceFunctionMonitorExecutor(serviceFunction)){
-            LOG.error("Put monitor information to Data Store failed! serviceFunction: {}", serviceFunction.getName());
-        }
+        for (SftServiceFunctionName curSftServiceFunctionName : sftServiceFunctionNameList){
+            sfName = curSftServiceFunctionName.getName();
 
-        if (SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitorExecutor(sftServiceFunctionName) != null){
-            java.lang.Long preCPUUtilization = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitorExecutor(sftServiceFunctionName)
-                                                   .getMonitoringInfo()
-                                                   .getResourceUtilization()
-                                                   .getCPUUtilization();
-
-            for (SftServiceFunctionName curSftServiceFunctionName : sftServiceFunctionNameList){
-                java.lang.Long curCPUUtilization = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitorExecutor(curSftServiceFunctionName.getName())
-                                            .getMonitoringInfo()
-                                            .getResourceUtilization()
-                                            .getCPUUtilization();
-
-                if (preCPUUtilization > curCPUUtilization){
-                    preCPUUtilization = curCPUUtilization;
-                    sftServiceFunctionName = curSftServiceFunctionName.getName();
-                }
+            /* Check next one if curSftServiceFunctionName doesn't exist */
+            ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunctionExecutor(sfName);
+            if (serviceFunction == null) {
+                LOG.error("ServiceFunction {} doesn't exist", sfName);
+                continue;
+            }
+
+            /* Update ServiceFunctionMonitor information */
+            ret = SfcProviderServiceFunctionAPI.putServiceFunctionMonitorExecutor(serviceFunction);
+            if (ret == false) {
+                LOG.error("Put monitor information to Data Store failed! serviceFunction: {}", sfName);
+            }
+
+            /* Read ServiceFunctionMonitor information */
+            SfcSfDescMon sfcSfDescMon = SfcProviderServiceFunctionAPI.readServiceFunctionDescriptionMonitorExecutor(sfName);
+            if (sfcSfDescMon == null) {
+                sftServiceFunctionName = sfName;
+                LOG.error("Read monitor information from Data Store failed! serviceFunction: {}", sfName);
+                // Use sfName if no sfcSfDescMon is available
+                break;
+            }
+
+            java.lang.Long curCPUUtilization = sfcSfDescMon.getMonitoringInfo().getResourceUtilization().getCPUUtilization();
+
+            if (preCPUUtilization > curCPUUtilization){
+                preCPUUtilization = curCPUUtilization;
+                sftServiceFunctionName = sfName;
             }
         }
+
+        if (sftServiceFunctionName == null) {
+            LOG.error("Failed to get one available ServiceFunction for {}", serviceFunctionType.getType().getSimpleName());
+        }
+
         return sftServiceFunctionName;
     }
 
-    public List<String> scheduleServiceFuntions(ServiceFunctionChain chain, int serviceIndex) {
+    public List<String> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex) {
         List<String> sfNameList = new ArrayList<>();
         List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
         sfcServiceFunctionList.addAll(chain.getSfcServiceFunction());
index f0417085c40cc71f768ec2825d48a0fc4e6c78cd..df5c8072ab8208c6ad3145cac115f0be14c97711 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.sfc.provider.api;
 
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sf.rev140701.service.functions.ServiceFunction;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.ServiceFunctionChain;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sfc.rev140701.service.function.chain.grouping.service.function.chain.SfcServiceFunction;
 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sft.rev140701.service.function.types.ServiceFunctionType;
@@ -37,12 +38,31 @@ public class SfcServiceFunctionRandomSchedulerAPI extends SfcServiceFunctionSche
 
     private String getServiceFunctionByType(ServiceFunctionType serviceFunctionType) {
         List<SftServiceFunctionName> sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+        int maxTries = sftServiceFunctionNameList.size();
         Random rad = new Random();
+        ServiceFunction serviceFunction = null;
+        String serviceFunctionName = null;
+        int start = rad.nextInt(sftServiceFunctionNameList.size());
 
-        return sftServiceFunctionNameList.get(rad.nextInt(sftServiceFunctionNameList.size())).getName();
+        while (maxTries > 0) {
+            serviceFunctionName = sftServiceFunctionNameList.get(start).getName();
+            serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunctionExecutor(serviceFunctionName);
+            if (serviceFunction != null) {
+                break;
+            } else {
+                LOG.debug("ServiceFunction {} doesn't exist", serviceFunctionName);
+                maxTries--;
+                serviceFunctionName = null;
+                start = (start + 1) % sftServiceFunctionNameList.size();
+            }
+        }
+        if (serviceFunctionName == null) {
+            LOG.error("Could not find an existing ServiceFunction for {}", serviceFunctionType.getType().getSimpleName());
+        }
+        return serviceFunctionName;
     }
 
-    public List<String> scheduleServiceFuntions(ServiceFunctionChain chain, int serviceIndex) {
+    public List<String> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex) {
         List<String> sfNameList = new ArrayList<>();
         List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
         sfcServiceFunctionList.addAll(chain.getSfcServiceFunction());
index 706ceffa6dc1d74275274a875f53947e02a5d3ac..f49793453b78d0537541b5c03eba01c56865f56e 100644 (file)
@@ -59,7 +59,7 @@ public class SfcServiceFunctionRoundRobinSchedulerAPI extends SfcServiceFunction
         return sftServiceFunctionName.getName();
     }
 
-    public List<String> scheduleServiceFuntions(ServiceFunctionChain chain, int serviceIndex) {
+    public List<String> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex) {
         List<String> sfNameList = new ArrayList<>();
         List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
         sfcServiceFunctionList.addAll(chain.getSfcServiceFunction());
index 41d4b71d48d9b0797996d3bde4057d631a25c39e..d5e7132e03adc06c9e65c23dad9b47de38d45b84 100644 (file)
@@ -32,5 +32,5 @@ public abstract class SfcServiceFunctionSchedulerAPI {
         this.sfcServiceFunctionSchedulerType = schedulerType;
     }
 
-    abstract public List<String> scheduleServiceFuntions(ServiceFunctionChain chain, int serviceIndex);
+    abstract public List<String> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex);
 }
index 9878ab195a90b6fc5d9952e60de2c237035136f6..48a741bec9c5066b56a7d7d3c0bfc16fd7dedaf3 100644 (file)
@@ -57,6 +57,7 @@ public class SfcServiceFunctionShortestPathSchedulerAPI extends SfcServiceFuncti
     private String getServiceFunctionByType(ServiceFunctionType serviceFunctionType, String preSfName, SfcProviderGraph sfcProviderGraph) {
         String sfcProviderTopologyNodeName = null;
         List<SftServiceFunctionName> sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+        int maxTries = sftServiceFunctionNameList.size();
 
         /* Return null if sftServiceFunctionNameList is empty */
         if (sftServiceFunctionNameList.size() == 0) {
@@ -71,7 +72,20 @@ public class SfcServiceFunctionShortestPathSchedulerAPI extends SfcServiceFuncti
         if (preSfName == null) {
             /* Randomly find one instance of serviceFunctionType */
             Random rad = new Random();
-            sfcProviderTopologyNodeName = sftServiceFunctionNameList.get(rad.nextInt(sftServiceFunctionNameList.size())).getName();
+            int start = rad.nextInt(sftServiceFunctionNameList.size());
+            SfcProviderTopologyNode firstHopNode = null;
+            while (maxTries > 0) {
+                sfcProviderTopologyNodeName = sftServiceFunctionNameList.get(start).getName();
+                firstHopNode = sfcProviderGraph.getNode(sfcProviderTopologyNodeName);
+                if (firstHopNode != null) {
+                    break;
+                } else {
+                    LOG.debug("ServiceFunction {} doesn't exist", sfcProviderTopologyNodeName);
+                    sfcProviderTopologyNodeName = null;
+                    start = (start + 1) % sftServiceFunctionNameList.size();
+                    maxTries--;
+                }
+            }
             LOG.debug("The first ServiceFunction name: {}", sfcProviderTopologyNodeName);
             return sfcProviderTopologyNodeName; //The first hop
         }
@@ -90,6 +104,11 @@ public class SfcServiceFunctionShortestPathSchedulerAPI extends SfcServiceFuncti
         sfcProviderTopologyNodeName = null;
         for (SftServiceFunctionName sftServiceFunctionName : sftServiceFunctionNameList) {
             String curSfName = sftServiceFunctionName.getName();
+            SfcProviderTopologyNode curSfcProviderTopologyNode = sfcProviderGraph.getNode(curSfName);
+            if (curSfcProviderTopologyNode == null) {
+                // curSfName doesn't exist in sfcProviderGraph, so skip it
+                continue;
+            }
             List<SfcProviderTopologyNode> sfcProviderTopologyNodeList = sfcProviderGraph.getShortestPath(preSfName, curSfName);
             length = sfcProviderTopologyNodeList.size();
             if (length <= 1) {
@@ -180,9 +199,9 @@ public class SfcServiceFunctionShortestPathSchedulerAPI extends SfcServiceFuncti
      * <p>
      * @param chain Service Function Chain to render
      * @param serviceIndex Not used currently
-     * @return List<String> Service Funtion name list in the shortest path
+     * @return List<String> Service Function name list in the shortest path
      */
-    public List<String> scheduleServiceFuntions(ServiceFunctionChain chain, int serviceIndex) {
+    public List<String> scheduleServiceFunctions(ServiceFunctionChain chain, int serviceIndex) {
         String preSfName = null;
         String sfName = null;
         List<String> sfNameList = new ArrayList<>();
@@ -213,7 +232,7 @@ public class SfcServiceFunctionShortestPathSchedulerAPI extends SfcServiceFuncti
                         preSfName = sfName;
                         LOG.debug("Next Service Function: {}", sfName);
                     } else {
-                        LOG.error("Couldn't find a reachable SF for ServiceFuntionType: {}", sfcServiceFunction.getType());
+                        LOG.error("Couldn't find a reachable SF for ServiceFunctionType: {}", sfcServiceFunction.getType());
                         return null;
                     }
                 } else {
index c48cdc7de3d513e3316876eb19485606f83d0aad..b3e6a1881ffad515bf465d81a92a8d122258a1d6 100755 (executable)
@@ -102,6 +102,7 @@ public class SfcProviderRenderedPathAPITest extends AbstractDataBrokerTest {
         executor.submit(SfcProviderServiceTypeAPI.getDeleteAll(new Object[]{}, new Class[]{}));
         executor.submit(SfcProviderServiceChainAPI.getDeleteAll(new Object[]{}, new Class[]{}));
         executor.submit(SfcProviderServicePathAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+        Thread.sleep(1000); // Wait for real delete
 
         // Create Service Functions
         final String[] sfNames = {"unittest-fw-1", "unittest-dpi-1", "unittest-napt-1", "unittest-http-header-enrichment-1", "unittest-qos-1"};
@@ -135,6 +136,7 @@ public class SfcProviderRenderedPathAPITest extends AbstractDataBrokerTest {
         sfsBuilder.setServiceFunction(sfList);
 
         executor.submit(SfcProviderServiceFunctionAPI.getPutAll(new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
+        Thread.sleep(1000); // Wait they are really created
 
         // Create ServiceFunctionTypeEntry for all ServiceFunctions
         for (ServiceFunction serviceFunction : sfList) {
@@ -191,6 +193,7 @@ public class SfcProviderRenderedPathAPITest extends AbstractDataBrokerTest {
             ServiceFunctionForwarder sff = sffBuilder.build();
             executor.submit(SfcProviderServiceForwarderAPI.getPut(new Object[]{sff}, new Class[]{ServiceFunctionForwarder.class})).get();
         }
+        Thread.sleep(1000); // Wait they are really created
     }
 
     @After
@@ -258,10 +261,18 @@ public class SfcProviderRenderedPathAPITest extends AbstractDataBrokerTest {
 
         CreateRenderedPathInputBuilder createRenderedPathInputBuilder = new CreateRenderedPathInputBuilder();
         createRenderedPathInputBuilder.setSymmetric(serviceFunctionPath.isSymmetric());
-        renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(serviceFunctionPath, createRenderedPathInputBuilder.build());
+        try {
+            renderedServicePath = SfcProviderRenderedPathAPI.createRenderedServicePathAndState(serviceFunctionPath, createRenderedPathInputBuilder.build());
+        } catch (NullPointerException e) {
+            e.printStackTrace();
+        }
         assertNotNull("Must be not null", renderedServicePath);
 
-        revRenderedServicePath = SfcProviderRenderedPathAPI.createSymmetricRenderedServicePathAndState(renderedServicePath);
+        try {
+            revRenderedServicePath = SfcProviderRenderedPathAPI.createSymmetricRenderedServicePathAndState(renderedServicePath);
+        } catch (NullPointerException e) {
+            e.printStackTrace();
+        }
         assertNotNull("Must be not null", revRenderedServicePath);
 
         RenderedServicePathFirstHop firstHop;
@@ -289,7 +300,12 @@ public class SfcProviderRenderedPathAPITest extends AbstractDataBrokerTest {
         sftList.add(HttpHeaderEnrichment.class);
         sftList.add(Qos.class);
         assertEquals("sftList size should be 5", sftList.size(), 5);
-        RenderedServicePathFirstHop firstHop = SfcProviderRenderedPathAPI.readRspFirstHopBySftList(sftList);
+        RenderedServicePathFirstHop firstHop = null;
+        try {
+            firstHop = SfcProviderRenderedPathAPI.readRspFirstHopBySftList(sftList);
+        } catch (NullPointerException e) {
+            e.printStackTrace();
+        }
         assertNotNull("Must be not null", firstHop);
         LOG.debug("First hop IP: {}, port: {}", firstHop.getIp().toString(), firstHop.getPort());
        assertEquals("Must be equal", firstHop.getIp(), new IpAddress(new Ipv4Address(SFF_LOCATOR_IP[0])));
index ce605cb2bc10b35a5bbb6543f9cad384bee7a820..6c13f1d3fd017469a105b280219502fc30fddf2f 100644 (file)
@@ -45,6 +45,8 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev14070
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
@@ -58,6 +60,7 @@ public class SfcServiceFunctionLoadBalanceSchedulerAPITest extends AbstractDataB
     DataBroker dataBroker;
     ExecutorService executor;
     OpendaylightSfc opendaylightSfc = new OpendaylightSfc();
+    private static final Logger LOG = LoggerFactory.getLogger(SfcProviderServiceChainAPITest.class);
 
     List<SfDataPlaneLocator> sfDPLList = new ArrayList<>();
     List<ServiceFunction> sfList = new ArrayList<>();
@@ -69,6 +72,51 @@ public class SfcServiceFunctionLoadBalanceSchedulerAPITest extends AbstractDataB
         opendaylightSfc.setDataProvider(dataBroker);
         executor = opendaylightSfc.getExecutor();
 
+        /* Delete all the content in SFC data store before unit test */
+        int maxTries = 10;
+        ServiceFunctionType serviceFunctionType;
+        List<SftServiceFunctionName> sftServiceFunctionNameList;
+        boolean emptyFlag = true;
+        while (maxTries > 0) {
+            emptyFlag = true;
+            executor.submit(SfcProviderServicePathAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+            executor.submit(SfcProviderServiceChainAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+            executor.submit(SfcProviderServiceTypeAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+            executor.submit(SfcProviderServiceFunctionAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+            executor.submit(SfcProviderServiceForwarderAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+            Thread.sleep(1000); //Wait for real delete
+
+            serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Firewall.class);
+            if (serviceFunctionType != null) {
+                sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+                if (sftServiceFunctionNameList.size() != 0) {
+                    emptyFlag = false;
+                }
+            }
+
+            serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Dpi.class);
+            if (serviceFunctionType != null) {
+                sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+                if (sftServiceFunctionNameList.size() != 0) {
+                    emptyFlag = false;
+                }
+            }
+
+            serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Napt44.class);
+            if (serviceFunctionType != null) {
+                sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+                if (sftServiceFunctionNameList.size() != 0) {
+                    emptyFlag = false;
+                }
+            }
+
+            maxTries--;
+            if (emptyFlag == true) {
+                break;
+            }
+        }
+        LOG.debug("Empty SFC data store {} times: {}", 10 - maxTries, emptyFlag ? "Successful" : "Failed");
+
         String sfcName = "loadbalance-unittest-chain-1";
         List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
         sfcServiceFunctionList.add(new SfcServiceFunctionBuilder()
@@ -128,6 +176,32 @@ public class SfcServiceFunctionLoadBalanceSchedulerAPITest extends AbstractDataB
         sfsBuilder.setServiceFunction(sfList);
         executor.submit(SfcProviderServiceFunctionAPI.getPutAll
                 (new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
+        //Wait a while in order to ensure they are really created
+        Thread.sleep(1000);
+
+        for (ServiceFunction serviceFunction: sfList) {
+            SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
+        }
+
+        /* Ensure all the ServiceFunctions in sfList are indeed created */
+        for (ServiceFunction serviceFunction : sfList) {
+            maxTries = 10;
+            ServiceFunction sf2 = null;
+            while (maxTries > 0) {
+                Object[] parameters2 = {serviceFunction.getName()};
+                Class[] parameterTypes2 = {String.class};
+                Object result = executor.submit(SfcProviderServiceFunctionAPI
+                    .getRead(parameters2, parameterTypes2)).get();
+                sf2 = (ServiceFunction) result;
+                maxTries--;
+                if (sf2 != null) {
+                    break;
+                }
+                Thread.sleep(1000);
+            }
+            LOG.debug("SfcServiceFunctionLoadBalanceSchedulerAPITest: getRead ServiceFunction {} {} times: {}", serviceFunction.getName(), 10 - maxTries, (sf2 == null) ? "Failed" : "Successful");
+        }
+
         // set CPUUtilization for SF
         String sfNameFW = "simple_fw_";
         for (int i=100; i<130; i=i+10){
@@ -195,28 +269,12 @@ public class SfcServiceFunctionLoadBalanceSchedulerAPITest extends AbstractDataB
     public void after() {
         executor.submit(SfcProviderServicePathAPI.getDeleteAll(new Object[]{}, new Class[]{}));
         executor.submit(SfcProviderServiceChainAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+        executor.submit(SfcProviderServiceTypeAPI.getDeleteAll(new Object[]{}, new Class[]{}));
         executor.submit(SfcProviderServiceFunctionAPI.getDeleteAll(new Object[]{}, new Class[]{}));
     }
 
     @Test
     public void testServiceFunctionLoadBalanceScheduler() throws ExecutionException, InterruptedException {
-
-        dataBroker = getDataBroker();
-        opendaylightSfc.setDataProvider(dataBroker);
-        executor = opendaylightSfc.getExecutor();
-
-        for (ServiceFunction serviceFuntion : sfList) {
-            Object[] parameters2 = {serviceFuntion.getName()};
-            Class[] parameterTypes2 = {String.class};
-            Object result = executor.submit(SfcProviderServiceFunctionAPI
-                    .getRead(parameters2, parameterTypes2)).get();
-            ServiceFunction sf2 = (ServiceFunction) result;
-
-            assertNotNull("Must be not null", sf2);
-            assertEquals("Must be equal", sf2.getName(), serviceFuntion.getName());
-            assertEquals("Must be equal", sf2.getType(), serviceFuntion.getType());
-        }
-
         Object[] sfcParameters = {sfChain};
         Class[] sfcParameterTypes = {ServiceFunctionChain.class};
         executor.submit(SfcProviderServiceChainAPI
@@ -231,10 +289,6 @@ public class SfcServiceFunctionLoadBalanceSchedulerAPITest extends AbstractDataB
         assertNotNull("Must be not null", sfc2);
         assertEquals("Must be equal", sfc2.getSfcServiceFunction(), sfChain.getSfcServiceFunction());
 
-        for (ServiceFunction serviceFunction: sfList) {
-            SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
-        }
-
         ServiceFunctionType serviceFunctionType;
         List<SftServiceFunctionName> sftServiceFunctionNameList;
 
@@ -262,7 +316,7 @@ public class SfcServiceFunctionLoadBalanceSchedulerAPITest extends AbstractDataB
         List<SftServiceFunctionName> sftNapt44List = serviceFunctionType.getSftServiceFunctionName();
 
         SfcServiceFunctionSchedulerAPI scheduler = new SfcServiceFunctionLoadBalanceSchedulerAPI();
-        List<String> serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+        List<String> serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
         assertNotNull("Must be not null", serviceFunctionNameArrayList);
 
         for (int i=0; i<3; i++){
similarity index 78%
rename from sfc-provider/src/test/java/org/opendaylight/sfc/provider/api/SfcServiceFuntionSchedulerAPITest.java
rename to sfc-provider/src/test/java/org/opendaylight/sfc/provider/api/SfcServiceFunctionSchedulerAPITest.java
index 7ed734eb8c0381a344be79d57dd7833fd9481293..685dafad29591075a5e7d22687f099e28ec26a18 100644 (file)
@@ -34,6 +34,8 @@ import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.sl.rev14070
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
@@ -43,11 +45,12 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 
-public class SfcServiceFuntionSchedulerAPITest extends AbstractDataBrokerTest {
+public class SfcServiceFunctionSchedulerAPITest extends AbstractDataBrokerTest {
 
     DataBroker dataBroker;
     ExecutorService executor;
     OpendaylightSfc opendaylightSfc = new OpendaylightSfc();
+    private static final Logger LOG = LoggerFactory.getLogger(SfcServiceFunctionSchedulerAPITest.class);
 
     List<SfDataPlaneLocator> sfDPLList = new ArrayList<>();
     List<ServiceFunction> sfList = new ArrayList<>();
@@ -59,6 +62,50 @@ public class SfcServiceFuntionSchedulerAPITest extends AbstractDataBrokerTest {
         opendaylightSfc.setDataProvider(dataBroker);
         executor = opendaylightSfc.getExecutor();
 
+        /* Delete all the content in SFC data store before unit test */
+        int maxTries = 10;
+        ServiceFunctionType serviceFunctionType;
+        List<SftServiceFunctionName> sftServiceFunctionNameList;
+        boolean emptyFlag = true;
+        while (maxTries > 0) {
+            emptyFlag = true;
+            executor.submit(SfcProviderServicePathAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+            executor.submit(SfcProviderServiceChainAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+            executor.submit(SfcProviderServiceTypeAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+            executor.submit(SfcProviderServiceFunctionAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+            executor.submit(SfcProviderServiceForwarderAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+            Thread.sleep(1000); //Wait for real delete
+
+            serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Firewall.class);
+            if (serviceFunctionType != null) {
+                sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+                if (sftServiceFunctionNameList.size() != 0) {
+                    emptyFlag = false;
+                }
+            }
+
+            serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Dpi.class);
+            if (serviceFunctionType != null) {
+                sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+                if (sftServiceFunctionNameList.size() != 0) {
+                    emptyFlag = false;
+                }
+            }
+
+            serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Napt44.class);
+            if (serviceFunctionType != null) {
+                sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
+                if (sftServiceFunctionNameList.size() != 0) {
+                    emptyFlag = false;
+                }
+            }
+
+            maxTries--;
+            if (emptyFlag == true) {
+                break;
+            }
+        }
+        LOG.debug("Empty SFC data store {} times: {}", 10 - maxTries, emptyFlag ? "Successful" : "Failed");
         String sfcName = "unittest-sched-chain-1";
         List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
         sfcServiceFunctionList.add(new SfcServiceFunctionBuilder()
@@ -114,6 +161,21 @@ public class SfcServiceFuntionSchedulerAPITest extends AbstractDataBrokerTest {
         sfList.add(SimpleTestEntityBuilder.buildServiceFunction("simple_nat_120", Napt44.class,
                 new IpAddress(new Ipv4Address("192.168.120.103")), sfDPLList.get(2), Boolean.FALSE));
 
+        ServiceFunctionsBuilder sfsBuilder = new ServiceFunctionsBuilder();
+        sfsBuilder.setServiceFunction(sfList);
+        executor.submit(SfcProviderServiceFunctionAPI.getPutAll
+                (new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
+        Thread.sleep(1000); //Wait they are really created
+
+        for (ServiceFunction serviceFunction: sfList) {
+            SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
+        }
+
+        Object[] sfcParameters = {sfChain};
+        Class[] sfcParameterTypes = {ServiceFunctionChain.class};
+        executor.submit(SfcProviderServiceChainAPI
+                .getPut(sfcParameters, sfcParameterTypes)).get();
+        Thread.sleep(1000); //Wait it is really created
     }
 
     @After
@@ -126,28 +188,28 @@ public class SfcServiceFuntionSchedulerAPITest extends AbstractDataBrokerTest {
 
     @Test
     public void testBasicEnvSetup() throws ExecutionException, InterruptedException {
-
-        ServiceFunctionsBuilder sfsBuilder = new ServiceFunctionsBuilder();
-        sfsBuilder.setServiceFunction(sfList);
-        executor.submit(SfcProviderServiceFunctionAPI.getPutAll
-                (new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
-        for (ServiceFunction serviceFuntion : sfList) {
-            Object[] parameters2 = {serviceFuntion.getName()};
-            Class[] parameterTypes2 = {String.class};
-            Object result = executor.submit(SfcProviderServiceFunctionAPI
+        int maxTries = 10;
+        for (ServiceFunction serviceFunction : sfList) {
+            maxTries = 10;
+            ServiceFunction sf2 = null;
+            while (maxTries > 0) {
+                Object[] parameters2 = {serviceFunction.getName()};
+                Class[] parameterTypes2 = {String.class};
+                Object result = executor.submit(SfcProviderServiceFunctionAPI
                     .getRead(parameters2, parameterTypes2)).get();
-            ServiceFunction sf2 = (ServiceFunction) result;
-
+                sf2 = (ServiceFunction) result;
+                maxTries--;
+                if (sf2 != null) {
+                    break;
+                }
+                Thread.sleep(1000);
+            }
+            LOG.debug("SfcServiceFunctionSchedulerAPITest: getRead ServiceFunction {} {} times: {}", serviceFunction.getName(), 10 - maxTries, (sf2 != null) ? "Successful" : "Failed");
             assertNotNull("Must be not null", sf2);
-            assertEquals("Must be equal", sf2.getName(), serviceFuntion.getName());
-            assertEquals("Must be equal", sf2.getType(), serviceFuntion.getType());
+            assertEquals("Must be equal", sf2.getName(), serviceFunction.getName());
+            assertEquals("Must be equal", sf2.getType(), serviceFunction.getType());
         }
 
-        Object[] sfcParameters = {sfChain};
-        Class[] sfcParameterTypes = {ServiceFunctionChain.class};
-        executor.submit(SfcProviderServiceChainAPI
-                .getPut(sfcParameters, sfcParameterTypes)).get();
-
         Object[] parameters2 = {sfChain.getName()};
         Class[] parameterTypes2 = {String.class};
         Object result = executor.submit(SfcProviderServiceChainAPI
@@ -157,16 +219,15 @@ public class SfcServiceFuntionSchedulerAPITest extends AbstractDataBrokerTest {
         assertNotNull("Must be not null", sfc2);
         assertEquals("Must be equal", sfc2.getSfcServiceFunction(), sfChain.getSfcServiceFunction());
 
-        for (ServiceFunction serviceFunction: sfList) {
-            SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
-        }
-
         ServiceFunctionType serviceFunctionType;
         List<SftServiceFunctionName> sftServiceFunctionNameList;
 
         serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Firewall.class);
         sftServiceFunctionNameList = serviceFunctionType.getSftServiceFunctionName();
         assertNotNull("Must be not null", sftServiceFunctionNameList);
+        for (SftServiceFunctionName sftServiceFunctionName : sftServiceFunctionNameList) {
+            LOG.debug("sftServiceFunctionName: {}", sftServiceFunctionName.getName());
+        }
         assertEquals("Must be equal", sftServiceFunctionNameList.size(), 3);
 
         serviceFunctionType = SfcProviderServiceTypeAPI.readServiceFunctionTypeExecutor(Dpi.class);
@@ -182,30 +243,15 @@ public class SfcServiceFuntionSchedulerAPITest extends AbstractDataBrokerTest {
 
     @Test
     public void testServiceFunctionRandomScheduler() throws ExecutionException, InterruptedException {
-
-        ServiceFunctionsBuilder sfsBuilder = new ServiceFunctionsBuilder();
-        sfsBuilder.setServiceFunction(sfList);
-        executor.submit(SfcProviderServiceFunctionAPI.getPutAll
-                (new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
-
-        Object[] sfcParameters = {sfChain};
-        Class[] sfcParameterTypes = {ServiceFunctionChain.class};
-        executor.submit(SfcProviderServiceChainAPI
-                .getPut(sfcParameters, sfcParameterTypes)).get();
-
-        for (ServiceFunction serviceFunction: sfList) {
-            SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
-        }
-
         int serviceIndex = 255;
         SfcServiceFunctionSchedulerAPI scheduler = new SfcServiceFunctionRandomSchedulerAPI();
         List<String> serviceFunctionNameArrayList =
-                scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+                scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
 
         assertNotNull("Must be not null", serviceFunctionNameArrayList);
 
-        ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI
-                                    .readServiceFunctionExecutor(serviceFunctionNameArrayList.get(0));
+        ServiceFunction serviceFunction = SfcProviderServiceFunctionAPI.readServiceFunctionExecutor(serviceFunctionNameArrayList.get(0));
+        assertNotNull("Must be not null", serviceFunction);
         assertEquals("Must be equal", serviceFunction.getType(), Firewall.class);
         assertNotEquals("Must be not equal", serviceFunction.getType(), Dpi.class);
 
@@ -222,21 +268,6 @@ public class SfcServiceFuntionSchedulerAPITest extends AbstractDataBrokerTest {
 
     @Test
     public void testServiceFunctionRoundRobinScheduler() throws ExecutionException, InterruptedException {
-
-        ServiceFunctionsBuilder sfsBuilder = new ServiceFunctionsBuilder();
-        sfsBuilder.setServiceFunction(sfList);
-        executor.submit(SfcProviderServiceFunctionAPI.getPutAll
-                (new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
-
-        Object[] sfcParameters = {sfChain};
-        Class[] sfcParameterTypes = {ServiceFunctionChain.class};
-        executor.submit(SfcProviderServiceChainAPI
-                .getPut(sfcParameters, sfcParameterTypes)).get();
-
-        for (ServiceFunction serviceFunction: sfList) {
-            SfcProviderServiceTypeAPI.createServiceFunctionTypeEntryExecutor(serviceFunction);
-        }
-
         int serviceIndex = 255;
         SfcServiceFunctionSchedulerAPI scheduler = new SfcServiceFunctionRoundRobinSchedulerAPI();
         List<String> serviceFunctionNameArrayList;
@@ -250,26 +281,26 @@ public class SfcServiceFuntionSchedulerAPITest extends AbstractDataBrokerTest {
         List<SftServiceFunctionName> sftNapt44List = serviceFunctionType.getSftServiceFunctionName();
 
         /* First round */
-        serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+        serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
         assertNotNull("Must be not null", serviceFunctionNameArrayList);
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(0), sftFirewallList.get(0).getName());
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(1), sftDpiList.get(0).getName());
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(2), sftNapt44List.get(0).getName());
 
-        serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+        serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
         assertNotNull("Must be not null", serviceFunctionNameArrayList);
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(0), sftFirewallList.get(1).getName());
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(1), sftDpiList.get(1).getName());
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(2), sftNapt44List.get(1).getName());
 
-        serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+        serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
         assertNotNull("Must be not null", serviceFunctionNameArrayList);
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(0), sftFirewallList.get(2).getName());
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(1), sftDpiList.get(2).getName());
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(2), sftNapt44List.get(2).getName());
 
         /* Second round */
-        serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+        serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
         assertNotNull("Must be not null", serviceFunctionNameArrayList);
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(0), sftFirewallList.get(0).getName());
         assertEquals("Must be equal", serviceFunctionNameArrayList.get(1), sftDpiList.get(0).getName());
index 9f8ec73aafa706057c70361b8ff485ad08f2f5a8..54dad272037b741e27ba6ecdb4207413c5e81621 100644 (file)
@@ -83,6 +83,7 @@ public class SfcServiceFunctionShortestPathSchedulerAPITest extends AbstractData
         executor.submit(SfcProviderServiceFunctionAPI.getDeleteAll(new Object[]{}, new Class[]{}));
         executor.submit(SfcProviderServiceForwarderAPI.getDeleteAll(new Object[]{}, new Class[]{}));
         executor.submit(SfcProviderServiceTypeAPI.getDeleteAll(new Object[]{}, new Class[]{}));
+        Thread.sleep(1000); // Wait for real delete
 
         //build SFs
         final String[] LOCATOR_IP_ADDRESS =
@@ -133,6 +134,7 @@ public class SfcServiceFunctionShortestPathSchedulerAPITest extends AbstractData
         sfsBuilder.setServiceFunction(sfList);
         executor.submit(SfcProviderServiceFunctionAPI.getPutAll
                 (new Object[]{sfsBuilder.build()}, new Class[]{ServiceFunctions.class})).get();
+        Thread.sleep(1000); // Wait they are really created
 
         String sfcName = "ShortestPath-unittest-chain-1";
         List<SfcServiceFunction> sfcServiceFunctionList = new ArrayList<>();
@@ -209,6 +211,7 @@ public class SfcServiceFunctionShortestPathSchedulerAPITest extends AbstractData
             ServiceFunctionForwarder sff = sffBuilder.build();
             executor.submit(SfcProviderServiceForwarderAPI.getPut(new Object[]{sff}, new Class[]{ServiceFunctionForwarder.class})).get();
         }
+        Thread.sleep(1000); // Wait they are really created
     }
 
     @After
@@ -225,6 +228,7 @@ public class SfcServiceFunctionShortestPathSchedulerAPITest extends AbstractData
         dataBroker = getDataBroker();
         opendaylightSfc.setDataProvider(dataBroker);
         executor = opendaylightSfc.getExecutor();
+        int maxTries = 10;
 
         /* Must create ServiceFunctionType first */
         for (ServiceFunction serviceFunction : sfList) {
@@ -234,13 +238,21 @@ public class SfcServiceFunctionShortestPathSchedulerAPITest extends AbstractData
         }
 
         for (ServiceFunction serviceFunction : sfList) {
-            Object[] parameters2 = {serviceFunction.getName()};
-            Class[] parameterTypes2 = {String.class};
-            Object result = executor.submit(SfcProviderServiceFunctionAPI
+            maxTries = 10;
+            ServiceFunction sf2 = null;
+            while (maxTries > 0) {
+                Object[] parameters2 = {serviceFunction.getName()};
+                Class[] parameterTypes2 = {String.class};
+                Object result = executor.submit(SfcProviderServiceFunctionAPI
                     .getRead(parameters2, parameterTypes2)).get();
-            ServiceFunction sf2 = (ServiceFunction) result;
-
-            LOG.debug("read ServiceFunction {}", serviceFunction.getName());
+                sf2 = (ServiceFunction) result;
+                maxTries--;
+                if (sf2 != null) {
+                    break;
+                }
+                Thread.sleep(1000);
+            }
+            LOG.debug("SfcServiceFunctionShortestPathSchedulerAPITest: getRead ServiceFunction {} {} times: {}", serviceFunction.getName(), 10 - maxTries, (sf2 != null) ? "Successful" : "Failed");
             assertNotNull("Must be not null", sf2);
             assertEquals("Must be equal", sf2.getName(), serviceFunction.getName());
             assertEquals("Must be equal", sf2.getType(), serviceFunction.getType());
@@ -270,7 +282,7 @@ public class SfcServiceFunctionShortestPathSchedulerAPITest extends AbstractData
         int serviceIndex = 255;
 
         SfcServiceFunctionShortestPathSchedulerAPI scheduler = new SfcServiceFunctionShortestPathSchedulerAPI();
-        List<String> serviceFunctionNameArrayList = scheduler.scheduleServiceFuntions(sfChain, serviceIndex);
+        List<String> serviceFunctionNameArrayList = scheduler.scheduleServiceFunctions(sfChain, serviceIndex);
         assertNotNull("Must be not null", serviceFunctionNameArrayList);
 
         Object[] parametersHop = {serviceFunctionNameArrayList.get(0)};