SfcGeniusInterfaceServiceManager implements ISfcGeniusInterfaceServiceHandler { @Override public void bindInterfacesOfServiceFunction(String sfName) { ReadWriteTransaction readWriteTransaction = dataBroker.newReadWriteTransaction(); SfcGeniusSfReader sfReader = getSfcGeniusSfReader(readWriteTransaction); SfcGeniusServiceHandler serviceHandler = getSfcGeniusServiceHandler(readWriteTransaction); LOG.debug("Bind interfaces of service function {}", sfName); sfReader.readInterfacesOfSf(new SfName(sfName)) .thenCompose(interfaceList -> CompletableFuture.allOf( interfaceList.stream() .map(serviceHandler::bindToInterface) .toArray(size -> new CompletableFuture<?>[size]))) .thenCompose((aVoid) -> SfcGeniusUtils.toCompletableFuture(readWriteTransaction.submit(), executor)) .exceptionally(exception -> { if (exception.getCause() instanceof SfcGeniusRuntimeException) { LOG.error("Error binding to interfaces of service function {}", sfName, exception.getCause()); return null; } throw new CompletionException(exception.getCause()); }) .join(); } SfcGeniusInterfaceServiceManager(DataBroker dataBroker,
                                            RpcProviderRegistry rpcProviderRegistry,
                                            Executor executor); @Override void bindInterfacesOfServiceFunction(String sfName); @Override void unbindInterfacesOfServiceFunction(String sfName); @Override void interfaceStateUp(String interfaceName, BigInteger dpnId); @Override void interfaceStateDown(String interfaceName, BigInteger nodeId);  }
@Test public void bindInterfacesOfServiceFunction() throws Exception { when(sfcGeniusSfReader.readInterfacesOfSf(any())) .thenReturn(CompletableFuture.completedFuture(Arrays.asList("I1", "I2"))); sfcGeniusInterfaceServiceManager.bindInterfacesOfServiceFunction("SF1"); verify(sfcGeniusSfReader).readInterfacesOfSf(new SfName("SF1")); verify(sfcGeniusServiceHandler).bindToInterface("I1"); verify(sfcGeniusServiceHandler).bindToInterface("I2"); verify(readWriteTransaction).submit(); }
@Test public void bindInterfacesOfServiceFunctionNoInterfaces() throws Exception { when(sfcGeniusSfReader.readInterfacesOfSf(any())) .thenReturn(CompletableFuture.completedFuture(Collections.emptyList())); sfcGeniusInterfaceServiceManager.bindInterfacesOfServiceFunction("SF1"); verify(sfcGeniusSfReader).readInterfacesOfSf(new SfName("SF1")); verifyZeroInteractions(sfcGeniusServiceHandler); }
@Test public void bindInterfacesOfServiceFunctionErrorNoException() throws Exception { when(sfcGeniusSfReader.readInterfacesOfSf(any())) .thenReturn(CompletableFuture.completedFuture(Arrays.asList("IF1", "IF2"))); when(readWriteTransaction.submit()).thenThrow(new SfcGeniusRuntimeException(new Throwable())); sfcGeniusInterfaceServiceManager.bindInterfacesOfServiceFunction("SF1"); }
@Test(expected = CompletionException.class) public void bindInterfacesOfServiceFunctionUnknownException() throws Exception { when(sfcGeniusSfReader.readInterfacesOfSf(any())) .thenReturn(CompletableFuture.completedFuture(Arrays.asList("IF1", "IF2"))); when(readWriteTransaction.submit()).thenThrow(new RuntimeException("")); sfcGeniusInterfaceServiceManager.bindInterfacesOfServiceFunction("SF1"); }