SfcGeniusServiceHandler { CompletableFuture<Void> unbindFromInterface(String interfaceName) { SfcGeniusIfStateReader ifStateReader = getIfStateReader(); SfcGeniusDpnIfWriter dpnIfWriter = getDpnIfWriter(); SfcGeniusTsaWriter tsaWriter = getTsaWriter(); SfcGeniusBoundServiceWriter boundServiceWriter = getBoundServiceWriter(); LOG.debug("Unbind SFC service from interface {}", interfaceName); return CompletableFuture.allOf( ifStateReader.readDpnId(interfaceName) .thenCompose(dpnId -> dpnIfWriter.removeInterfaceFromDpn(dpnId, interfaceName)) .thenCompose(optionalOldDpn -> optionalOldDpn .map(tsaWriter::removeTerminatingServiceAction) .orElse(CompletableFuture.completedFuture(null))), boundServiceWriter.unbindService(interfaceName) ); } SfcGeniusServiceHandler(Map<BigInteger, Set<String>> dpnInterfaces,
                            ReadWriteTransaction transaction,
                            RpcProviderRegistry rpcProviderRegistry,
                            Executor executor);   }
@Test public void unbindFromInterfaceLastOfDpn() throws Exception { String interfaceName = "IF1"; BigInteger dpnId = BigInteger.valueOf(19); when(sfcGeniusIfStateReader.readDpnId(interfaceName)).thenReturn(CompletableFuture.completedFuture(dpnId)); when(sfcGeniusDpnIfWriter.removeInterfaceFromDpn(dpnId, interfaceName)) .thenReturn(CompletableFuture.completedFuture(Optional.of(dpnId))); sfcGeniusServiceHandler.unbindFromInterface(interfaceName); verify(sfcGeniusTsaWriter).removeTerminatingServiceAction(dpnId); verify(sfcGeniusBoundServiceWriter).unbindService(interfaceName); }
@Test public void unbindFromInterface() throws Exception { String interfaceName = "IF1"; BigInteger dpnId = BigInteger.valueOf(19); when(sfcGeniusIfStateReader.readDpnId(interfaceName)).thenReturn(CompletableFuture.completedFuture(dpnId)); when(sfcGeniusDpnIfWriter.removeInterfaceFromDpn(dpnId, interfaceName)) .thenReturn(CompletableFuture.completedFuture(Optional.empty())); sfcGeniusServiceHandler.unbindFromInterface(interfaceName); verify(sfcGeniusBoundServiceWriter).unbindService(interfaceName); verifyZeroInteractions(sfcGeniusTsaWriter); }