package net.sf.jdistunit.daemon;
import java.util.List;
import junit.framework.TestCase;
import net.sf.agentopia.util.net.HostId;
import net.sf.jdistunit.platform.agent.ITestBox;
import net.sf.jdistunit.platform.agent.JDistUnitAgent;
import net.sf.jdistunit.platform.agent.TestBox;
/**
* Same as the example test case, but code is optimized to be used in the
* JDistUnit web pages.
*
* @author <a href="mailto:kain@land-of-kain.de">Kai Ruhl</a>
* @since 26 Nov 2009
*/
public class JDistUnitExampleTestWeb extends TestCase {
/** The JDistUnit test box. */
private ITestBox testBox;
/**
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
testBox = new TestBox(new HostId("ginko.vpn:15900"));
testBox.connectToNetwork(new HostId("ginko.vpn:15907"));
testBox.connectToNetwork(new HostId("eva.vpn:15907"));
}
/**
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
testBox.shutdown();
Thread.sleep(2000);
}
/**
* @throws Exception If something failed.
*/
public void testHomepageLoad() throws Exception {
JDistUnitAgent agent = new HomepageTestAgent();
agent.setRequestCount(2);
agent.setTimeOut(30000L);
agent.setThreadTimeStep(300L);
testBox.deployTestAgents(agent);
testBox.waitForResults(1);
assertEquals(testBox.getTestServerCount(), testBox.getReturnedAgentCount());
assertEquals(2, testBox.getNumberOfSuccesses());
assertEquals(0, testBox.getNumberOfFailures());
assertEquals(0, testBox.getNumberOfStarvations());
List<Throwable> errorList = testBox.getErrorList();
assertTrue(errorList.isEmpty());
assertTrue(testBox.getPerformanceMinimum() > 0);
assertTrue(testBox.getPerformanceAverage() < 3000);
assertTrue(testBox.getPerformanceMaximum() < 5000);
}
}