Commit 98145c41 authored by Kaio Oliveira's avatar Kaio Oliveira
Browse files

Add test for VmAllocationPolicyMigrationSla

As part of the US, we need some Unit Tests for our new
AllocationPolicy.
parent ebb577a6
package org.cloudbus.cloudsim.allocationpolicies;
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.migration.VmAllocationPolicyMigrationSla;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.resources.Bandwidth;
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;
/**
* @author Kaio Kassiano Moura Oliveira (@kaiokmo)
* @author Eduardo de Lucena Falcao (@eduardolfalcao)
*/
public class VmAllocationPolicyMigrationSlaTest {
public static final int HOST_MIPS = 1000;
public static final int HOST_RAM = 10000;
public static final int HOST_IOPS = 5000;
public static final int HOST_BW = 100000;
public static final int HOST_BASE_STORAGE = 1000;
private VmAllocationPolicyMigrationSla policy;
@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);
policy = new VmAllocationPolicyMigrationSla();
policy.setDatacenter(datacenter);
}
@Test
public void migrateVmFromHeavenToHell() {
throw new NotImplementedException("TODO");
}
@Test
public void migrateVmFromHellToHeaven() {
throw new NotImplementedException("TODO");
}
private Vm createMockedVm(int id, double cpuUsage, double ramUsage, double iopsUsage, double bwUsage) {
VmWithMetadata vm = EasyMock.createMock(VmWithMetadata.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.replay(vm);
return vm;
}
private Host createMockedHost(int id, int pesNumber, Vm vm) {
Host host = EasyMock.createMock(Host.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(host.getBw()).andReturn(new Bandwidth(HOST_BW)).anyTimes();
EasyMock.expect(host.getNumberOfWorkingPes()).andReturn((long) 2).anyTimes();
List<Vm> vms = new ArrayList<Vm>();
vms.add(vm);
EasyMock.expect(host.getVmList()).andReturn(vms);
EasyMock.replay(host);
return host;
}
private Datacenter createMockedDatacenter(List<Host> hosts) {
Datacenter datacenter = EasyMock.createMock(Datacenter.class);
EasyMock.expect(datacenter.getHostList()).andReturn(hosts).anyTimes();
EasyMock.replay(datacenter);
return datacenter;
}
}
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