BwProvisionerSimple extends BwProvisioner { @Override public long getAllocatedBwForVm(Vm vm) { if (getBwTable().containsKey(vm.getUid())) { return getBwTable().get(vm.getUid()); } return 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 testGetAllocatedBwforVm() { Vm vm1 = new Vm(0, 0, 0, 0, 0, BW / 2, 0, "", null); Vm vm2 = new Vm(1, 0, 0, 0, 0, BW, 0, "", null); assertTrue(bwProvisioner.isSuitableForVm(vm1, BW / 2)); assertTrue(bwProvisioner.allocateBwForVm(vm1, BW / 2)); assertEquals(BW / 2, bwProvisioner.getAllocatedBwForVm(vm1)); assertFalse(bwProvisioner.isSuitableForVm(vm2, BW)); assertFalse(bwProvisioner.allocateBwForVm(vm2, BW)); assertEquals(0, bwProvisioner.getAllocatedBwForVm(vm2)); assertTrue(bwProvisioner.isSuitableForVm(vm2, BW / 4)); assertTrue(bwProvisioner.allocateBwForVm(vm2, BW / 4)); assertEquals(BW / 4, bwProvisioner.getAllocatedBwForVm(vm2)); assertTrue(bwProvisioner.isSuitableForVm(vm2, BW / 2)); assertTrue(bwProvisioner.allocateBwForVm(vm2, BW / 2)); assertEquals(BW / 2, bwProvisioner.getAllocatedBwForVm(vm2)); }