Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lucas Cavalcante
cloudsimplus
Commits
98145c41
Commit
98145c41
authored
Jun 18, 2018
by
Kaio Oliveira
Browse files
Add test for VmAllocationPolicyMigrationSla
As part of the US, we need some Unit Tests for our new AllocationPolicy.
parent
ebb577a6
Changes
1
Hide whitespace changes
Inline
Side-by-side
cloudsim-plus/src/test/java/org/cloudbus/cloudsim/allocationpolicies/VmAllocationPolicyMigrationSlaTest.java
0 → 100644
View file @
98145c41
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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment