2014-04-05 03:27:18 -04:00
|
|
|
#ifndef NXSTESTHUB_H
|
|
|
|
#define NXSTESTHUB_H
|
|
|
|
|
|
|
|
#include "util/rsthreads.h"
|
|
|
|
#include "gxs/rsgxsnetservice.h"
|
|
|
|
#include "nxstestscenario.h"
|
2014-04-19 06:20:07 -04:00
|
|
|
#include <queue>
|
2014-04-05 03:27:18 -04:00
|
|
|
|
|
|
|
// it would probably be useful if the test scenario
|
|
|
|
// provided the net dummy managers
|
|
|
|
// hence one could envision synchronising between an arbitrary number
|
|
|
|
// of peers
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
namespace rs_nxs_test
|
|
|
|
{
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-18 17:58:14 -04:00
|
|
|
class RecvPeerItemIface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~RecvPeerItemIface(){}
|
|
|
|
virtual bool recvItem(RsRawItem *item, const RsPeerId& peerFrom) =0 ;
|
|
|
|
};
|
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
/*!
|
|
|
|
* Testing of nxs services occurs through use of two services
|
|
|
|
* When a service sends this class can interrogate the send and the receives of
|
|
|
|
*
|
|
|
|
* NxsScenario stores the type of synchronisation to be tested
|
|
|
|
* Operation:
|
|
|
|
* First NxsTestHub needs to be instantiated with a test scenario
|
|
|
|
* * The scenario contains two databases to be used on the communicating pair of RsGxsNetService instances (net instances)
|
|
|
|
* The Test hub has a ticker service for the p3Services which allows the netservices to search what groups and messages they have
|
|
|
|
* and synchronise according to their subscriptions. The default is to subscribe to all groups held by other peer
|
|
|
|
* The threads for both net instances are started which begins their processing of transactions
|
|
|
|
*/
|
2014-04-18 17:58:14 -04:00
|
|
|
class NxsTestHub : public RsThread, public RecvPeerItemIface
|
2014-04-13 17:52:53 -04:00
|
|
|
{
|
|
|
|
public:
|
2014-04-05 03:27:18 -04:00
|
|
|
|
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
/*!
|
|
|
|
* This constructs the test hub
|
|
|
|
* for a give scenario in mind
|
|
|
|
*/
|
2014-04-18 17:58:14 -04:00
|
|
|
NxsTestHub(NxsTestScenario::pointer testScenario);
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
/*!
|
|
|
|
* This cleans up what ever testing resources are left
|
|
|
|
* including the test scenario
|
|
|
|
*/
|
|
|
|
virtual ~NxsTestHub();
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
/*!
|
|
|
|
* To be called only after end test is called
|
|
|
|
* otherwise undefined
|
|
|
|
*/
|
|
|
|
bool testsPassed();
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
/*!
|
|
|
|
* This simulates the p3Service ticker and calls both gxs net services tick methods
|
|
|
|
* Also enables transport of messages between both services
|
|
|
|
*/
|
2015-12-13 11:22:31 -05:00
|
|
|
void runloop();
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
/*!
|
|
|
|
* Begings test, equivalent to CreateThread(this)
|
|
|
|
*/
|
|
|
|
void StartTest();
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
/*!
|
|
|
|
* Gracefully ends the test
|
|
|
|
*/
|
|
|
|
void EndTest();
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-05-27 17:14:05 -04:00
|
|
|
/*!
|
|
|
|
* Clean up test environment
|
|
|
|
*/
|
|
|
|
void CleanUpTest();
|
2014-04-13 17:52:53 -04:00
|
|
|
/*!
|
|
|
|
* @param messages messages are deleted after function returns
|
|
|
|
*/
|
|
|
|
void notifyNewMessages(const RsPeerId&, std::vector<RsNxsMsg*>& messages);
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
/*!
|
|
|
|
* @param messages messages are deleted after function returns
|
|
|
|
*/
|
|
|
|
void notifyNewGroups(const RsPeerId&, std::vector<RsNxsGrp*>& groups);
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
static void Wait(int seconds);
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-18 17:58:14 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool recvItem(RsRawItem *item, const RsPeerId& peerFrom);
|
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
private:
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
void tick();
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
private:
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-19 06:20:07 -04:00
|
|
|
typedef std::pair<RsPeerId, RsRawItem*> PayLoad;
|
|
|
|
|
2014-04-18 17:58:14 -04:00
|
|
|
typedef std::map<RsPeerId, RsGxsNetService::pointer > PeerNxsMap ;
|
2014-04-13 17:52:53 -04:00
|
|
|
PeerNxsMap mPeerNxsMap;
|
2014-04-18 17:58:14 -04:00
|
|
|
NxsTestScenario::pointer mTestScenario;
|
2014-04-19 06:20:07 -04:00
|
|
|
std::queue<PayLoad> mPayLoad;
|
2014-04-05 03:27:18 -04:00
|
|
|
|
2014-04-13 17:52:53 -04:00
|
|
|
};
|
|
|
|
}
|
2014-04-05 03:27:18 -04:00
|
|
|
#endif // NXSTESTHUB_H
|