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
fogbow
fogbow-green-sitter
Commits
d0ffb17b
Commit
d0ffb17b
authored
Mar 27, 2015
by
aninhacostaribeiro
Browse files
Uptdated the tests of GreenStrategy
parent
e6282f29
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/fogbowcloud/green/server/core/greenStrategy/DefaultGreenStrategy.java
View file @
d0ffb17b
...
...
@@ -136,7 +136,6 @@ public class DefaultGreenStrategy implements GreenStrategy {
LOGGER
.
info
(
"Will send idle hosts to bed. Hosts' status: "
+
this
.
hostsAwake
);
for
(
Host
host
:
this
.
hostsAwake
)
{
if
(
host
.
isNovaEnable
()
&&
host
.
isNovaRunning
()
&&
(
host
.
getRunningVM
()
==
0
))
{
...
...
src/test/java/org/fogbowcloud/green/server/core/greenStrategy/TestDefaultGreenStrategy.java
View file @
d0ffb17b
...
...
@@ -28,21 +28,21 @@ public class TestDefaultGreenStrategy {
public
void
testCheckHostLastSeen
()
{
Host
lost
=
new
Host
(
"lost"
,
0
,
true
,
true
,
0
,
0
,
0
);
lost
.
setLastSeen
(
0
);
Host
still
=
new
Host
(
"still"
,
0
,
true
,
true
,
0
,
0
,
0
);
Host
still
l
=
new
Host
(
"still
l
"
,
0
,
true
,
true
,
0
,
0
,
0
);
List
<
Host
>
hosts
=
new
LinkedList
<
Host
>();
hosts
.
add
(
lost
);
hosts
.
add
(
still
);
hosts
.
add
(
still
l
);
OpenStackInfoPlugin
osip
=
this
.
createOpenStackInfoPluginMock
(
hosts
);
DefaultGreenStrategy
dgs
=
new
DefaultGreenStrategy
(
osip
,
1800000
);
DateWrapper
date
=
this
.
createDateMock
(
0
);
dgs
.
setDateWrapper
(
date
);
dgs
.
receiveIamAliveInfo
(
"lost"
,
"lost@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
receiveIamAliveInfo
(
"still"
,
"still@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
receiveIamAliveInfo
(
"still
l
"
,
"still
l
@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
setExpirationTime
(
1500000
);
dgs
.
checkExpiredHosts
();
DateWrapper
newDate
=
this
.
createDateMock
(
1500001
);
dgs
.
setDateWrapper
(
newDate
);
dgs
.
receiveIamAliveInfo
(
"still"
,
"still@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
receiveIamAliveInfo
(
"still
l
"
,
"still
l
@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
checkExpiredHosts
();
Assert
.
assertEquals
(
1
,
dgs
.
getHostsAwake
().
size
());
}
...
...
@@ -91,7 +91,7 @@ public class TestDefaultGreenStrategy {
}
@Test
public
void
testOneHost
Napping
()
{
public
void
testOneHost
InGracePeriod
()
{
Host
napping
=
new
Host
(
"host1"
,
0
,
true
,
true
,
0
,
0
,
0
);
List
<
Host
>
hosts
=
new
LinkedList
<
Host
>();
hosts
.
add
(
napping
);
...
...
@@ -99,6 +99,9 @@ public class TestDefaultGreenStrategy {
DefaultGreenStrategy
dgs
=
new
DefaultGreenStrategy
(
osip
,
1800000
);
DateWrapper
date
=
this
.
createDateMock
(
3600001
);
dgs
.
setDateWrapper
(
date
);
dgs
.
receiveIamAliveInfo
(
"host1"
,
"wake@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
DateWrapper
date1
=
this
.
createDateMock
(
5400002
);
dgs
.
setDateWrapper
(
date1
);
dgs
.
sendIdleHostsToBed
();
Assert
.
assertEquals
(
1
,
dgs
.
getHostsInGracePeriod
().
size
());
}
...
...
@@ -106,23 +109,25 @@ public class TestDefaultGreenStrategy {
@Test
public
void
testOneHostSleeping
()
{
Host
h1
=
new
Host
(
"host1"
,
0
,
true
,
true
,
1800000
,
0
,
0
);
h1
.
setMacAddress
(
"mac"
);
List
<
Host
>
hosts
=
new
LinkedList
<
Host
>();
hosts
.
add
(
h1
);
DateWrapper
date
=
this
.
createDateMock
(
3600001
);
ServerCommunicationComponent
gscc
=
Mockito
.
mock
(
ServerCommunicationComponent
.
class
);
try
{
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
h1
.
getMacAddress
());
}
catch
(
IOException
e
)
{
//Ignorating exception because it always do nothing
//Ignorating exception because it always do
es
nothing
}
OpenStackInfoPlugin
osip
=
this
.
createOpenStackInfoPluginMock
(
hosts
);
DefaultGreenStrategy
dgs
=
new
DefaultGreenStrategy
(
osip
,
1800000
);
DateWrapper
date
=
this
.
createDateMock
(
3600001
);
dgs
.
setDateWrapper
(
date
);
dgs
.
setCommunicationComponent
(
gscc
);
dgs
.
receiveIamAliveInfo
(
"host1"
,
"wake@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
sendIdleHostsToBed
();
h1
.
setNappingSince
(
1800000
);
DateWrapper
date1
=
this
.
createDateMock
(
5400002
);
dgs
.
setDateWrapper
(
date1
);
dgs
.
sendIdleHostsToBed
();
Assert
.
assertEquals
(
1
,
dgs
.
getSleepingHosts
().
size
());
Assert
.
assertEquals
(
0
,
dgs
.
getHostsInGracePeriod
().
size
());
...
...
@@ -132,15 +137,15 @@ public class TestDefaultGreenStrategy {
public
void
testUpdatingLostHost
()
{
Host
lost
=
new
Host
(
"lost"
,
0
,
true
,
true
,
0
,
0
,
0
);
lost
.
setLastSeen
(
0
);
Host
still
=
new
Host
(
"still"
,
0
,
true
,
true
,
0
,
0
,
0
);
Host
still
l
=
new
Host
(
"still
l
"
,
0
,
true
,
true
,
0
,
0
,
0
);
List
<
Host
>
hosts
=
new
LinkedList
<
Host
>();
hosts
.
add
(
lost
);
hosts
.
add
(
still
);
hosts
.
add
(
still
l
);
OpenStackInfoPlugin
osip
=
this
.
createOpenStackInfoPluginMock
(
hosts
);
DefaultGreenStrategy
dgs
=
new
DefaultGreenStrategy
(
osip
,
1800000
);
DateWrapper
date
=
this
.
createDateMock
(
1500001
);
dgs
.
setDateWrapper
(
date
);
dgs
.
receiveIamAliveInfo
(
"host"
,
"still@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
receiveIamAliveInfo
(
"host"
,
"still
l
@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
setExpirationTime
(
1500000
);
dgs
.
checkExpiredHosts
();
dgs
.
updateAllHosts
();
...
...
@@ -162,13 +167,13 @@ public class TestDefaultGreenStrategy {
@Test
public
void
testWakeUp
()
{
Host
mustWake
=
new
Host
(
"wake"
,
0
,
true
,
true
,
1800000
,
3
,
8
);
Host
stilSleep
=
new
Host
(
"stil"
,
0
,
true
,
true
,
1800000
,
3
,
2
);
Host
stilSleep2
=
new
Host
(
"stil2"
,
0
,
true
,
true
,
1800000
,
1
,
2
);
Host
stil
l
Sleep
=
new
Host
(
"stil
l
"
,
0
,
true
,
true
,
1800000
,
3
,
2
);
Host
stil
l
Sleep2
=
new
Host
(
"stil
l
2"
,
0
,
true
,
true
,
1800000
,
1
,
2
);
List
<
Host
>
hosts
=
new
LinkedList
<
Host
>();
hosts
.
add
(
mustWake
);
hosts
.
add
(
stilSleep
);
hosts
.
add
(
stilSleep2
);
hosts
.
add
(
stil
l
Sleep
);
hosts
.
add
(
stil
l
Sleep2
);
DateWrapper
date
=
this
.
createDateMock
(
3600001
);
OpenStackInfoPlugin
osip
=
this
.
createOpenStackInfoPluginMock
(
hosts
);
...
...
@@ -179,25 +184,28 @@ public class TestDefaultGreenStrategy {
try
{
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
"wake"
);
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
mustWake
.
getMacAddress
());
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
stilSleep
.
getMacAddress
());
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
stilSleep2
.
getMacAddress
());
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
stil
l
Sleep
.
getMacAddress
());
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
stil
l
Sleep2
.
getMacAddress
());
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
//Ignorating exception because it always does nothing
}
dgs
.
receiveIamAliveInfo
(
"wake"
,
"wake@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
receiveIamAliveInfo
(
"still"
,
"still1@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
receiveIamAliveInfo
(
"still2"
,
"still2@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
setCommunicationComponent
(
gscc
);
dgs
.
sendIdleHostsToBed
();
mustWake
.
setNappingSince
(
1800000
);
stilSleep
.
setNappingSince
(
1800000
);
stilSleep2
.
setNappingSince
(
1800000
);
stillSleep
.
setNappingSince
(
1800000
);
stillSleep2
.
setNappingSince
(
1800000
);
DateWrapper
date1
=
this
.
createDateMock
(
5400002
);
dgs
.
setDateWrapper
(
date1
);
dgs
.
sendIdleHostsToBed
();
dgs
.
wakeUpSleepingHost
(
2
,
4
);
List
<
Host
>
expetedResult
=
new
LinkedList
<
Host
>();
expetedResult
.
add
(
stilSleep
);
expetedResult
.
add
(
stilSleep2
);
expetedResult
.
add
(
stil
l
Sleep
);
expetedResult
.
add
(
stil
l
Sleep2
);
Assert
.
assertArrayEquals
(
expetedResult
.
toArray
(),
dgs
.
getSleepingHosts
().
toArray
());
...
...
@@ -217,36 +225,36 @@ public class TestDefaultGreenStrategy {
@Test
public
void
testMultipleWakableHosts
()
{
Host
mustWake
=
new
Host
(
"wake"
,
0
,
true
,
true
,
1800000
,
3
,
8
);
Host
mustWake2
=
new
Host
(
"stil"
,
0
,
true
,
true
,
1800000
,
3
,
5
);
Host
mustWake2
=
new
Host
(
"still"
,
0
,
true
,
true
,
1800000
,
3
,
5
);
List
<
Host
>
hosts
=
new
LinkedList
<
Host
>();
hosts
.
add
(
mustWake
);
hosts
.
add
(
mustWake2
);
DateWrapper
date
=
this
.
createDateMock
(
3600001
);
ServerCommunicationComponent
gscc
=
Mockito
.
mock
(
ServerCommunicationComponent
.
class
);
try
{
Mockito
.
doNothing
().
when
(
gscc
).
wakeUpHost
(
"wake"
);
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
//Ignorating exception because it always does nothing
}
OpenStackInfoPlugin
osip
=
this
.
createOpenStackInfoPluginMock
(
hosts
);
DateWrapper
date
=
this
.
createDateMock
(
3600001
);
DefaultGreenStrategy
dgs
=
new
DefaultGreenStrategy
(
osip
,
1800000
);
dgs
.
setDateWrapper
(
date
);
dgs
.
setCommunicationComponent
(
gscc
);
dgs
.
receiveIamAliveInfo
(
"wake"
,
"wake@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
receiveIamAliveInfo
(
"still"
,
"still@test.com"
,
"123.456.789.10"
,
"A1:B2:C3:D4:E5:67"
);
dgs
.
sendIdleHostsToBed
();
mustWake
.
setNappingSince
(
1800000
);
mustWake2
.
setNappingSince
(
1800000
);
DateWrapper
date1
=
this
.
createDateMock
(
5400002
);
dgs
.
setDateWrapper
(
date1
);
dgs
.
sendIdleHostsToBed
();
Assert
.
assertEquals
(
"wake"
,
dgs
.
getSleepingHosts
().
peek
().
getName
());
dgs
.
wakeUpSleepingHost
(
2
,
4
);
Assert
.
assertEquals
(
1
,
dgs
.
getSleepingHosts
().
size
());
Assert
.
assertEquals
(
1
,
dgs
.
getSleepingHosts
().
size
());
}
}
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