Commit d7acc47f authored by Eduardo Falcão's avatar Eduardo Falcão
Browse files

tests for getVmsWithEnoughCredit

parent 190bf4ce
......@@ -186,8 +186,8 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
for (Host h : looseSlaHosts) {
for (Vm vm : h.getVmList()) {
if (SLAMonitor.getVmViolationTime(vm, clock) + MIGRATION_TIME <
SLAMonitor.getMaximumAllowedSlaViolationTime(vm)) {
if (SLAMonitor.getVmViolationTime(vm, clock) + MIGRATION_TIME <=
SLAMonitor.getMaximumAllowedSlaViolationTime(vm)) {
candidateVmsToMigrate.add(vm);
}
}
......@@ -270,6 +270,10 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
@Override
public Optional<Host> findHostForVm(Vm vm) {
return allocationPolicy.findHostForVm(vm);
}
}
public int getMIGRATION_TIME() {
return MIGRATION_TIME;
}
}
......@@ -7,6 +7,7 @@ import java.util.List;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicy;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.core.Simulation;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.provisioners.ResourceProvisioner;
......@@ -17,6 +18,11 @@ import org.cloudbus.cloudsim.resources.Iops;
import org.cloudbus.cloudsim.resources.Ram;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.vms.VmSimple;
import org.cloudbus.cloudsim.vms.VmStateHistoryEntry;
import org.cloudsimplus.slametrics.SLAMonitor;
import org.cloudsimplus.slametrics.SlaContract;
import org.cloudsimplus.slametrics.SlaMetric;
import org.cloudsimplus.slametrics.SlaMetricDimension;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
......@@ -44,11 +50,16 @@ public class VmAllocationPolicyMigrationSlaTest {
policy = new VmAllocationPolicyMigrationSla(ap, MIGRATION_TIME);
}
private Datacenter createMockedDatacenter(List<Host> hosts) {
private Datacenter createMockedDatacenter(List<Host> hosts, double time) {
Datacenter datacenter = EasyMock.createMock(Datacenter.class);
EasyMock.expect(datacenter.getHostList()).andReturn(hosts).anyTimes();
Simulation sim = EasyMock.createMock(Simulation.class);
EasyMock.expect(datacenter.getSimulation()).andReturn(sim).anyTimes();
EasyMock.expect(sim.clock()).andReturn(time).anyTimes();
EasyMock.replay(datacenter);
EasyMock.replay(sim);
return datacenter;
}
......@@ -107,6 +118,65 @@ public class VmAllocationPolicyMigrationSlaTest {
return vm;
}
@Test
public void testGetVmsWithEnoughCredit() {
final long MINIMUM_IOPS = 500;
final double MINIMUM_AVAILABILITY = 99.9;
SlaContract contract = new SlaContract();
SlaMetricDimension iopsMetricDimension = new SlaMetricDimension(MINIMUM_IOPS);
iopsMetricDimension.setName("minValue");
SlaMetric iopsMetric = new SlaMetric("IOPSProvisioned");
iopsMetric.getDimensions().add(iopsMetricDimension);
contract.getMetrics().add(iopsMetric);
SlaMetricDimension availabilityMetricDimension = new SlaMetricDimension(MINIMUM_AVAILABILITY);
availabilityMetricDimension.setName("minValue");
SlaMetric availabilityMetric = new SlaMetric("Availability");
availabilityMetric.getDimensions().add(availabilityMetricDimension);
contract.getMetrics().add(availabilityMetric);
Vm vm0 = new VmSimple(0, 0);
vm0.setContract(contract);
vm0.addStateHistoryEntry(new VmStateHistoryEntry(0,0,0,MINIMUM_IOPS,0,false)); //allocatedIops is MINIMUM_IOPS
vm0.addStateHistoryEntry(new VmStateHistoryEntry(SLAMonitor.getMaximumAllowedSlaViolationTime(vm0),0,0,MINIMUM_IOPS,0,false));
Host h0 = createMockedHostWithIops(1, 0, vm0, 0, 0, 0, null);
List<Host> hosts = new ArrayList<Host>();
hosts.add(h0);
Datacenter dc = createMockedDatacenter(hosts,SLAMonitor.getMaximumAllowedSlaViolationTime(vm0));
policy.setDatacenter(dc);
assertEquals(1, policy.getVmsWithEnoughCredit(hosts).size());
vm0 = new VmSimple(0, 0);
vm0.setContract(contract);
vm0.addStateHistoryEntry(new VmStateHistoryEntry(0,0,0,MINIMUM_IOPS-1,0,false)); //allocatedIops is MINIMUM_IOPS
vm0.addStateHistoryEntry(new VmStateHistoryEntry(SLAMonitor.getMaximumAllowedSlaViolationTime(vm0),0,0,MINIMUM_IOPS-1,0,false));
h0 = createMockedHostWithIops(1, 0, vm0, 0, 0, 0, null);
hosts.clear();
hosts.add(h0);
dc = createMockedDatacenter(hosts,SLAMonitor.getMaximumAllowedSlaViolationTime(vm0));
policy.setDatacenter(dc);
assertEquals(0, policy.getVmsWithEnoughCredit(hosts).size());
vm0 = new VmSimple(0, 0);
vm0.setContract(contract);
vm0.addStateHistoryEntry(new VmStateHistoryEntry(0,0,0,MINIMUM_IOPS-1,0,false)); //allocatedIops is MINIMUM_IOPS
vm0.addStateHistoryEntry(new VmStateHistoryEntry(SLAMonitor.getMaximumAllowedSlaViolationTime(vm0)-policy.getMIGRATION_TIME(),0,0,MINIMUM_IOPS,0,false));
h0 = createMockedHostWithIops(1, 0, vm0, 0, 0, 0, null);
hosts.clear();
hosts.add(h0);
dc = createMockedDatacenter(hosts,SLAMonitor.getMaximumAllowedSlaViolationTime(vm0));
policy.setDatacenter(dc);
assertEquals(1, policy.getVmsWithEnoughCredit(hosts).size());
}
@Test
public void testSortVmDescending() {
Vm vm1 = createMockedVmWithIops(1, 0.0, 0.0, 0.0, 0.0, 900, 0); //available = 900
......@@ -225,7 +295,7 @@ public class VmAllocationPolicyMigrationSlaTest {
hosts.add(createMockedHostWithIops(i, 0, null, 0, 0, 0.0, new ResourceProvisionerShared()));
}
Datacenter dc = createMockedDatacenter(hosts);
Datacenter dc = createMockedDatacenter(hosts,0);
policy.setDatacenter(dc);
assertEquals(NUM_HEAVEN_HOSTS, policy.getHostsWithLooseSla().size());
......
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