Commit 976e08a4 authored by Kaio Oliveira's avatar Kaio Oliveira
Browse files

Implement more tests

Also we needed to fix the package location for the
VmAllocationPolicyMigrationSlaTest class, in order to better use the
visibility of some methods.
parent 98145c41
......@@ -132,7 +132,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* or a list of hosts from low to high fragmentation
* @param list a list of Machines (vms or hosts)
*/
private void sort(List<? extends Machine> list){
protected void sort(List<? extends Machine> list){
if(list.isEmpty())
return;
......@@ -179,7 +179,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* @param h the host
* @return a list of VMs
*/
private List<Vm> getVmsWithEnoughCredit(List<Host> looseSlaHosts){
protected List<Vm> getVmsWithEnoughCredit(List<Host> looseSlaHosts){
List<Vm> candidateVmsToMigrate = new ArrayList<Vm>();
final double clock = getDatacenter().getSimulation().clock();
......@@ -196,11 +196,11 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
return candidateVmsToMigrate;
}
private double getVmFragmentation(Vm vm){
protected double getVmFragmentation(Vm vm){
return vm.getIops().getAvailableResource();
}
private double getHostFragmentation(Host h){
protected double getHostFragmentation(Host h){
return h.getIops().getAvailableResource();
}
......@@ -210,7 +210,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* @param host a tight SLA host
* @return a set of VMs
*/
private Set<Vm> getSufferingVms(Set<Host> tightSlaHosts){
protected Set<Vm> getSufferingVms(Set<Host> tightSlaHosts){
Set<Vm> sufferingVms = new HashSet<Vm>();
final double clock = getDatacenter().getSimulation().clock();
......@@ -231,7 +231,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* Get hosts in which the SLA are delivered with no performance degradation.
* @return a set of hosts
*/
private List<Host> getHostsWithTightSla(Datacenter dc){
protected List<Host> getHostsWithTightSla(Datacenter dc){
return getHostsFromSlaExploitationPolicy(dc, TIGHT);
}
......@@ -240,7 +240,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* (may have (or not) performance degradation)
* @return a set of hosts
*/
private List<Host> getHostsWithLooseSla(Datacenter dc){
protected List<Host> getHostsWithLooseSla(Datacenter dc){
return getHostsFromSlaExploitationPolicy(dc, LOOSE);
}
......@@ -250,7 +250,7 @@ public class VmAllocationPolicyMigrationSla extends VmAllocationPolicyAbstract {
* @param policyType type scenario of the host SlaExplotation
* @return a set of hosts
*/
private List<Host> getHostsFromSlaExploitationPolicy(Datacenter dc, String policyType) {
protected List<Host> getHostsFromSlaExploitationPolicy(Datacenter dc, String policyType) {
List<Host> exploitationHosts = new ArrayList<Host>();
for (Host host : dc.getHostList()) {
if (policyType.toUpperCase().equals(LOOSE) &&
......
package org.cloudbus.cloudsim.allocationpolicies;
package org.cloudbus.cloudsim.allocationpolicies.migration;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang3.NotImplementedException;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicy;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigrationSla;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.hosts.Host;
......@@ -15,8 +16,6 @@ import org.cloudbus.cloudsim.resources.Iops;
import org.cloudbus.cloudsim.resources.Ram;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.vms.VmWithMetadata;
import org.cloudbus.cloudsim.vms.VmWithMetadata.VmData;
import org.cloudbus.cloudsim.vms.VmWithMetadata.VmLabel;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
......@@ -32,6 +31,8 @@ public class VmAllocationPolicyMigrationSlaTest {
public static final int HOST_BW = 100000;
public static final int HOST_BASE_STORAGE = 1000;
public static final int MIGRATION_TIME = 60;
private VmAllocationPolicyMigrationSla policy;
@Before
......@@ -48,9 +49,22 @@ public class VmAllocationPolicyMigrationSlaTest {
Datacenter datacenter = createMockedDatacenter(hosts);
policy = new VmAllocationPolicyMigrationSla();
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);
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);
}
@Test
public void migrateVmFromHeavenToHell() {
......
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