Commit e4f9d3f0 authored by aninhacostaribeiro's avatar aninhacostaribeiro
Browse files

Added a new Test for test the setAllHosts() method

parent 284a59dc
......@@ -56,6 +56,34 @@ public class DefaultGreenStrategy implements GreenStrategy {
this.allWakedHosts = this.openStackPlugin.getHostInformation();
}
protected void setLostHostTime(long lostHostTime) {
this.lostHostTime = lostHostTime;
}
public void setCommunicationComponent(ServerCommunicationComponent gscc) {
this.scc = gscc;
}
protected void setDate(Date date) {
this.lastUpdatedTime = date;
}
public List<Host> getNappingHosts() {
return nappingHosts;
}
public List<Host> getSleepingHosts() {
return sleepingHosts;
}
public List<? extends Host> getAllWakedHosts() {
return allWakedHosts;
}
public List<Host> getLostHosts() {
return lostHosts;
}
protected void setAllHosts() {
List<Host> nowHosts = new LinkedList<Host>();
nowHosts.addAll(this.allWakedHosts);
......@@ -74,6 +102,9 @@ public class DefaultGreenStrategy implements GreenStrategy {
if(this.nappingHosts.contains(host)){
this.nappingHosts.remove(host);
}
if (this.sleepingHosts.contains(host)){
this.sleepingHosts.remove(host);
}
}
}
......@@ -90,29 +121,6 @@ public class DefaultGreenStrategy implements GreenStrategy {
}
}
protected void setLostHostTime(long lostHostTime) {
this.lostHostTime = lostHostTime;
}
public void setCommunicationComponent(ServerCommunicationComponent gscc) {
this.scc = gscc;
}
protected void setDate(Date date) {
this.lastUpdatedTime = date;
}
public List<Host> getNappingHosts() {
return nappingHosts;
}
public List<Host> getSleepingHosts() {
return sleepingHosts;
}
public List<? extends Host> getAllWakedHosts() {
return allWakedHosts;
}
public void receiveIamAliveInfo(String hostName, String jid, String ip,
String macAddress) {
......@@ -213,4 +221,4 @@ public class DefaultGreenStrategy implements GreenStrategy {
}
}, 0, sleepingTime, TimeUnit.MILLISECONDS);
}
}
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ public class TestDefaultGreenStrategy {
public void testCheckHostLastSeen() {
Host lost = new Host ("lost", 0, true, true, 0, 0, 0);
lost.setLastSeen(0);
Host still = new Host ("lost", 0, true, true, 0, 0, 0);
Host still = new Host ("still", 0, true, true, 0, 0, 0);
still.setLastSeen(1500000);
List<Host> hosts = new LinkedList<Host>();
hosts.add(lost);
......@@ -77,6 +77,26 @@ public class TestDefaultGreenStrategy {
Assert.assertEquals(1, dgs.getSleepingHosts().size());
Assert.assertEquals(0, dgs.getNappingHosts().size());
}
@Test
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);
still.setLastSeen(1500000);
List<Host> hosts = new LinkedList<Host>();
hosts.add(lost);
hosts.add(still);
OpenStackInfoPlugin osip = this.createOpenStackInfoPluginMock(hosts);
DefaultGreenStrategy dgs = new DefaultGreenStrategy(osip, 1800000);
Date date = this.createDateMock(1500001);
dgs.setDate(date);
dgs.setLostHostTime(1500000);
dgs.checkHostsLastSeen();
dgs.setAllHosts();
Assert.assertEquals(1, dgs.getAllWakedHosts().size());
Assert.assertEquals(1, dgs.getLostHosts().size());
}
@Test
public void testNoHosts() {
......
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