org.ourgrid.test.functionalunits
Class PeerUnit

java.lang.Object
  extended by org.ourgrid.test.functionalunits.PeerUnit
All Implemented Interfaces:
FunctionalTestUnit

public class PeerUnit
extends java.lang.Object
implements FunctionalTestUnit

PeerUnit will represents a peer that will be used to execute functional tests of OurGrid. A default creation of a PeerUnit will find and use a disponible port, address and any other detail that isn't needed to a test. Also is possible interact between functional tests unit to permit a easy way to create and mantain any test. This class will execute scripts to control the peer.


Method Summary
 void destroy()
          This method is used to delete enviroment files that the FunctionalTestUnit uses.
 java.lang.String getAddress()
          Gets the address that this peer is published.
 java.lang.String getDefaultPropertiesFile()
          Returns the default properties file that will be used by this FunctionalTestUnit.
 java.lang.String getHostname()
          Get the hostname of the peer.
 java.io.File getIDFile()
          Gets the idfile being used by this test peer.
 java.lang.String getName()
          Returns the name of this FunctionalTestUnit.
 long getPeerID()
          Get this peerID
 int getPort()
          Get the port of the peer.
 java.lang.Double getRankingForPeer(PeerUnit peerUnit)
          Getts the ranking of a given peer.
 java.io.File getRankingsFile()
          Gets the rankings being used by this test peer.
 boolean gumsBeenSet()
          Verifies if gums have been set.
 java.util.Collection<StatusEntry> gumsInState(AllocationStatus state)
          Verify what gums are in a certain state at this peer.
 boolean isRunning()
          Verify if this peer is running.
 void kill()
          Kills this unit by calling System.exit()
 void setCorePeer(CorePeerUnit corePeer)
          Set the core peer that this peer will contact.
 void setGums(UserAgentUnit... userAgentUnits)
          Set the gums to be used by this PeerUnit.
 void setId(long peerID)
          Sets the ID value of peer
 void setRankingsFile(java.util.Map<PeerUnit,java.lang.Double> rankings)
          Sets the ranking file of Network of Favors
 void start()
          Starts this PeerUnit.
 boolean stillIdle()
          This method verifies if the functional test unit was not waken up since the last waitUntilWorkIsDone() call.
 void stop()
          Stops this PeerUnit.
 void unsetGums()
          Unsets gums being used at this PeerUnit.
 void waitUntilWorkIsDone()
          This method will block until this FunctionalTestUnit has stopped all work.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAddress

public java.lang.String getAddress()
Gets the address that this peer is published.

Returns:
The address that this peer is published.

getName

public java.lang.String getName()
Description copied from interface: FunctionalTestUnit
Returns the name of this FunctionalTestUnit.

Specified by:
getName in interface FunctionalTestUnit
Returns:
The name of this FunctionalTestUnit.
See Also:
FunctionalTestUnit.getName()

getHostname

public java.lang.String getHostname()
Get the hostname of the peer.

Specified by:
getHostname in interface FunctionalTestUnit
Returns:
The hostname of the peer.

getPort

public int getPort()
Get the port of the peer.

Specified by:
getPort in interface FunctionalTestUnit
Returns:
The port of the peer.

getDefaultPropertiesFile

public java.lang.String getDefaultPropertiesFile()
Description copied from interface: FunctionalTestUnit
Returns the default properties file that will be used by this FunctionalTestUnit.

Specified by:
getDefaultPropertiesFile in interface FunctionalTestUnit
See Also:
FunctionalTestUnit.getDefaultPropertiesFile()

setCorePeer

public void setCorePeer(CorePeerUnit corePeer)
                 throws java.lang.Exception
Set the core peer that this peer will contact.

Parameters:
corePeer - CorePeerUnit object to be used as test.
Throws:
java.lang.Exception

setGums

public void setGums(UserAgentUnit... userAgentUnits)
             throws java.lang.Exception
Set the gums to be used by this PeerUnit. This method will block until all gums are IDLE.

Parameters:
userAgentUnits - Units to be set at this peer.
Throws:
java.lang.Exception - If gums could not ber set.

gumsBeenSet

public boolean gumsBeenSet()
Verifies if gums have been set.

Returns:
True if this peer has gums set

start

public void start()
           throws java.lang.Exception
Starts this PeerUnit.

Specified by:
start in interface FunctionalTestUnit
Throws:
java.io.IOException
java.lang.Exception

stop

public void stop()
          throws java.lang.Exception
Stops this PeerUnit.

Specified by:
stop in interface FunctionalTestUnit
Throws:
java.io.IOException
java.lang.Exception

unsetGums

public void unsetGums()
               throws java.lang.Exception
Unsets gums being used at this PeerUnit.

Throws:
java.lang.Exception

isRunning

public boolean isRunning()
Verify if this peer is running.

Specified by:
isRunning in interface FunctionalTestUnit
Returns:
True if this peer is running.
Throws:
java.io.IOException

gumsInState

public java.util.Collection<StatusEntry> gumsInState(AllocationStatus state)
                                              throws java.lang.Exception
Verify what gums are in a certain state at this peer.

Parameters:
state - State of Gums to be returned
Returns:
The gums that are up at this peer.
Throws:
java.lang.Exception

destroy

public void destroy()
Description copied from interface: FunctionalTestUnit
This method is used to delete enviroment files that the FunctionalTestUnit uses.

Specified by:
destroy in interface FunctionalTestUnit
See Also:
FunctionalTestUnit.destroy()

getIDFile

public java.io.File getIDFile()
Gets the idfile being used by this test peer.

Returns:
ID file.

getRankingsFile

public java.io.File getRankingsFile()
Gets the rankings being used by this test peer.

Returns:
ID file.

setId

public void setId(long peerID)
           throws java.lang.Exception
Sets the ID value of peer

Parameters:
peerID - new ID
Throws:
java.lang.Exception

setRankingsFile

public void setRankingsFile(java.util.Map<PeerUnit,java.lang.Double> rankings)
                     throws java.lang.Exception
Sets the ranking file of Network of Favors

Parameters:
rankings - Map containning the relations between Peers and value of balance
Throws:
java.io.FileNotFoundException - if file does not exists
java.io.IOException - if occurred a problem while manipulate the file object
java.lang.Exception

getPeerID

public long getPeerID()
Get this peerID

Returns:
ID of this peer unit

getRankingForPeer

public java.lang.Double getRankingForPeer(PeerUnit peerUnit)
                                   throws java.rmi.RemoteException
Getts the ranking of a given peer.

Parameters:
peerUnit - Peer to get reanking from.
Returns:
Value of the ranking.
Throws:
java.lang.Exception
java.rmi.RemoteException

waitUntilWorkIsDone

public void waitUntilWorkIsDone()
                         throws java.lang.Exception
Description copied from interface: FunctionalTestUnit
This method will block until this FunctionalTestUnit has stopped all work.

Specified by:
waitUntilWorkIsDone in interface FunctionalTestUnit
Throws:
java.lang.Exception

stillIdle

public boolean stillIdle()
                  throws java.lang.Exception
Description copied from interface: FunctionalTestUnit
This method verifies if the functional test unit was not waken up since the last waitUntilWorkIsDone() call.

Specified by:
stillIdle in interface FunctionalTestUnit
Returns:
True if it hasnt.
Throws:
java.lang.Exception

kill

public void kill()
          throws java.lang.Exception
Description copied from interface: FunctionalTestUnit
Kills this unit by calling System.exit()

Specified by:
kill in interface FunctionalTestUnit
Throws:
java.lang.Exception