PeProvisionerSimple extends PeProvisioner { @Override public boolean allocateMipsForVm(Vm vm, double mips) { return allocateMipsForVm(vm.getUid(), mips); } PeProvisionerSimple(double availableMips); @Override boolean allocateMipsForVm(Vm vm, double mips); @Override boolean allocateMipsForVm(String vmUid, double mips); @Override boolean allocateMipsForVm(Vm vm, List<Double> mips); @Override void deallocateMipsForAllVms(); @Override double getAllocatedMipsForVmByVirtualPeId(Vm vm, int peId); @Override List<Double> getAllocatedMipsForVm(Vm vm); @Override double getTotalAllocatedMipsForVm(Vm vm); @Override void deallocateMipsForVm(Vm vm);  }
@Test public void testAllocateMipsForVm() { Vm vm1 = new Vm(0, 0, MIPS / 2, 1, 0, 0, 0, "", null); Vm vm2 = new Vm(1, 0, MIPS / 2, 1, 0, 0, 0, "", null); Vm vm3 = new Vm(2, 0, MIPS / 2, 2, 0, 0, 0, "", null); assertTrue(peProvisioner.allocateMipsForVm(vm1, MIPS / 2)); assertEquals(MIPS / 2, peProvisioner.getAvailableMips(), 0); assertEquals(MIPS / 2, peProvisioner.getTotalAllocatedMips(), 0); assertEquals(0.5, peProvisioner.getUtilization(), 0); assertTrue(peProvisioner.allocateMipsForVm(vm2, MIPS / 4)); assertEquals(MIPS / 4, peProvisioner.getAvailableMips(), 0); assertEquals(MIPS * 3 / 4, peProvisioner.getTotalAllocatedMips(), 0); assertEquals(0.75, peProvisioner.getUtilization(), 0); assertFalse(peProvisioner.allocateMipsForVm(vm3, MIPS / 2)); assertEquals(MIPS / 4, peProvisioner.getAvailableMips(), 0); assertEquals(MIPS * 3 / 4, peProvisioner.getTotalAllocatedMips(), 0); assertEquals(0.75, peProvisioner.getUtilization(), 0); peProvisioner.deallocateMipsForVm(vm1); peProvisioner.deallocateMipsForVm(vm2); assertTrue(peProvisioner.allocateMipsForVm(vm3, MIPS / 4)); assertEquals(MIPS * 3 / 4, peProvisioner.getAvailableMips(), 0); assertEquals(MIPS / 4, peProvisioner.getTotalAllocatedMips(), 0); assertEquals(0.25, peProvisioner.getUtilization(), 0); assertTrue(peProvisioner.allocateMipsForVm(vm3, MIPS / 4)); assertEquals(MIPS / 2, peProvisioner.getAvailableMips(), 0); assertEquals(MIPS / 2, peProvisioner.getTotalAllocatedMips(), 0); assertEquals(0.5, peProvisioner.getUtilization(), 0); ArrayList<Double> mipsArray = new ArrayList<Double>(); mipsArray.add(MIPS / 2.0); mipsArray.add(MIPS / 2.0); assertTrue(peProvisioner.allocateMipsForVm(vm3, mipsArray)); assertEquals(0, peProvisioner.getAvailableMips(), 0); assertEquals(MIPS, peProvisioner.getTotalAllocatedMips(), 0); assertEquals(1, peProvisioner.getUtilization(), 0); }