Commit 64e2baa6 authored by Kaio Oliveira's avatar Kaio Oliveira
Browse files

Fix VmsFragmentation and HostFragmentation tests

These two tests are now testing our AllocationPolicy correctly.
parent 7972b7f6
......@@ -36,71 +36,87 @@ public class VmAllocationPolicyMigrationSlaTest {
@Before
public void setUp() {
Vm vm1 = createMockedVm(1, 0.1, 0.1, 0.9, 0.5);
Host h1 = createMockedHost(1, 2, vm1);
Vm vm2 = createMockedVm(2, 0.1, 0.1, 0.5, 0.5);
Host h2 = createMockedHost(2, 2, vm2);
List<Host> hosts = new ArrayList<>();
hosts.add(h1);
hosts.add(h2);
Datacenter datacenter = createMockedDatacenter(hosts);
VmAllocationPolicy ap = new VmAllocationPolicySimple();
policy = new VmAllocationPolicyMigrationSla(ap, MIGRATION_TIME);
policy.setDatacenter(datacenter);
}
@Test
public void getVmsFragmentationTest() {
Vm vm1 = createMockedVm(1, 0.1, 0.1, 0.9, 0.5);
Vm vm2 = createMockedVm(2, 0.1, 0.1, 0.5, 0.5);
public void getVmFragmentationTest() {
Vm vm1 = createMockedVmWithIops(1, 0.1, 0.1, 0.1, 0.5, 900, 1000);
Vm vm2 = createMockedVmWithIops(2, 0.1, 0.1, 0.5, 0.5, 500, 1000);
Vm vm3 = createMockedVmWithIops(3, 0.1, 0.1, 1.0, 0.5, 0, 1000);
Vm vm4 = createMockedVmWithIops(4, 0.1, 0.1, 0.0, 0.5, 1000, 1000);
double vmFragmentation1 = policy.getVmFragmentation(vm1);
double vmFragmentation2 = policy.getVmFragmentation(vm2);
assertEquals(vm1.getIopsPercentUsage() - vm1.getIops().getCapacity(), vmFragmentation1, 2);
assertEquals(vm2.getIopsPercentUsage() - vm2.getIops().getCapacity(), vmFragmentation2, 2);
}
double vmFragmentation3 = policy.getVmFragmentation(vm3);
double vmFragmentation4 = policy.getVmFragmentation(vm4);
@Test
public void migrateVmFromHeavenToHell() {
throw new NotImplementedException("TODO");
assertEquals(vm1.getIops().getCapacity() - (vm1.getIopsPercentUsage() * vm1.getIops().getCapacity()), vmFragmentation1, 1);
assertEquals(vm2.getIops().getCapacity() - (vm2.getIopsPercentUsage() * vm2.getIops().getCapacity()), vmFragmentation2, 1);
assertEquals(vm3.getIops().getCapacity() - (vm3.getIopsPercentUsage() * vm3.getIops().getCapacity()), vmFragmentation3, 1);
assertEquals(vm4.getIops().getCapacity() - (vm4.getIopsPercentUsage() * vm4.getIops().getCapacity()), vmFragmentation4, 1);
}
@Test
public void migrateVmFromHellToHeaven() {
throw new NotImplementedException("TODO");
public void getHostFragmentation() {
Vm vm1 = createMockedVmWithIops(1, 0.1, 0.1, 0.1, 0.5, 900, 1000);
Vm vm2 = createMockedVmWithIops(2, 0.1, 0.1, 0.5, 0.5, 500, 1000);
Vm vm3 = createMockedVmWithIops(3, 0.1, 0.1, 1.0, 0.5, 0, 1000);
Vm vm4 = createMockedVmWithIops(4, 0.1, 0.1, 0.0, 0.5, 1000, 1000);
Host h1 = createMockedHostWithIops(1, 2, vm1, 900, 1000, 0.1);
Host h2 = createMockedHostWithIops(2, 2, vm2, 500, 1000, 0.5);
Host h3 = createMockedHostWithIops(3, 2, vm3, 0, 1000, 1.0);
Host h4 = createMockedHostWithIops(4, 2, vm4, 1000, 1000, 0.0);
double hostFragmentation1 = policy.getHostFragmentation(h1);
double hostFragmentation2 = policy.getHostFragmentation(h2);
double hostFragmentation3 = policy.getHostFragmentation(h3);
double hostFragmentation4 = policy.getHostFragmentation(h4);
assertEquals(h1.getIops().getCapacity() - (h1.getIops().getPercentUtilization() * h1.getIops().getCapacity()), hostFragmentation1, 1);
assertEquals(h2.getIops().getCapacity() - (h2.getIops().getPercentUtilization() * h2.getIops().getCapacity()), hostFragmentation2, 1);
assertEquals(h3.getIops().getCapacity() - (h3.getIops().getPercentUtilization() * h3.getIops().getCapacity()), hostFragmentation3, 1);
assertEquals(h4.getIops().getCapacity() - (h4.getIops().getPercentUtilization() * h4.getIops().getCapacity()), hostFragmentation4, 1);
}
private Vm createMockedVm(int id, double cpuUsage, double ramUsage, double iopsUsage, double bwUsage) {
private Vm createMockedVmWithIops(int id, double cpuUsage, double ramUsage,
double iopsUsage, double bwUsage,
long availableResource, long iopsCapacity) {
VmSimple vm = EasyMock.createMock(VmSimple.class);
Iops iops = EasyMock.createMock(Iops.class);
EasyMock.expect(vm.getId()).andReturn(id).anyTimes();
EasyMock.expect(vm.getCpuPercentUsage()).andReturn(cpuUsage).anyTimes();
EasyMock.expect(vm.getCurrentRequestedMaxMips()).andReturn((double) (HOST_MIPS / 2)).anyTimes();
EasyMock.expect(vm.getRamPercentUsage()).andReturn(ramUsage).anyTimes();
EasyMock.expect(vm.getCurrentAllocatedRam()).andReturn((long) (HOST_RAM / 2)).anyTimes();
EasyMock.expect(vm.getIopsPercentUsage()).andReturn(iopsUsage).anyTimes();
EasyMock.expect(vm.getCurrentAllocatedIops()).andReturn((long) (HOST_IOPS / 2)).anyTimes();
EasyMock.expect(vm.getBwPercentUsage()).andReturn(bwUsage).anyTimes();
EasyMock.expect(vm.getCurrentAllocatedBw()).andReturn((long) (HOST_BW / 2)).anyTimes();
EasyMock.expect(iops.getAvailableResource()).andReturn(availableResource).anyTimes();
EasyMock.expect(iops.getCapacity()).andReturn(iopsCapacity).anyTimes();
EasyMock.expect(vm.getIops()).andReturn(iops).anyTimes();
EasyMock.replay(iops);
EasyMock.replay(vm);
return vm;
}
private Host createMockedHost(int id, int pesNumber, Vm vm) {
private Host createMockedHostWithIops(int id, int pesNumber, Vm vm, long availableResource, long iopsCapacity, double iopsUsage) {
Host host = EasyMock.createMock(Host.class);
Iops iops = EasyMock.createMock(Iops.class);
EasyMock.expect(host.getId()).andReturn(id).anyTimes();
EasyMock.expect(host.getNumberOfPes()).andReturn((long) pesNumber).anyTimes();
EasyMock.expect(host.getMips()).andReturn((double) HOST_MIPS).anyTimes();
EasyMock.expect(host.getRam()).andReturn(new Ram(HOST_RAM)).anyTimes();
EasyMock.expect(host.getIops()).andReturn(new Iops(HOST_IOPS)).anyTimes();
EasyMock.expect(iops.getAvailableResource()).andReturn(availableResource).anyTimes();
EasyMock.expect(iops.getCapacity()).andReturn(iopsCapacity).anyTimes();
EasyMock.expect(iops.getPercentUtilization()).andReturn(iopsUsage).anyTimes();
EasyMock.expect(host.getIops()).andReturn(iops).anyTimes();
EasyMock.expect(host.getBw()).andReturn(new Bandwidth(HOST_BW)).anyTimes();
EasyMock.expect(host.getNumberOfWorkingPes()).andReturn((long) 2).anyTimes();
......@@ -108,6 +124,8 @@ public class VmAllocationPolicyMigrationSlaTest {
vms.add(vm);
EasyMock.expect(host.getVmList()).andReturn(vms);
EasyMock.replay(iops);
EasyMock.replay(host);
return host;
......@@ -121,4 +139,13 @@ public class VmAllocationPolicyMigrationSlaTest {
return datacenter;
}
private Iops createMockedIopsResource(long capacity) {
Iops iops = EasyMock.createMock(Iops.class);
EasyMock.expect(iops).andReturn(new Iops(capacity)).anyTimes();
EasyMock.replay(iops);
return iops;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment