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
1e87be58
Commit
1e87be58
authored
Apr 06, 2015
by
aninhacostaribeiro
Browse files
Added new tests
parent
7cd9e96c
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/fogbowcloud/green/agent/AgentCommunicationComponent.java
View file @
1e87be58
...
...
@@ -27,7 +27,7 @@ public class AgentCommunicationComponent {
private
ScheduledExecutorService
executor
=
Executors
.
newScheduledThreadPool
(
1
);
private
Properties
prop
;
private
long
sleeping
Time
;
private
int
thread
Time
;
private
XMPPClient
client
;
public
AgentCommunicationComponent
(
Properties
prop
)
{
...
...
@@ -37,8 +37,14 @@ public class AgentCommunicationComponent {
this
.
prop
.
getProperty
(
"xmpp.password"
),
this
.
prop
.
getProperty
(
"xmpp.host"
),
Integer
.
parseInt
(
this
.
prop
.
getProperty
(
"xmpp.port"
)));
this
.
sleepingTime
=
Long
.
parseLong
(
this
.
prop
.
getProperty
(
"green.sleepingTime"
));
if
(
this
.
prop
.
getProperty
(
"green.threadTime"
)
!=
null
)
{
this
.
threadTime
=
Integer
.
parseInt
(
this
.
prop
.
getProperty
(
"green.threadTime"
));
}
else
{
this
.
threadTime
=
60
;
}
}
catch
(
Exception
e
)
{
LOGGER
.
fatal
(
"The configuration file is not correct"
,
e
);
}
...
...
@@ -130,7 +136,7 @@ public class AgentCommunicationComponent {
public
void
run
()
{
sendIamAliveSignal
();
}
},
0
,
sleeping
Time
,
TimeUnit
.
MILLI
SECONDS
);
},
0
,
thread
Time
,
TimeUnit
.
SECONDS
);
}
}
src/main/java/org/fogbowcloud/green/server/core/greenStrategy/DefaultGreenStrategy.java
View file @
1e87be58
...
...
@@ -33,21 +33,29 @@ public class DefaultGreenStrategy implements GreenStrategy {
private
long
graceTime
;
private
long
expirationTime
;
private
int
threadTime
;
private
ScheduledExecutorService
executorService
=
Executors
.
newScheduledThreadPool
(
1
);
public
DefaultGreenStrategy
(
Properties
greenProperties
)
{
this
.
openStackPlugin
=
new
OpenStackInfoPlugin
(
greenProperties
.
getProperty
(
"openstack.endpoint"
).
toString
(),
greenProperties
.
getProperty
(
"openstack.username"
).
toString
(),
greenProperties
.
get
(
"openstack.password"
).
toString
(),
greenProperties
public
DefaultGreenStrategy
(
Properties
prop
)
{
this
.
openStackPlugin
=
new
OpenStackInfoPlugin
(
prop
.
getProperty
(
"openstack.endpoint"
).
toString
(),
prop
.
getProperty
(
"openstack.username"
).
toString
(),
prop
.
get
(
"openstack.password"
).
toString
(),
prop
.
getProperty
(
"openstack.tenant"
).
toString
());
this
.
dateWrapper
=
new
DateWrapper
();
this
.
graceTime
=
Long
.
parseLong
(
greenProperties
this
.
graceTime
=
Long
.
parseLong
(
prop
.
getProperty
(
"greenstrategy.gracetime"
))
*
1000
;
this
.
expirationTime
=
Long
.
parseLong
(
greenProperties
this
.
expirationTime
=
Long
.
parseLong
(
prop
.
getProperty
(
"greenstrategy.expirationtime"
))
*
1000
;
if
(
prop
.
getProperty
(
"green.threadTime"
)
!=
null
)
{
this
.
threadTime
=
Integer
.
parseInt
(
prop
.
getProperty
(
"green.threadTime"
));
}
else
{
this
.
threadTime
=
60
;
}
}
/*
...
...
@@ -217,6 +225,6 @@ public class DefaultGreenStrategy implements GreenStrategy {
LOGGER
.
warn
(
"Exception thrown at the main thread"
,
e
);
}
}
},
0
,
1
,
TimeUnit
.
MINUTE
S
);
},
0
,
threadTime
,
TimeUnit
.
SECOND
S
);
}
}
\ No newline at end of file
src/main/java/org/fogbowcloud/green/server/core/plugins/openstack/OpenStackInfoPlugin.java
View file @
1e87be58
...
...
@@ -44,7 +44,6 @@ public class OpenStackInfoPlugin implements CloudInfoPlugin {
for
(
Hypervisor
hypervisor
:
hypervisors
)
{
hostsName
.
add
(
hypervisor
.
getHypervisorHostname
());
}
System
.
out
.
println
(
hostsName
.
toString
());
return
hostsName
;
}
...
...
src/test/java/org/fogbowcloud/green/agent/TestAgentCommunicationComponent.java
View file @
1e87be58
...
...
@@ -4,40 +4,46 @@ import java.util.Properties;
import
org.junit.Assert
;
import
org.jamppa.client.XMPPClient
;
import
org.jamppa.client.plugin.xep0077.XEP0077
;
import
org.jivesoftware.smack.XMPPConnection
;
import
org.jivesoftware.smack.XMPPException
;
import
org.junit.Test
;
import
org.mockito.Mockito
;
import
org.xmpp.packet.IQ
;
public
class
TestAgentCommunicationComponent
{
p
rivate
XMPPClient
createXMPPClientMock
()
{
@Test
p
ublic
void
testSendIamAliveSignal
()
{
XMPPClient
client
=
Mockito
.
mock
(
XMPPClient
.
class
);
Mockito
.
doReturn
(
Mockito
.
mock
(
XMPPConnection
.
class
)).
when
(
client
)
.
getConnection
();
return
client
;
}
private
Properties
createPropMock
(
String
hostName
,
String
ip
,
String
macAddress
)
{
Properties
prop
=
Mockito
.
mock
(
Properties
.
class
);
Mockito
.
doReturn
(
ip
).
when
(
prop
).
getProperty
(
"host.ip"
);
Mockito
.
doReturn
(
hostName
).
when
(
prop
).
getProperty
(
"host.name"
);
Mockito
.
doReturn
(
macAddress
).
when
(
prop
).
getProperty
(
"host.macAddress"
);
return
prop
;
Mockito
.
doReturn
(
"123.456.78.9"
).
when
(
prop
).
getProperty
(
"host.ip"
);
Mockito
.
doReturn
(
"host"
).
when
(
prop
).
getProperty
(
"host.name"
);
Mockito
.
doReturn
(
"A1:B2:C3:D4:E5:67"
).
when
(
prop
)
.
getProperty
(
"host.macAddress"
);
AgentCommunicationComponent
acc
=
new
AgentCommunicationComponent
(
prop
);
acc
.
setClient
(
client
);
IQ
expectedIQ
=
acc
.
sendIamAliveSignal
();
Assert
.
assertEquals
(
expectedIQ
.
getElement
().
element
(
"query"
)
.
elementText
(
"ip"
),
"123.456.78.9"
);
Assert
.
assertEquals
(
expectedIQ
.
getElement
().
element
(
"query"
)
.
elementText
(
"hostName"
),
"host"
);
Assert
.
assertEquals
(
expectedIQ
.
getElement
().
element
(
"query"
)
.
elementText
(
"macAddress"
),
"A1:B2:C3:D4:E5:67"
);
}
@Test
public
void
testSendIamAliveSignal
()
{
XMPPClient
client
=
createXMPPClientMock
();
Properties
prop
=
createPropMock
(
"host"
,
"123.456.78.9"
,
"A1:B2:C3:D4:E5:67"
);
public
void
testInitConnectException
()
throws
XMPPException
{
XMPPClient
client
=
Mockito
.
mock
(
XMPPClient
.
class
);
XMPPException
e
=
new
XMPPException
();
Mockito
.
doThrow
(
e
).
when
(
client
).
connect
();
Mockito
.
doThrow
(
e
).
when
(
client
).
registerPlugin
(
new
XEP0077
());
Properties
prop
=
Mockito
.
mock
(
Properties
.
class
);
AgentCommunicationComponent
acc
=
new
AgentCommunicationComponent
(
prop
);
acc
.
setClient
(
client
);
IQ
expectedIQ
=
acc
.
sendIamAliveSignal
();
Assert
.
assertEquals
(
expectedIQ
.
getElement
().
element
(
"query"
).
elementText
(
"ip"
),
"123.456.78.9"
);
Assert
.
assertEquals
(
expectedIQ
.
getElement
().
element
(
"query"
).
elementText
(
"hostName"
),
"host"
);
Assert
.
assertEquals
(
expectedIQ
.
getElement
().
element
(
"query"
).
elementText
(
"macAddress"
),
"A1:B2:C3:D4:E5:67"
);
Assert
.
assertEquals
(
false
,
acc
.
init
());
}
}
src/test/java/org/fogbowcloud/green/server/communication/TestWakeUpRequestHandler.java
View file @
1e87be58
...
...
@@ -26,7 +26,6 @@ public class TestWakeUpRequestHandler {
query
.
addElement
(
"minRAM"
).
setText
(
Integer
.
toString
(
1024
));
WakeUpRequestHandler
wurh
=
new
WakeUpRequestHandler
(
this
.
createGreenStrategyMock
(
1
,
1024
));
IQ
result
=
wurh
.
handle
(
iq
);
System
.
out
.
println
(
result
);
Assert
.
assertEquals
(
result
.
getFrom
().
toString
(),
"green.test.com"
);
}
...
...
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