PeProvisionerSimple extends PeProvisioner { @Override public List<Double> getAllocatedMipsForVm(Vm vm) { if (getPeTable().containsKey(vm.getUid())) { return getPeTable().get(vm.getUid()); } return null; } 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 testGetAllocatedMipsForVm() { 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); assertNull(peProvisioner.getAllocatedMipsForVm(vm1)); assertEquals(0, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm1, 0), 0); assertTrue(peProvisioner.allocateMipsForVm(vm1, MIPS / 2)); ArrayList<Double> allocatedMips1 = new ArrayList<Double>(); allocatedMips1.add(MIPS / 2); assertTrue(allocatedMips1.equals(peProvisioner.getAllocatedMipsForVm(vm1))); assertEquals(MIPS / 2, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm1, 0), 0); assertEquals(0, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm1, 1), 0); assertEquals(MIPS / 2, peProvisioner.getTotalAllocatedMipsForVm(vm1), 0); assertTrue(peProvisioner.allocateMipsForVm(vm2, MIPS / 4)); ArrayList<Double> allocatedMips2 = new ArrayList<Double>(); allocatedMips2.add(MIPS / 4); assertTrue(allocatedMips2.equals(peProvisioner.getAllocatedMipsForVm(vm2))); assertEquals(MIPS / 4, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm2, 0), 0); assertEquals(MIPS / 4, peProvisioner.getTotalAllocatedMipsForVm(vm2), 0); peProvisioner.deallocateMipsForVm(vm1); peProvisioner.deallocateMipsForVm(vm2); assertTrue(peProvisioner.allocateMipsForVm(vm3, MIPS / 4)); ArrayList<Double> allocatedMips3 = new ArrayList<Double>(); allocatedMips3.add(MIPS / 4); assertTrue(allocatedMips3.equals(peProvisioner.getAllocatedMipsForVm(vm3))); assertEquals(MIPS / 4, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm3, 0), 0); assertEquals(MIPS / 4, peProvisioner.getTotalAllocatedMipsForVm(vm3), 0); assertTrue(peProvisioner.allocateMipsForVm(vm3, MIPS / 4)); allocatedMips3.add(MIPS / 4); assertTrue(allocatedMips3.equals(peProvisioner.getAllocatedMipsForVm(vm3))); assertEquals(MIPS / 4, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm3, 0), 0); assertEquals(MIPS / 4, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm3, 1), 0); assertEquals(MIPS / 2, peProvisioner.getTotalAllocatedMipsForVm(vm3), 0); ArrayList<Double> allocatedMips4 = new ArrayList<Double>(); allocatedMips4.add(MIPS / 2.0); allocatedMips4.add(MIPS); assertFalse(peProvisioner.allocateMipsForVm(vm3, allocatedMips4)); ArrayList<Double> allocatedMips5 = new ArrayList<Double>(); allocatedMips5.add(MIPS / 2.0); allocatedMips5.add(MIPS / 2.0); assertTrue(peProvisioner.allocateMipsForVm(vm3, allocatedMips5)); assertTrue(allocatedMips5.equals(peProvisioner.getAllocatedMipsForVm(vm3))); assertEquals(MIPS / 2, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm3, 0), 0); assertEquals(MIPS / 2, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm3, 1), 0); assertEquals(MIPS, peProvisioner.getTotalAllocatedMipsForVm(vm3), 0); peProvisioner.deallocateMipsForVm(vm1); peProvisioner.deallocateMipsForVm(vm2); peProvisioner.deallocateMipsForVm(vm3); assertNull(peProvisioner.getAllocatedMipsForVm(vm1)); assertNull(peProvisioner.getAllocatedMipsForVm(vm2)); assertNull(peProvisioner.getAllocatedMipsForVm(vm3)); assertEquals(0, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm1, 0), 0); assertEquals(0, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm2, 0), 0); assertEquals(0, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm3, 0), 0); assertEquals(0, peProvisioner.getAllocatedMipsForVmByVirtualPeId(vm3, 1), 0); assertEquals(0, peProvisioner.getTotalAllocatedMipsForVm(vm1), 0); assertEquals(0, peProvisioner.getTotalAllocatedMipsForVm(vm2), 0); assertEquals(0, peProvisioner.getTotalAllocatedMipsForVm(vm3), 0); assertEquals(MIPS, peProvisioner.getAvailableMips(), 0); }