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

test sla migration

parent 09f21a7b
......@@ -82,7 +82,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
}
//filter heaven hosts
List<Host> looseSlaHosts = getHostsWithLooseSla(getDatacenter());
List<Host> looseSlaHosts = getHostsWithLooseSla();
//get all vms from heaven hosts and sort vms from higher to lower fragmentation
List<Vm> vmsDescendingFragmentation = new ArrayList<Vm>();
......@@ -90,7 +90,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
sort(vmsDescendingFragmentation);
//filter hell hosts and sort hell hosts ascending by fragmentation
List<Host> tightSlaHosts = getHostsWithTightSla(getDatacenter());
List<Host> tightSlaHosts = getHostsWithTightSla();
sort(tightSlaHosts);
//update current fragmentation
......@@ -231,8 +231,8 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* Get hosts in which the SLA are delivered with no performance degradation.
* @return a set of hosts
*/
protected List<Host> getHostsWithTightSla(Datacenter dc){
return getHostsFromSlaExploitationPolicy(dc, TIGHT);
protected List<Host> getHostsWithTightSla(){
return getHostsFromSlaExploitationPolicy(getDatacenter(), TIGHT);
}
/**
......@@ -240,8 +240,8 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* (may have (or not) performance degradation)
* @return a set of hosts
*/
protected List<Host> getHostsWithLooseSla(Datacenter dc){
return getHostsFromSlaExploitationPolicy(dc, LOOSE);
protected List<Host> getHostsWithLooseSla(){
return getHostsFromSlaExploitationPolicy(getDatacenter(), LOOSE);
}
/**
......@@ -251,22 +251,18 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* @return a set of hosts
*/
protected List<Host> getHostsFromSlaExploitationPolicy(Datacenter dc, String policyType) {
List<Host> exploitationHosts = new ArrayList<Host>();
List<Host> hosts = new ArrayList<Host>();
for (Host host : dc.getHostList()) {
if (policyType.toUpperCase().equals(LOOSE) &&
host.getIopsProvisioner() instanceof ResourceProvisionerSimple) {
exploitationHosts.add(host);
hosts.add(host);
}
else if (policyType.toUpperCase().equals(TIGHT) &&
host.getIopsProvisioner() instanceof ResourceProvisionerShared) {
exploitationHosts.add(host);
}
else {
Log.print("This host is neither heaven nor hell: "+host.getIopsProvisioner().toString());
System.exit(0);
hosts.add(host);
}
}
return exploitationHosts;
return hosts;
}
@Override
......
......@@ -20,6 +20,8 @@ import org.cloudbus.cloudsim.resources.ResourceManageable;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.vms.VmSimple;
import org.easymock.EasyMock;
import org.easymock.internal.matchers.InstanceOf;
import org.hamcrest.core.AnyOf;
import org.junit.Before;
import org.junit.Test;
......@@ -40,21 +42,8 @@ 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
......@@ -120,10 +109,8 @@ public class VmAllocationPolicyMigrationSlaTest {
private Datacenter createMockedDatacenter(List<Host> hosts) {
Datacenter datacenter = EasyMock.createMock(Datacenter.class);
EasyMock.expect(datacenter.getHostList()).andReturn(hosts).anyTimes();
EasyMock.replay(datacenter);
return datacenter;
}
......@@ -131,14 +118,20 @@ public class VmAllocationPolicyMigrationSlaTest {
public void getHostsWithTightSla_test(){
List<Host> hosts = new ArrayList<Host>();
final int NUM_HEAVEN_HOSTS = 50;
for(int i = 0; i < NUM_HEAVEN_HOSTS; i++)
for(int i = 0; i < NUM_HEAVEN_HOSTS; i++){
hosts.add(createMockedHost(i, 0, null, new ResourceProvisionerSimple()));
final int NUM_HELL_HOSTS = 50;
for(int i = NUM_HEAVEN_HOSTS; i < NUM_HELL_HOSTS; i++)
System.out.println("#"+i);
}
final int NUM_HELL_HOSTS = 150;
for(int i = NUM_HEAVEN_HOSTS; i < NUM_HEAVEN_HOSTS+NUM_HELL_HOSTS; i++){
hosts.add(createMockedHost(i, 0, null, new ResourceProvisionerShared()));
System.out.println("*"+i);
}
Datacenter dc = createMockedDatacenter(hosts);
policy.setDatacenter(dc);
assertEquals(NUM_HEAVEN_HOSTS, policy.getHostsWithLooseSla().size());
assertEquals(NUM_HELL_HOSTS, policy.getHostsWithTightSla().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