### Question:
BaseResourceAllocationAction extends
        NbTrackableAction<T, S, E, C> { @VisibleForTesting void updateAvailableBandwidth(SwitchId srcSwitch, int srcPort, SwitchId dstSwitch, int dstPort, long allowedOverprovisionedBandwidth, boolean forceToIgnoreBandwidth) throws ResourceAllocationException { long usedBandwidth = flowPathRepository.getUsedBandwidthBetweenEndpoints(srcSwitch, srcPort, dstSwitch, dstPort); log.debug("Updating ISL {}_{}-{}_{} with used bandwidth {}", srcSwitch, srcPort, dstSwitch, dstPort, usedBandwidth); long islAvailableBandwidth = islRepository.updateAvailableBandwidth(srcSwitch, srcPort, dstSwitch, dstPort, usedBandwidth); if (!forceToIgnoreBandwidth && (islAvailableBandwidth + allowedOverprovisionedBandwidth) < 0) { throw new ResourceAllocationException(format("ISL %s_%d-%s_%d was overprovisioned", srcSwitch, srcPort, dstSwitch, dstPort)); } } BaseResourceAllocationAction(PersistenceManager persistenceManager,
                                        int pathAllocationRetriesLimit, int pathAllocationRetryDelay,
                                        PathComputer pathComputer, FlowResourcesManager resourcesManager,
                                        FlowOperationsDashboardLogger dashboardLogger);   }### Answer:
@Test(expected = ResourceAllocationException.class) public void updateAvailableBandwidthFailsOnOverProvisionTest() throws ResourceAllocationException { when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory); when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository); when(repositoryFactory.createIslRepository()).thenReturn(islRepository); when(flowPathRepository.getUsedBandwidthBetweenEndpoints(any(), eq(10), any(), eq(10))) .thenReturn(100L); when(islRepository.updateAvailableBandwidth(any(), eq(10), any(), eq(10), eq(100L))) .thenReturn(-1L); BaseResourceAllocationAction action = Mockito.mock(BaseResourceAllocationAction.class, Mockito.withSettings() .useConstructor(persistenceManager, 3, 3, pathComputer, resourcesManager, dashboardLogger) .defaultAnswer(Mockito.CALLS_REAL_METHODS)); action.updateAvailableBandwidth(new SwitchId(1000), 10, new SwitchId(1000), 10, 0L, false); }
@Test() public void updateAvailableBandwidthIgnorsOverProvisionTest() throws ResourceAllocationException { when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory); when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository); when(repositoryFactory.createIslRepository()).thenReturn(islRepository); when(flowPathRepository.getUsedBandwidthBetweenEndpoints(any(), eq(10), any(), eq(10))) .thenReturn(100L); when(islRepository.updateAvailableBandwidth(any(), eq(10), any(), eq(10), eq(100L))) .thenReturn(-1L); BaseResourceAllocationAction action = Mockito.mock(BaseResourceAllocationAction.class, Mockito.withSettings() .useConstructor(persistenceManager, 3, 3, pathComputer, resourcesManager, dashboardLogger) .defaultAnswer(Mockito.CALLS_REAL_METHODS)); action.updateAvailableBandwidth(new SwitchId(1000), 10, new SwitchId(1000), 10, 0L, true); }