server.testmodules
Class TestModule

java.lang.Object
  extended by server.framework.network.ServerSocketCommunicator
      extended by server.testmodules.TestModule
All Implemented Interfaces:
Communicator
Direct Known Subclasses:
PingTest, TransferSpeedTest

public abstract class TestModule
extends ServerSocketCommunicator

An abstract class containing common methods for test-classes. Such methods can be measurement and report generating methods.

Author:
Martin Jarrett, Eivind Sorteberg

Nested Class Summary
protected  class TestModule.Sender
          The internal class responsible for sending messages from the server.
static class TestModule.TestType
          Enumeration determining the test type.
protected  class TestModule.Timer
          The internal class that times the time a message takes to go from the server to the client and back.
 
Nested classes/interfaces inherited from class server.framework.network.ServerSocketCommunicator
ServerSocketCommunicator.ReceiverThread, ServerSocketCommunicator.SenderThread
 
Field Summary
protected  java.util.ArrayList<java.util.HashMap<java.lang.Integer,TestModule.Timer>> allTests
           
protected  int currentRun
           
protected  long interval
           
protected  java.lang.String message
           
static java.lang.String NETWORK
           
static int NOF_INTERVALS
           
static int NOF_PACKETS
           
static int NOF_RUNS
           
static java.lang.String PROVIDER
           
 int random
           
 
Fields inherited from class server.framework.network.ServerSocketCommunicator
receiverThread, senderThread, server, socket
 
Constructor Summary
TestModule(SocketWrapper socket, AbstractServer server)
          Creates a TestModule object with the specified attributes.
 
Method Summary
protected abstract  java.lang.Number[] calculateValues(TestModule.Timer[] timers, int interval_no)
          Calculates values from the Timers.
 void close()
          Closes the connection.
 boolean connect(java.lang.String[] addresses)
          Uses the parent class implementation.
 void disconnect(java.lang.String[] addresses)
          Uses the parent class implementation.
protected abstract  java.lang.String findIdString(java.lang.String message)
          Finds the id of a message.
protected  long[] getAllValues(TestModule.Timer[] timers)
          Gets all values from the Timers'.
protected abstract  java.lang.String[] getHeaders()
          Gets the headers for the coloumns in the report.
 int getId()
          Generates an id from the counter before the counter is incremented.
protected abstract  long getInitialInterval()
          Gets the initial interval to use between sends.
protected abstract  java.lang.String getInitialMessage()
          Gets the initial message to send.
 int getLastId()
          Gets the previous id.
 java.lang.String getReport(boolean printAllTimers)
          Generates and returns the test report from the test results.
protected abstract  java.lang.String getStringToSend(int id)
          Gets the String to send.
protected static java.lang.String getThreeDigitString(long number)
          Converts from a number to a string of three digits by filling in zeros before the number.
protected static java.lang.String getTimeInSeconds(long nanos)
          Converts from nanoseconds to seconds.
protected abstract  java.lang.String getTitle()
          Gets the title for the report.
protected abstract  void notifyAboutIntervalComplete()
          Notifies the TestModules that the interval is complete.
 void notifyAboutMessageReceived(java.lang.Object message)
          Method that is called when the receiver thread receives a new message.
protected  void notifyAboutRunComplete()
          Notifies the TestModule that the run is completed and the next run can be started.
 void runTest()
          Starts the test and initialize import variables.
 void searchForNodes()
          Uses the parent class implementation.
 void sendMessage(java.lang.Object message, boolean confirm)
          Notifies the sender thread that a new message is to be sent.
 
Methods inherited from class server.framework.network.ServerSocketCommunicator
getSocket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOF_PACKETS

public static final int NOF_PACKETS
See Also:
Constant Field Values

NOF_INTERVALS

public static final int NOF_INTERVALS
See Also:
Constant Field Values

NOF_RUNS

public static final int NOF_RUNS
See Also:
Constant Field Values

PROVIDER

public static final java.lang.String PROVIDER
See Also:
Constant Field Values

NETWORK

public static final java.lang.String NETWORK
See Also:
Constant Field Values

random

public int random

message

protected java.lang.String message

allTests

protected java.util.ArrayList<java.util.HashMap<java.lang.Integer,TestModule.Timer>> allTests

currentRun

protected int currentRun

interval

protected long interval
Constructor Detail

TestModule

public TestModule(SocketWrapper socket,
                  AbstractServer server)
Creates a TestModule object with the specified attributes. Calls the parent constructor and initialize the ArrayList of the tests and the currentRun to zero.

Parameters:
socket - The test client's SocketWrapper object.
server - The test server.
Method Detail

connect

public boolean connect(java.lang.String[] addresses)
Uses the parent class implementation.

Specified by:
connect in interface Communicator
Overrides:
connect in class ServerSocketCommunicator
Parameters:
addresses - See parent class.
Returns:
See parent class.

disconnect

public void disconnect(java.lang.String[] addresses)
Uses the parent class implementation.

Specified by:
disconnect in interface Communicator
Overrides:
disconnect in class ServerSocketCommunicator
Parameters:
addresses - See parent class.

sendMessage

public void sendMessage(java.lang.Object message,
                        boolean confirm)
Notifies the sender thread that a new message is to be sent.

Specified by:
sendMessage in interface Communicator
Overrides:
sendMessage in class ServerSocketCommunicator
Parameters:
message - The message to send.
confirm - Not used in this implementation.

close

public void close()
Closes the connection.

Specified by:
close in interface Communicator
Overrides:
close in class ServerSocketCommunicator

searchForNodes

public void searchForNodes()
Uses the parent class implementation.

Specified by:
searchForNodes in interface Communicator
Overrides:
searchForNodes in class ServerSocketCommunicator

getReport

public java.lang.String getReport(boolean printAllTimers)
Generates and returns the test report from the test results.

Parameters:
printAllTimers - Whether all results should be printed or just the main results.
Returns:
The report as a String.

notifyAboutMessageReceived

public void notifyAboutMessageReceived(java.lang.Object message)
Method that is called when the receiver thread receives a new message. When this happens, the server model is notified about the event.

Specified by:
notifyAboutMessageReceived in interface Communicator
Overrides:
notifyAboutMessageReceived in class ServerSocketCommunicator
Parameters:
message - The message that has been received.

findIdString

protected abstract java.lang.String findIdString(java.lang.String message)
Finds the id of a message.

Parameters:
message - The message to find an id from.
Returns:
The id as a String.

calculateValues

protected abstract java.lang.Number[] calculateValues(TestModule.Timer[] timers,
                                                      int interval_no)
Calculates values from the Timers.

Parameters:
timers - The Timers to calculate from.
interval_no - The interval number to calculate.
Returns:
The array of calculated values.

getAllValues

protected long[] getAllValues(TestModule.Timer[] timers)
Gets all values from the Timers'.

Parameters:
timers - The array of Timers to retrived the values from.
Returns:
The array of values.

runTest

public void runTest()
Starts the test and initialize import variables. The test is started by creating a new Sender thread.


notifyAboutRunComplete

protected void notifyAboutRunComplete()
Notifies the TestModule that the run is completed and the next run can be started. If the last run is completed, the programs sleeps to ensure that the last messages arrive before the report is printed.


getId

public int getId()
Generates an id from the counter before the counter is incremented.

Returns:
An id to be used in the message.

getLastId

public int getLastId()
Gets the previous id.

Returns:
The previous id.

getTimeInSeconds

protected static java.lang.String getTimeInSeconds(long nanos)
Converts from nanoseconds to seconds.

Parameters:
nanos - The amount of nanoseconds to convert.
Returns:
The amount of seconds as a String.

getThreeDigitString

protected static java.lang.String getThreeDigitString(long number)
Converts from a number to a string of three digits by filling in zeros before the number. Two zeros are added if the number is lower than 10 (converts from 7 to 007) and one zero is added if the number is between 10 and 100 (converts from 13 to 013).

Parameters:
number - The number to be converted.
Returns:
The converted three digit String.

notifyAboutIntervalComplete

protected abstract void notifyAboutIntervalComplete()
Notifies the TestModules that the interval is complete.


getInitialInterval

protected abstract long getInitialInterval()
Gets the initial interval to use between sends.

Returns:
The initial interval.

getInitialMessage

protected abstract java.lang.String getInitialMessage()
Gets the initial message to send.

Returns:
The initial message.

getHeaders

protected abstract java.lang.String[] getHeaders()
Gets the headers for the coloumns in the report.

Returns:
The coloumn headers.

getTitle

protected abstract java.lang.String getTitle()
Gets the title for the report.

Returns:
The report title.

getStringToSend

protected abstract java.lang.String getStringToSend(int id)
Gets the String to send.

Parameters:
id - The id of the message to send.
Returns:
The String to send.