SfcGeniusServiceHandler { CompletableFuture<Void> bindToInterface(String interfaceName) { SfcGeniusIfStateReader ifStateReader = getIfStateReader(); SfcGeniusDpnIfWriter dpnIfWriter = getDpnIfWriter(); SfcGeniusTsaWriter tsaWriter = getTsaWriter(); SfcGeniusBoundServiceWriter boundServiceWriter = getBoundServiceWriter(); LOG.debug("Bind SFC service to interface {}", interfaceName); return CompletableFuture.allOf( ifStateReader.readDpnId(interfaceName) .thenCompose(dpnId -> dpnIfWriter.addInterface(dpnId, interfaceName)) .thenCompose(optionalOldDpn -> optionalOldDpn .map(tsaWriter::createTerminatingServiceAction) .orElse(CompletableFuture.completedFuture(null))), boundServiceWriter.bindService(interfaceName) ); } SfcGeniusServiceHandler(Map<BigInteger, Set<String>> dpnInterfaces,
                            ReadWriteTransaction transaction,
                            RpcProviderRegistry rpcProviderRegistry,
                            Executor executor);   }
@Test public void bindToInterfaceFirstOfDpn() throws Exception { String interfaceName = "IF1"; BigInteger dpnId = BigInteger.valueOf(17); Short offset = 130; when(sfcGeniusIfStateReader.readDpnId(interfaceName)).thenReturn(CompletableFuture.completedFuture(dpnId)); when(sfcGeniusDpnIfWriter.addInterface(dpnId, interfaceName)) .thenReturn(CompletableFuture.completedFuture(Optional.of(dpnId))); sfcGeniusServiceHandler.bindToInterface(interfaceName); verify(sfcGeniusTsaWriter).createTerminatingServiceAction(dpnId); verify(sfcGeniusBoundServiceWriter).bindService(interfaceName); }
@Test public void bindToInterface() throws Exception { String interfaceName = "IF1"; BigInteger dpnId = BigInteger.valueOf(18); Short offset = 130; when(sfcGeniusIfStateReader.readDpnId(interfaceName)).thenReturn(CompletableFuture.completedFuture(dpnId)); when(sfcGeniusDpnIfWriter.addInterface(dpnId, interfaceName)) .thenReturn(CompletableFuture.completedFuture(Optional.empty())); sfcGeniusServiceHandler.bindToInterface(interfaceName); verify(sfcGeniusBoundServiceWriter).bindService(interfaceName); verifyZeroInteractions(sfcGeniusTsaWriter); }