added some compile fixes (didn't define static variables in nxsitems and nxstransaction)

added new nxs net test hub code for testing nxs netservice (fails at the moment) 
also a completed definitions and other related compile time issue due to incorrect inheritance statements

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-new_cache_system@5290 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
chrisparker126 2012-07-12 20:18:58 +00:00
parent 51d6396c9f
commit 24f6f874f2
13 changed files with 634 additions and 54 deletions

View file

@ -1,5 +1,74 @@
#include "nxstesthub.h"
NxsTestHub::NxsTestHub()
NxsTestHub::NxsTestHub(NxsTestScenario* nts) : mTestScenario(nts)
{
netServicePairs.first = new RsGxsNetService(0, mTestScenario->dummyDataService1(), &netMgr1, mTestScenario);
netServicePairs.second = new RsGxsNetService(0, mTestScenario->dummyDataService2(), &netMgr2, mTestScenario);
mServicePairs.first = netServicePairs.first;
mServicePairs.second = netServicePairs.second;
createThread(*(netServicePairs.first));
createThread(*(netServicePairs.second));
}
NxsTestHub::~NxsTestHub()
{
delete netServicePairs.first;
delete netServicePairs.second;
}
void NxsTestHub::run()
{
std::list<RsItem*> send_queue_s1, send_queue_s2;
while(isRunning()){
// make thread sleep for a couple secs
usleep(300);
p3Service* s1 = mServicePairs.first;
p3Service* s2 = mServicePairs.second;
RsItem* item = NULL;
while((item = s1->send()) != NULL)
{
send_queue_s1.push_back(item);
}
while((item = s2->send()) != NULL)
{
send_queue_s2.push_back(item);
}
while(!send_queue_s1.empty()){
item = send_queue_s1.front();
s2->receive(dynamic_cast<RsRawItem*>(item));
send_queue_s1.pop_front();
}
while(!send_queue_s2.empty()){
item = send_queue_s2.front();
s1->receive(dynamic_cast<RsRawItem*>(item));
send_queue_s2.pop_front();
}
// tick services so nxs net services processe items
s1->tick();
s2->tick();
}
// also shut down this net service peers if this goes down
netServicePairs.first->join();
netServicePairs.second->join();
}
bool NxsTestHub::testsPassed()
{
return false;
}

View file

@ -3,35 +3,83 @@
#include "util/rsthreads.h"
#include "gxs/rsgxsnetservice.h"
#include "nxstestscenario.h"
/*!
* This scenario module allows you to model
* simply back and forth conversation between nxs and a virtual peer
* (this module being the virtual peer)
*/
class NxsScenario
// 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
class NxsNetDummyMgr1 : public RsNxsNetMgr
{
static int SCENARIO_OUTGOING;
static int SCENARIO_INCOMING;
public:
virtual int scenarioType() = 0;
NxsNetDummyMgr1() : mOwnId("peerA") {
virtual void receive(RsNxsItem* ) = 0;
virtual RsNxsItem* send() = 0;
mPeers.insert("peerB");
}
std::string getOwnId() { return mOwnId; }
void getOnlineList(std::set<std::string>& ssl_peers) { ssl_peers = mPeers; }
private:
std::string mOwnId;
std::set<std::string> mPeers;
};
class NxsNetDummyMgr2 : public RsNxsNetMgr
{
public:
NxsNetDummyMgr2() : mOwnId("peerB") {
mPeers.insert("peerA");
}
std::string getOwnId() { return mOwnId; }
void getOnlineList(std::set<std::string>& ssl_peers) { ssl_peers = mPeers; }
private:
std::string mOwnId;
std::set<std::string> mPeers;
};
/*!
* 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
*/
class NxsTestHub : public RsThread
{
public:
NxsTestHub(NxsScenario* , std::pair<RsGxsNetService*, RsGxsNetService*> servicePair);
/*!
* This construct the test hub
* for a give scenario in mind
*/
NxsTestHub(NxsTestScenario*);
/*!
*
*/
virtual ~NxsTestHub();
/*!
* To be called only after this thread has
@ -39,7 +87,22 @@ public:
*/
bool testsPassed();
/*!
* This simulates the p3Service ticker and calls both gxs net services tick methods
* Also enables transport of messages between both services
*/
void run();
private:
std::pair<p3Service*, p3Service*> mServicePairs;
std::pair<RsGxsNetService*, RsGxsNetService*> netServicePairs;
NxsTestScenario *mTestScenario;
NxsNetDummyMgr1 netMgr1;
NxsNetDummyMgr2 netMgr2;
};
#endif // NXSTESTHUB_H

View file

@ -0,0 +1,147 @@
/*
* nxstestscenario.cc
*
* Created on: 10 Jul 2012
* Author: crispy
*/
#include "nxstestscenario.h"
#include "gxs/rsdataservice.h"
#include "data_support.h"
NxsMessageTest::NxsMessageTest()
{
mStorePair.first = new RsDataService(".", "dStore1", 0);
mStorePair.second = new RsDataService(".", "dStore2", 0);
setUpDataBases();
}
std::string NxsMessageTest::getTestName()
{
return std::string("Nxs Message Test!");
}
NxsMessageTest::~NxsMessageTest(){
delete mStorePair.first;
delete mStorePair.second;
}
void NxsMessageTest::setUpDataBases()
{
// create several groups and then messages of that
// group for both second and first of pair
RsDataService* dStore = dynamic_cast<RsDataService*>(mStorePair.first);
populateStore(dStore);
dStore = dynamic_cast<RsDataService*>(mStorePair.second);
populateStore(dStore);
dStore = NULL;
return;
}
void NxsMessageTest::populateStore(RsGeneralDataService* dStore)
{
int nGrp = rand()%7;
std::vector<std::string> grpIdList;
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
RsNxsGrp* grp = NULL;
RsGxsGrpMetaData* grpMeta =NULL;
for(int i = 0; i < nGrp; i++)
{
std::pair<RsNxsGrp*, RsGxsGrpMetaData*> p;
grp = new RsNxsGrp(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
grpMeta = new RsGxsGrpMetaData();
p.first = grp;
p.second = grpMeta;
init_item(*grp);
init_item(grpMeta);
grpMeta->mGroupId = grp->grpId;
grps.insert(p);
grpIdList.push_back(grp->grpId);
grpMeta = NULL;
grp = NULL;
}
dStore->storeGroup(grps);
std::map<RsNxsGrp*, RsGxsGrpMetaData*>::iterator grp_it
= grps.begin();
for(; grp_it != grps.end(); grp_it++)
{
delete grp_it->first;
delete grp_it->second;
}
int nMsgs = rand()%23;
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
RsNxsMsg* msg = NULL;
RsGxsMsgMetaData* msgMeta = NULL;
for(int i=0; i<nMsgs; i++)
{
msg = new RsNxsMsg(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
msgMeta = new RsGxsMsgMetaData();
init_item(*msg);
init_item(msgMeta);
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
int chosen = 0;
const std::string& grpId = grpIdList[rand()%nGrp];
msgMeta->mMsgId = msg->msgId;
msgMeta->mGroupId = msg->grpId = grpId;
msg = NULL;
msgMeta = NULL;
msgs.insert(p);
}
dStore->storeMessage(msgs);
// clean up
std::map<RsNxsMsg*, RsGxsMsgMetaData*>::iterator msg_it
= msgs.begin();
for(; msg_it != msgs.end(); msg_it++)
{
delete msg_it->first;
delete msg_it->second;
}
return;
}
void NxsMessageTest::notifyNewMessages(std::vector<RsNxsMsg*>& messages)
{
std::vector<RsNxsMsg*>::iterator vit = messages.begin();
for(; vit != messages.end(); vit++)
{
mPeerMsgs[(*vit)->PeerId()].push_back(*vit);
}
}
void NxsMessageTest::notifyNewGroups(std::vector<RsNxsGrp*>& groups)
{
std::vector<RsNxsGrp*>::iterator vit = groups.begin();
for(; vit != groups.end(); vit++)
{
mPeerGrps[(*vit)->PeerId()].push_back(*vit);
}
}
RsGeneralDataService* NxsMessageTest::dummyDataService1()
{
return mStorePair.first;
}
RsGeneralDataService* NxsMessageTest::dummyDataService2()
{
return mStorePair.second;
}

View file

@ -0,0 +1,68 @@
/*
* nxstestscenario.h
*
* Created on: 10 Jul 2012
* Author: crispy
*/
#ifndef NXSTESTSCENARIO_H_
#define NXSTESTSCENARIO_H_
#include <map>
#include "gxs/rsdataservice.h"
#include "gxs/rsnxsobserver.h"
/*!
* This scenario module provides data resources
*/
class NxsTestScenario : public RsNxsObserver
{
public:
virtual std::string getTestName() = 0;
virtual RsGeneralDataService* dummyDataService1() = 0;
virtual RsGeneralDataService* dummyDataService2() = 0;
};
class NxsMessageTest : public NxsTestScenario
{
public:
NxsMessageTest();
virtual ~NxsMessageTest();
std::string getTestName();
RsGeneralDataService* dummyDataService1();
RsGeneralDataService* dummyDataService2();
public:
/*!
* @param messages messages are deleted after function returns
*/
void notifyNewMessages(std::vector<RsNxsMsg*>& messages);
/*!
* @param messages messages are deleted after function returns
*/
void notifyNewGroups(std::vector<RsNxsGrp*>& groups);
private:
void setUpDataBases();
void populateStore(RsGeneralDataService* dStore);
private:
std::string mTestName;
std::pair<RsGeneralDataService*, RsGeneralDataService*> mStorePair;
std::map<std::string, std::vector<RsNxsMsg*> > mPeerMsgs;
std::map<std::string, std::vector<RsNxsGrp*> > mPeerGrps;
};
#endif /* NXSTESTSCENARIO_H_ */

View file

@ -0,0 +1,34 @@
/*
* rsgxsnetservice_test.cc
*
* Created on: 11 Jul 2012
* Author: crispy
*/
#include "util/utest.h"
#include "nxstesthub.h"
#include "nxstestscenario.h"
INITTEST();
int main()
{
// first setup
NxsMessageTest msgTest;
NxsTestHub hub(&msgTest);
// now get things started
createThread(hub);
// put this thread to sleep for 10 secs
usleep(10000);
hub.join();
CHECK(hub.testsPassed());
FINALREPORT("RsGxsNetService Tests");
return TESTRESULT();
}