@Test public void testSendBandWidthRestrictions() throws Exception { BandwidthRestriction mockBandwidthRestriction = mock(BandwidthRestriction.class); long maxBandwidth = 23L; int maxBandwidthPercent = 34; when(mockBandwidthRestriction.getBandwidth()).thenReturn(maxBandwidth); when(mockHarvestCoordinatorDao.getBandwidthRestriction(anyString(), any(Date.class))).thenReturn(mockBandwidthRestriction); TargetInstance mockTargetInstance = mock(TargetInstance.class); ArrayList<TargetInstance> running = Lists.newArrayList(mockTargetInstance); when(mockTargetInstanceDao.findTargetInstances(any(TargetInstanceCriteria.class))).thenReturn(running); HashMap<Long, TargetInstance> map = Maps.newHashMap(); map.put(1L, mockTargetInstance); when(mockBandwidthCalculator.calculateBandwidthAllocation(running, maxBandwidth, maxBandwidthPercent)).thenReturn(map ); underTest.setMaxBandwidthPercent(maxBandwidthPercent); underTest.sendBandWidthRestrictions(); verify(mockTargetInstanceDao).findTargetInstances(any(TargetInstanceCriteria.class)); verify(mockBandwidthCalculator).calculateBandwidthAllocation(running, maxBandwidth, maxBandwidthPercent); verify(mockHarvestAgentManager).restrictBandwidthFor(mockTargetInstance); }
@Override public void sendBandWidthRestrictions() { HashMap<Long, TargetInstance> running = calculateBandwidthAllocation(); for (TargetInstance ti : running.values()) { harvestAgentManager.restrictBandwidthFor(ti); } }
HarvestBandwidthManagerImpl implements HarvestBandwidthManager { @Override public void sendBandWidthRestrictions() { HashMap<Long, TargetInstance> running = calculateBandwidthAllocation(); for (TargetInstance ti : running.values()) { harvestAgentManager.restrictBandwidthFor(ti); } } }
HarvestBandwidthManagerImpl implements HarvestBandwidthManager { @Override public void sendBandWidthRestrictions() { HashMap<Long, TargetInstance> running = calculateBandwidthAllocation(); for (TargetInstance ti : running.values()) { harvestAgentManager.restrictBandwidthFor(ti); } }  }
HarvestBandwidthManagerImpl implements HarvestBandwidthManager { @Override public void sendBandWidthRestrictions() { HashMap<Long, TargetInstance> running = calculateBandwidthAllocation(); for (TargetInstance ti : running.values()) { harvestAgentManager.restrictBandwidthFor(ti); } }  @Override void sendBandWidthRestrictions(); @Override HashMap<Long, TargetInstance> calculateBandwidthAllocation(TargetInstance aTargetInstance); @Override HashMap<Long, TargetInstance> calculateBandwidthAllocation(); @Override long getCurrentGlobalMaxBandwidth(); @Override boolean isMiniumBandwidthAvailable(QueuedTargetInstanceDTO aTargetInstance); @Override boolean isMiniumBandwidthAvailable(TargetInstance aTargetInstance); @Override synchronized void checkForBandwidthTransition(); @Override boolean isHarvestOptimizationAllowed(); @Override BandwidthRestriction getBandwidthRestriction(Long oid); @Override void saveOrUpdate(BandwidthRestriction bandwidthRestriction); @Override void delete(BandwidthRestriction bandwidthRestriction); @Override BandwidthRestriction getBandwidthRestriction(String aDay, Date aTime); @Override HashMap<String, List<BandwidthRestriction>> getBandwidthRestrictions(); @Override int getMinimumBandwidth(); @Override void setMinimumBandwidth(int minimumBandwidth); @Override int getMaxBandwidthPercent(); @Override void setMaxBandwidthPercent(int maxBandwidthPercent); void setHarvestCoordinatorDao(HarvestCoordinatorDAO harvestCoordinatorDao); void setHarvestAgentManager(HarvestAgentManager harvestAgentManager); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); void setAuditor(Auditor auditor); void setBandwidthCalculator(BandwidthCalculator bandwidthCalculator); }
HarvestBandwidthManagerImpl implements HarvestBandwidthManager { @Override public void sendBandWidthRestrictions() { HashMap<Long, TargetInstance> running = calculateBandwidthAllocation(); for (TargetInstance ti : running.values()) { harvestAgentManager.restrictBandwidthFor(ti); } }  @Override void sendBandWidthRestrictions(); @Override HashMap<Long, TargetInstance> calculateBandwidthAllocation(TargetInstance aTargetInstance); @Override HashMap<Long, TargetInstance> calculateBandwidthAllocation(); @Override long getCurrentGlobalMaxBandwidth(); @Override boolean isMiniumBandwidthAvailable(QueuedTargetInstanceDTO aTargetInstance); @Override boolean isMiniumBandwidthAvailable(TargetInstance aTargetInstance); @Override synchronized void checkForBandwidthTransition(); @Override boolean isHarvestOptimizationAllowed(); @Override BandwidthRestriction getBandwidthRestriction(Long oid); @Override void saveOrUpdate(BandwidthRestriction bandwidthRestriction); @Override void delete(BandwidthRestriction bandwidthRestriction); @Override BandwidthRestriction getBandwidthRestriction(String aDay, Date aTime); @Override HashMap<String, List<BandwidthRestriction>> getBandwidthRestrictions(); @Override int getMinimumBandwidth(); @Override void setMinimumBandwidth(int minimumBandwidth); @Override int getMaxBandwidthPercent(); @Override void setMaxBandwidthPercent(int maxBandwidthPercent); void setHarvestCoordinatorDao(HarvestCoordinatorDAO harvestCoordinatorDao); void setHarvestAgentManager(HarvestAgentManager harvestAgentManager); void setTargetInstanceDao(TargetInstanceDAO targetInstanceDao); void setAuditor(Auditor auditor); void setBandwidthCalculator(BandwidthCalculator bandwidthCalculator);  }