RamProvisionerSimple extends RamProvisioner { @Override public int getAllocatedRamForVm(Vm vm) { if (getRamTable().containsKey(vm.getUid())) { return getRamTable().get(vm.getUid()); } return 0; } RamProvisionerSimple(int availableRam); @Override boolean allocateRamForVm(Vm vm, int ram); @Override int getAllocatedRamForVm(Vm vm); @Override void deallocateRamForVm(Vm vm); @Override void deallocateRamForAllVms(); @Override boolean isSuitableForVm(Vm vm, int ram);  }
@Test public void testGetAllocatedRamForVm() { Vm vm1 = new Vm(0, 0, 0, 0, RAM / 2, 0, 0, "", null); Vm vm2 = new Vm(1, 0, 0, 0, RAM, 0, 0, "", null); assertTrue(ramProvisioner.isSuitableForVm(vm1, RAM / 2)); assertTrue(ramProvisioner.allocateRamForVm(vm1, RAM / 2)); assertEquals(RAM / 2, ramProvisioner.getAllocatedRamForVm(vm1)); assertFalse(ramProvisioner.isSuitableForVm(vm2, RAM)); assertFalse(ramProvisioner.allocateRamForVm(vm2, RAM)); assertEquals(0, ramProvisioner.getAllocatedRamForVm(vm2)); assertTrue(ramProvisioner.isSuitableForVm(vm2, RAM / 4)); assertTrue(ramProvisioner.allocateRamForVm(vm2, RAM / 4)); assertEquals(RAM / 4, ramProvisioner.getAllocatedRamForVm(vm2)); assertTrue(ramProvisioner.isSuitableForVm(vm2, RAM / 2)); assertTrue(ramProvisioner.allocateRamForVm(vm2, RAM / 2)); assertEquals(RAM / 2, ramProvisioner.getAllocatedRamForVm(vm2)); }