BwProvisionerSimple extends BwProvisioner { @Override public void deallocateBwForVm(Vm vm) { if (getBwTable().containsKey(vm.getUid())) { long amountFreed = getBwTable().remove(vm.getUid()); setAvailableBw(getAvailableBw() + amountFreed); vm.setCurrentAllocatedBw(0); } } BwProvisionerSimple(long bw); @Override boolean allocateBwForVm(Vm vm, long bw); @Override long getAllocatedBwForVm(Vm vm); @Override void deallocateBwForVm(Vm vm); @Override void deallocateBwForAllVms(); @Override boolean isSuitableForVm(Vm vm, long bw);  }
@Test public void testDeallocateBwForVm() { Vm vm1 = new Vm(0, 0, 0, 0, 0, BW / 2, 0, "", null); Vm vm2 = new Vm(1, 0, 0, 0, 0, BW / 2, 0, "", null); assertEquals(0, vm1.getCurrentAllocatedBw()); assertEquals(0, vm2.getCurrentAllocatedBw()); assertTrue(bwProvisioner.isSuitableForVm(vm1, BW / 2)); assertTrue(bwProvisioner.allocateBwForVm(vm1, BW / 2)); assertEquals(BW / 2, bwProvisioner.getAvailableBw()); bwProvisioner.deallocateBwForVm(vm1); assertEquals(BW, bwProvisioner.getAvailableBw()); assertTrue(bwProvisioner.isSuitableForVm(vm1, BW / 2)); assertTrue(bwProvisioner.allocateBwForVm(vm1, BW / 2)); assertTrue(bwProvisioner.isSuitableForVm(vm2, BW / 2)); assertTrue(bwProvisioner.allocateBwForVm(vm2, BW / 2)); assertEquals(0, bwProvisioner.getAvailableBw()); bwProvisioner.deallocateBwForVm(vm1); bwProvisioner.deallocateBwForVm(vm2); assertEquals(BW, bwProvisioner.getAvailableBw()); assertEquals(0, vm1.getCurrentAllocatedBw()); assertEquals(0, vm2.getCurrentAllocatedBw()); }