FRODO Version 2.19.1
An open-source framework for Distributed Constraint Optimization (DCOP)
Loading...
Searching...
No Matches
frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > > Class Template Reference

JUnit test for the class LeaderElectionMaxID. More...

Inheritance diagram for frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >:

Public Member Functions

 LeaderElectionMaxIDTest (String method)
 Constructor that instantiates a test only for the input method.
void testRandomSharedMemory () throws IOException
 Tests the DFS generation protocol on a random graph using QueueIOPipes.
void testRandomTCP () throws IOException
 Tests the DFS generation protocol on a random graph using TCP pipes.
void testRandom (boolean useTCP) throws IOException
 Tests the leader election protocol on a random graph of "agents".
Collection< MessageTypegetMsgTypes ()
void notifyIn (Message msg)
 Keeps track of the output of the leader election protocol sent by each agent.
void setQueue (Queue queue)
 Does nothing in this case.
Public Member Functions inherited from frodo2.communication.IncomingMsgPolicyInterface< T >
default void notifyIn (Message msg, Object toAgent)
 Notifies the listener of an incoming message.

Static Public Member Functions

static TestSuite suite ()
static Map< String, String > computeLeaders (List< String > nodes, List< List< String > > components)
 Compute the leaders.
static< S extends Comparable< S > Map< String, S > computeLeaders (int nbrAgents, List< List< String > > components, Map< String, S > uniqueIDs)
 Compute the leaders.

Protected Member Functions

void setUp ()
void tearDown () throws Exception
 Ends all queues.
Map< String, S > initiatingIDandListener ()
 Compute uniqueID, link them with variable name and generate listeners.
void checkOutputs (Map< String, S > allUniqueIDs)
 Called to verify output correctness.
int getNbrMsgsNeeded ()

Protected Attributes

int nbrAgents
 Number of agents in the test.
Map< String, Queuequeues
 List of queues, indexed by agent name.
Map< String, MessageLEoutput< String > > outputs
 For each agent, the output of LeaderElectionMaxID.
Integer remainingOutputs
 Current number of agents that still need to their output of the leader election protocol.
final ReentrantLock finished_lock = new ReentrantLock ()
 Used to make the test thread wait.
final Condition finished = finished_lock.newCondition()
 Used to wake up the test thread when all agents have finished.
RandGraphFactory.Graph graph
 Random graph used to generate a constraint graph.
Map< String, QueueOutputPipeInterfacepipes
 One output pipe used to send messages to each queue, indexed by the queue's agent name.

Private Attributes

final int maxNbrAgents = 5
 Maximum number of agents in the random graph.
final int maxNbrPipes = 10
 Maximum number of pipes (edges) in the random graph.

Detailed Description

JUnit test for the class LeaderElectionMaxID.

Author
Thomas Leaute
Parameters
<S>type used for scores

Constructor & Destructor Documentation

◆ LeaderElectionMaxIDTest()

Constructor that instantiates a test only for the input method.

Parameters
methodtest method

Referenced by suite().

Member Function Documentation

◆ checkOutputs()

◆ computeLeaders() [1/2]

static< S extends Comparable< S > Map< String, S > frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.computeLeaders ( int nbrAgents,
List< List< String > > components,
Map< String, S > uniqueIDs )
static

Compute the leaders.

Parameters
<S>the type used for the scores
nbrAgentsnumber of agents
componentscomponents in the graph
uniqueIDsfor each variable, its unique ID
Returns
for each agent, its leader

References nbrAgents.

◆ computeLeaders() [2/2]

Map< String, String > frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.computeLeaders ( List< String > nodes,
List< List< String > > components )
static

Compute the leaders.

Parameters
nodeslist of nodes in the graph
componentscomponents in the graph
Returns
for each agent, its leader

References computeLeaders().

Referenced by checkOutputs(), frodo2.algorithms.varOrdering.election.tests.VariableElectionTest< S extends Comparable< S > &Serializable >.checkOutputs(), computeLeaders(), frodo2.algorithms.dpop.privacy.test.SecureRerootingTest.randomTest(), and frodo2.algorithms.varOrdering.dfs.tests.DFSgenerationTest.testRandom().

Here is the call graph for this function:

◆ getMsgTypes()

◆ getNbrMsgsNeeded()

int frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.getNbrMsgsNeeded ( )
protected
Returns
the expected number of messages exchanged

References graph, and nbrAgents.

Referenced by testRandom().

◆ initiatingIDandListener()

Map< String, S > frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.initiatingIDandListener ( )
protected

Compute uniqueID, link them with variable name and generate listeners.

Returns
the map name-id

References frodo2.communication.Queue.addIncomingMessagePolicy(), graph, initiatingIDandListener(), nbrAgents, and queues.

Referenced by initiatingIDandListener(), and testRandom().

Here is the call graph for this function:

◆ notifyIn()

void frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.notifyIn ( Message msg)

Keeps track of the output of the leader election protocol sent by each agent.

See also
IncomingMsgPolicyInterface.notifyIn(Message)

Implements frodo2.communication.IncomingMsgPolicyInterface< T >.

References notifyIn(), and frodo2.algorithms.varOrdering.election.LeaderElectionMaxID< T extends Comparable< T > &Serializable >.OUTPUT_MSG_TYPE.

Referenced by notifyIn().

Here is the call graph for this function:

◆ setQueue()

void frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.setQueue ( Queue queue)

Does nothing in this case.

Parameters
queuethe queue

Implements frodo2.communication.MessageListener< T >.

◆ setUp()

void frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.setUp ( )
protected
See also
junit.framework.TestCase#setUp()

References frodo2.algorithms.RandGraphFactory.getRandGraph(), graph, maxNbrAgents, and maxNbrPipes.

Here is the call graph for this function:

◆ suite()

TestSuite frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.suite ( )
static
Returns
the test suite for this test

References LeaderElectionMaxIDTest().

Referenced by frodo2.algorithms.varOrdering.election.tests.AllTestsElection.suite().

Here is the call graph for this function:

◆ tearDown()

void frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.tearDown ( ) throws Exception
protected

Ends all queues.

See also
junit.framework.TestCase#tearDown()

References graph, outputs, pipes, and queues.

◆ testRandom()

void frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.testRandom ( boolean useTCP) throws IOException

Tests the leader election protocol on a random graph of "agents".

Parameters
useTCPtrue whether TCP pipes should be used instead of QueueIOPipes
Exceptions
IOExceptionthrown if the method fails to create pipes

References checkOutputs(), frodo2.algorithms.test.AllTests.createQueueNetwork(), getNbrMsgsNeeded(), graph, initiatingIDandListener(), nbrAgents, pipes, queues, and frodo2.algorithms.varOrdering.election.LeaderElectionMaxID< T extends Comparable< T > &Serializable >.START_MSG_TYPE.

Referenced by testRandomSharedMemory(), and testRandomTCP().

Here is the call graph for this function:

◆ testRandomSharedMemory()

void frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.testRandomSharedMemory ( ) throws IOException

Tests the DFS generation protocol on a random graph using QueueIOPipes.

Exceptions
IOExceptionthrown if the method fails to create pipes

References testRandom().

Here is the call graph for this function:

◆ testRandomTCP()

void frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.testRandomTCP ( ) throws IOException

Tests the DFS generation protocol on a random graph using TCP pipes.

Exceptions
IOExceptionthrown if the method fails to create pipes

References testRandom().

Here is the call graph for this function:

Member Data Documentation

◆ finished

final Condition frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.finished = finished_lock.newCondition()
protected

Used to wake up the test thread when all agents have finished.

◆ finished_lock

final ReentrantLock frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.finished_lock = new ReentrantLock ()
protected

Used to make the test thread wait.

◆ graph

RandGraphFactory.Graph frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.graph
protected

Random graph used to generate a constraint graph.

Referenced by checkOutputs(), getNbrMsgsNeeded(), initiatingIDandListener(), setUp(), tearDown(), and testRandom().

◆ maxNbrAgents

final int frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.maxNbrAgents = 5
private

Maximum number of agents in the random graph.

Note
Must be at least 2.

Referenced by setUp().

◆ maxNbrPipes

final int frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.maxNbrPipes = 10
private

Maximum number of pipes (edges) in the random graph.

Referenced by setUp().

◆ nbrAgents

int frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.nbrAgents
protected

Number of agents in the test.

Referenced by computeLeaders(), getNbrMsgsNeeded(), initiatingIDandListener(), and testRandom().

◆ outputs

Map< String, MessageLEoutput<String> > frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.outputs
protected

For each agent, the output of LeaderElectionMaxID.

Referenced by checkOutputs(), and tearDown().

◆ pipes

One output pipe used to send messages to each queue, indexed by the queue's agent name.

Referenced by tearDown(), and testRandom().

◆ queues

Map<String, Queue> frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.queues
protected

List of queues, indexed by agent name.

Referenced by initiatingIDandListener(), tearDown(), and testRandom().

◆ remainingOutputs

Integer frodo2.algorithms.varOrdering.election.tests.LeaderElectionMaxIDTest< S extends Comparable< S > >.remainingOutputs
protected

Current number of agents that still need to their output of the leader election protocol.


The documentation for this class was generated from the following file: