mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-11 23:49:38 -05:00
- reviving nxs tests for gtest framework
- removed double update bug thunder found git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7275 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5be7910cf5
commit
e916299ceb
@ -748,11 +748,6 @@ bool p3IdService::updateGroup(uint32_t& token, RsGxsIdGroup &group)
|
||||
|
||||
RsGenExchange::updateGroup(token, item);
|
||||
|
||||
|
||||
RsGxsGroupUpdateMeta updateMeta(RsGxsGroupId(id.toStdString()));
|
||||
RsGenExchange::updateGroup(token, item);
|
||||
|
||||
|
||||
// if its in the cache - clear it.
|
||||
{
|
||||
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
|
||||
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* nxsdummyservices.cc
|
||||
*
|
||||
* Created on: 13 Apr 2014
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
|
||||
#include "nxsdummyservices.h"
|
||||
|
||||
|
||||
|
||||
rs_nxs_test::RsNxsSimpleDummyCircles::RsNxsSimpleDummyCircles(
|
||||
std::list<Membership>& membership, bool cached) {
|
||||
}
|
||||
|
||||
bool rs_nxs_test::RsNxsSimpleDummyCircles::isLoaded(
|
||||
const RsGxsCircleId& circleId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rs_nxs_test::RsNxsSimpleDummyCircles::loadCircle(
|
||||
const RsGxsCircleId& circleId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int rs_nxs_test::RsNxsSimpleDummyCircles::canSend(const RsGxsCircleId& circleId,
|
||||
const RsPgpId& id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int rs_nxs_test::RsNxsSimpleDummyCircles::canReceive(
|
||||
const RsGxsCircleId& circleId, const RsPgpId& id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rs_nxs_test::RsNxsSimpleDummyCircles::recipients(
|
||||
const RsGxsCircleId& circleId, std::list<RsPgpId>& friendlist) {
|
||||
return true;
|
||||
}
|
||||
|
||||
rs_nxs_test::RsNxsSimpleDummyReputation::RsNxsSimpleDummyReputation(
|
||||
RepMap& repMap, bool cached) {
|
||||
}
|
||||
|
||||
bool rs_nxs_test::RsNxsSimpleDummyReputation::haveReputation(
|
||||
const RsGxsId& id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rs_nxs_test::RsNxsSimpleDummyReputation::loadReputation(const RsGxsId& id,
|
||||
const std::list<RsPeerId>& peers) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rs_nxs_test::RsNxsSimpleDummyReputation::getReputation(const RsGxsId& id,
|
||||
GixsReputation& rep) {
|
||||
return true;
|
||||
}
|
101
tests/unittests/libretroshare/gxs/nxs_test/nxsdummyservices.h
Normal file
101
tests/unittests/libretroshare/gxs/nxs_test/nxsdummyservices.h
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* nxsdummyservices.h
|
||||
*
|
||||
* Created on: 13 Apr 2014
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef NXSDUMMYSERVICES_H_
|
||||
#define NXSDUMMYSERVICES_H_
|
||||
|
||||
|
||||
namespace rs_nxs_test
|
||||
{
|
||||
|
||||
|
||||
/*!
|
||||
* This dummy circles implementation
|
||||
* allow instantiation with simple membership
|
||||
* list for a given circle
|
||||
*/
|
||||
class RsNxsSimpleDummyCircles : public RsGcxs
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
typedef std::map<RsGxsCircleId, std::list<RsPgpId> > Membership;
|
||||
|
||||
/*!
|
||||
*
|
||||
* @param membership
|
||||
* @param cached
|
||||
*/
|
||||
RsNxsSimpleDummyCircles(std::list<Membership>& membership, bool cached)
|
||||
|
||||
/* GXS Interface - for working out who can receive */
|
||||
bool isLoaded(const RsGxsCircleId &circleId);
|
||||
bool loadCircle(const RsGxsCircleId &circleId);
|
||||
|
||||
int canSend(const RsGxsCircleId &circleId, const RsPgpId &id);
|
||||
int canReceive(const RsGxsCircleId &circleId, const RsPgpId &id);
|
||||
bool recipients(const RsGxsCircleId &circleId, std::list<RsPgpId> &friendlist);
|
||||
|
||||
private:
|
||||
|
||||
std::list<Membership> mMembership;
|
||||
};
|
||||
|
||||
/*!
|
||||
* This dummy reputation allows you to set the
|
||||
* reputations of peers
|
||||
*/
|
||||
class RsNxsSimpleDummyReputation : public RsGixsReputation
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<RsGxsId, GixsReputation> RepMap;
|
||||
|
||||
|
||||
/*!
|
||||
* Instantiate the dummy rep service with
|
||||
* a reputation map
|
||||
* @param repMap should contain the reputations of a set of ids
|
||||
* @param cached this means initial call for an ids \n
|
||||
* rep will return false, until a request has been made to load it
|
||||
*/
|
||||
RsNxsSimpleDummyReputation(RepMap& repMap, bool cached );
|
||||
|
||||
bool haveReputation(const RsGxsId &id);
|
||||
bool loadReputation(const RsGxsId &id, const std::list<RsPeerId>& peers);
|
||||
bool getReputation(const RsGxsId &id, GixsReputation &rep);
|
||||
|
||||
private:
|
||||
|
||||
RepMap mRepMap;
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* Very simple net manager
|
||||
*/
|
||||
class RsNxsNetDummyMgr : public RsNxsNetMgr
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
RsNxsNetDummyMgr(RsPeerId ownId, std::set<RsPeerId> peers) : mOwnId(ownId), mPeers(peers) {
|
||||
|
||||
}
|
||||
|
||||
const RsPeerId& getOwnId() { return mOwnId; }
|
||||
void getOnlineList(uint32_t serviceId, std::set<RsPeerId>& ssl_peers) { ssl_peers = mPeers; }
|
||||
|
||||
private:
|
||||
|
||||
RsPeerId mOwnId;
|
||||
std::set<RsPeerId> mPeers;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* NXSDUMMYSERVICES_H_ */
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* nxsgrpsync_test.cc
|
||||
*
|
||||
* Created on: 13 Apr 2014
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "nxsgrpsync_test.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "nxsdummyservices.h"
|
||||
|
||||
using namespace rs_nxs_test;
|
||||
|
||||
template<typename T>
|
||||
void copy_all_but(T& ex, const std::list<T>& s, std::list<T> d)
|
||||
{
|
||||
std::list<T>::const_iterator cit = s.begin();
|
||||
for(; cit != s.end(); cit++)
|
||||
if(*cit != ex)
|
||||
d.push_back(*cit);
|
||||
}
|
||||
|
||||
NxsGrpSync::NxsGrpSync()
|
||||
{
|
||||
// first choose ids
|
||||
|
||||
int numPeers = 2;
|
||||
|
||||
for(int i =0; i < numPeers; i++)
|
||||
{
|
||||
|
||||
|
||||
RsPeerId id = RsPeerId::random();
|
||||
mPeerIds.push_back(id);
|
||||
}
|
||||
|
||||
|
||||
std::list<RsPeerId>::iterator it = mPeerIds.begin();
|
||||
for(; it != mPeerIds.end(); it++)
|
||||
{
|
||||
// data stores
|
||||
RsGeneralDataService* ds = new RsDataService("./", "grp_store" +
|
||||
it->toStdString(), mServType, NULL, "key");
|
||||
mDataServices.insert(*it, ds);
|
||||
|
||||
// net managers
|
||||
std::list<RsPeerId> otherPeers;
|
||||
copy_all_but<RsPeerId>(*it, mPeerIds, otherPeers);
|
||||
RsNxsNetMgr* mgr = new RsNxsNetDummyMgr(*it, otherPeers);
|
||||
mNxsNetMgrs.insert(std::make_pair(*it, mgr));
|
||||
|
||||
// now reputation service
|
||||
mRep = new RsNxsSimpleDummyReputation();
|
||||
mCircles = new RsNxsSimpleDummyCircles();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NxsGrpSync::getPeers(std::list<RsPeerId>& peerIds)
|
||||
{
|
||||
peerIds = mPeerIds;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RsGeneralDataService* NxsGrpSync::getDataService(const RsPeerId& peerId)
|
||||
{
|
||||
return mDataServices[peerId];
|
||||
}
|
||||
|
||||
bool NxsGrpSync::checkTestPassed()
|
||||
{
|
||||
// look at data store of peer1 an compare to peer 2
|
||||
return true;
|
||||
}
|
||||
|
||||
RsNxsNetMgr* NxsGrpSync::getDummyNetManager(const RsPeerId& peerId)
|
||||
{
|
||||
return mNxsNetMgrs[peerId];
|
||||
}
|
||||
|
||||
RsGcxs* NxsGrpSync::getDummyCircles(const RsPeerId& peerId)
|
||||
{
|
||||
return mCircles;
|
||||
}
|
||||
|
||||
RsGixsReputation* NxsGrpSync::getDummyReputations(const RsPeerId& peerId)
|
||||
{
|
||||
return mRep;
|
||||
}
|
||||
|
||||
uint16_t NxsGrpSync::getServiceType()
|
||||
{
|
||||
}
|
40
tests/unittests/libretroshare/gxs/nxs_test/nxsgrpsync_test.h
Normal file
40
tests/unittests/libretroshare/gxs/nxs_test/nxsgrpsync_test.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* nxsgrpsync_test.h
|
||||
*
|
||||
* Created on: 13 Apr 2014
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef NXSGRPSYNC_TEST_H_
|
||||
#define NXSGRPSYNC_TEST_H_
|
||||
|
||||
|
||||
#include "nxstestscenario.h"
|
||||
|
||||
class NxsGrpSync : public NxsTestScenario
|
||||
{
|
||||
public:
|
||||
|
||||
NxsGrpSync();
|
||||
|
||||
void getPeers(std::list<RsPeerId>& peerIds);
|
||||
RsGeneralDataService* getDataService(const RsPeerId& peerId);
|
||||
bool checkTestPassed();
|
||||
RsNxsNetMgr* getDummyNetManager(const RsPeerId& peerId);
|
||||
RsGcxs* getDummyCircles(const RsPeerId& peerId);
|
||||
RsGixsReputation* getDummyReputations(const RsPeerId& peerId);
|
||||
uint16_t getServiceType();
|
||||
|
||||
private:
|
||||
|
||||
std::list<RsPeerId> mPeerIds;
|
||||
std::map<RsPeerId, RsGeneralDataService*> mDataServices;
|
||||
std::map<RsPeerId, RsNxsNetMgr*> mNxsNetMgrs;
|
||||
RsGixsReputation* mRep;
|
||||
RsGcxs* mCircles;
|
||||
|
||||
int mServType;
|
||||
};
|
||||
|
||||
|
||||
#endif /* NXSGRPSYNC_TEST_H_ */
|
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* nxsmsgsync_test.cc
|
||||
*
|
||||
* Created on: 13 Apr 2014
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
51
tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.h
Normal file
51
tests/unittests/libretroshare/gxs/nxs_test/nxsmsgsync_test.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* nxsmsgsync_test.h
|
||||
*
|
||||
* Created on: 13 Apr 2014
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef NXSMSGSYNC_TEST_H_
|
||||
#define NXSMSGSYNC_TEST_H_
|
||||
|
||||
|
||||
|
||||
|
||||
class NxsMessageTest : public NxsTestScenario
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
NxsMessageTest(uint16_t servtype);
|
||||
virtual ~NxsMessageTest();
|
||||
std::string getTestName();
|
||||
uint16_t getServiceType();
|
||||
RsGeneralDataService* getDataService(const RsPeerId& peer);
|
||||
|
||||
/*!
|
||||
* Call to remove files created
|
||||
* in the test directory
|
||||
*/
|
||||
void cleanUp();
|
||||
|
||||
bool testPassed();
|
||||
|
||||
private:
|
||||
void setUpDataBases();
|
||||
void populateStore(RsGeneralDataService* dStore);
|
||||
|
||||
private:
|
||||
|
||||
std::string mTestName;
|
||||
std::map<RsPeerId, RsGeneralDataService*> mPeerStoreMap;
|
||||
std::set<std::string> mStoreNames;
|
||||
uint16_t mServType;
|
||||
|
||||
RsMutex mMsgTestMtx;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* NXSMSGSYNC_TEST_H_ */
|
@ -1,130 +1,193 @@
|
||||
#include "nxstesthub.h"
|
||||
|
||||
NxsTestHub::NxsTestHub(NxsTestScenario * nts, std::set<RsPeerId> &peers) : mTestScenario(nts)
|
||||
|
||||
|
||||
class NotifyWithPeerId : public RsNxsObserver
|
||||
{
|
||||
public:
|
||||
|
||||
std::set<RsPeerId>::iterator sit = peers.begin();
|
||||
NotifyWithPeerId(RsPeerId val, NxsTestHub& hub)
|
||||
: mPeerId(val), mTestHub(hub){
|
||||
|
||||
for(; sit != peers.end(); sit++)
|
||||
{
|
||||
std::set<RsPeerId> msgPeers = peers;
|
||||
|
||||
// add peers all peers except one iterator currently points to
|
||||
msgPeers.erase(*sit);
|
||||
NxsNetDummyMgr* dummyMgr = new NxsNetDummyMgr(*sit, msgPeers);
|
||||
RsGeneralDataService* ds = mTestScenario->getDataService(*sit);
|
||||
NxsMessageTestObserver* obs = new NxsMessageTestObserver(ds);
|
||||
|
||||
RsServiceInfo info;
|
||||
RsGxsNetService* netService =
|
||||
new RsGxsNetService(mTestScenario->getServiceType(),
|
||||
ds, dummyMgr, obs, info);
|
||||
|
||||
|
||||
mNetServices.insert(std::make_pair(*sit, netService));
|
||||
mObservers.insert(std::make_pair(*sit, obs));
|
||||
}
|
||||
|
||||
sit = peers.begin();
|
||||
|
||||
// launch net services
|
||||
for(; sit != peers.end(); sit++)
|
||||
{
|
||||
RsGxsNetService* n = mNetServices[*sit];
|
||||
createThread(*n);
|
||||
mServices.insert(std::make_pair(*sit, n));
|
||||
}
|
||||
}
|
||||
|
||||
NxsTestHub::~NxsTestHub()
|
||||
{
|
||||
std::map<RsPeerId, RsGxsNetService*>::iterator mit = mNetServices.begin();
|
||||
|
||||
for(; mit != mNetServices.end(); mit++)
|
||||
delete mit->second;
|
||||
}
|
||||
|
||||
|
||||
void NxsTestHub::run()
|
||||
{
|
||||
double timeDelta = .2;
|
||||
|
||||
while(isRunning()){
|
||||
|
||||
// make thread sleep for a bit
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
|
||||
std::map<RsPeerId, p3Service*>::iterator mit = mServices.begin();
|
||||
|
||||
for(; mit != mServices.end(); mit++)
|
||||
{
|
||||
p3Service* s = mit->second;
|
||||
s->tick();
|
||||
}
|
||||
|
||||
mit = mServices.begin();
|
||||
|
||||
// collect msgs to send to peers from peers
|
||||
for(; mit != mServices.end(); mit++)
|
||||
{
|
||||
const RsPeerId& peer = mit->first;
|
||||
p3Service* s = mit->second;
|
||||
|
||||
// first store all the sends from all services
|
||||
RsItem* item = NULL;
|
||||
|
||||
while((item = s->send()) != NULL){
|
||||
|
||||
const RsPeerId peerToReceive = item->PeerId();
|
||||
|
||||
// set the peer this item comes from
|
||||
item->PeerId(peer);
|
||||
mPeerQueues[peerToReceive].push_back(item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// now route items to peers
|
||||
std::map<RsPeerId, std::vector<RsItem*> >::iterator mit_queue = mPeerQueues.begin();
|
||||
|
||||
for(; mit_queue != mPeerQueues.end(); mit_queue++)
|
||||
{
|
||||
std::vector<RsItem*>& queueV = mit_queue->second;
|
||||
std::vector<RsItem*>::iterator vit = queueV.begin();
|
||||
const RsPeerId peerToReceive = mit_queue->first;
|
||||
for(; vit != queueV.end(); vit++)
|
||||
{
|
||||
|
||||
RsItem* item = *vit;
|
||||
p3Service* service = mServices[peerToReceive];
|
||||
|
||||
service->receive(dynamic_cast<RsRawItem*>(item));
|
||||
}
|
||||
queueV.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NxsTestHub::cleanUp()
|
||||
{
|
||||
std::map<RsPeerId, RsGxsNetService*>::iterator mit = mNetServices.begin();
|
||||
for(; mit != mNetServices.end(); mit++)
|
||||
void notifyNewMessages(std::vector<RsNxsMsg*>& messages)
|
||||
{
|
||||
RsGxsNetService* n = mit->second;
|
||||
n->join();
|
||||
mTestHub.notifyNewMessages(mPeerId, messages);
|
||||
}
|
||||
|
||||
// also shut down this net service peers if this goes down
|
||||
mTestScenario->cleanUp();
|
||||
void notifyNewGroups(std::vector<RsNxsGrp*>& groups)
|
||||
{
|
||||
mTestHub.notifyNewGroups(mPeerId, groups);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
RsPeerId mPeerId;
|
||||
rs_nxs_test::NxsTestHub& mTestHub;
|
||||
};
|
||||
|
||||
rs_nxs_test::NxsTestHub::NxsTestHub(NxsTestScenario* testScenario)
|
||||
: mTestScenario(testScenario)
|
||||
{
|
||||
std::list<RsPeerId> peers;
|
||||
mTestScenario->getPeers(peers);
|
||||
|
||||
// for each peer get initialise a nxs net instance
|
||||
// and pass this to the simulator
|
||||
|
||||
std::list<RsPeerId>::const_iterator cit = peers.begin();
|
||||
|
||||
for(; cit != peers.end(); cit++)
|
||||
{
|
||||
RsGxsNetService* ns = new RsGxsNetService(mTestScenario->getServiceType(),
|
||||
mTestScenario->getDataService(*cit), mTestScenario->getDummyNetManager(*cit),
|
||||
new NotifyWithPeerId(*cit, *this),
|
||||
mTestScenario->getServiceInfo(), mTestScenario->getDummyReputations(*cit),
|
||||
mTestScenario->getDummyCircles(*cit), true);
|
||||
|
||||
mPeerNxsMap.insert(std::make_pair(*cit, ns));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rs_nxs_test::NxsTestHub::~NxsTestHub() {
|
||||
}
|
||||
|
||||
|
||||
bool rs_nxs_test::NxsTestHub::testsPassed()
|
||||
{
|
||||
return mTestScenario->checkTestPassed();
|
||||
}
|
||||
|
||||
|
||||
void rs_nxs_test::NxsTestHub::run()
|
||||
{
|
||||
bool running = isRunning();
|
||||
double timeDelta = .2;
|
||||
while(running)
|
||||
{
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
tick();
|
||||
|
||||
running = isRunning();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void rs_nxs_test::NxsTestHub::StartTest()
|
||||
{
|
||||
// get all services up and running
|
||||
PeerNxsMap::iterator mit = mPeerNxsMap.begin();
|
||||
for(; mit != mPeerNxsMap.end(); mit++)
|
||||
{
|
||||
createThread(*(mit->second));
|
||||
}
|
||||
|
||||
createThread(*this);
|
||||
}
|
||||
|
||||
|
||||
void rs_nxs_test::NxsTestHub::EndTest()
|
||||
{
|
||||
// then stop this thread
|
||||
join();
|
||||
|
||||
// stop services
|
||||
PeerNxsMap::iterator mit = mPeerNxsMap.begin();
|
||||
for(; mit != mPeerNxsMap.end(); mit++)
|
||||
{
|
||||
mit->second->join();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool NxsTestHub::testsPassed()
|
||||
void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid,
|
||||
std::vector<RsNxsMsg*>& messages)
|
||||
{
|
||||
return false;
|
||||
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> toStore;
|
||||
std::vector<RsNxsMsg*>::iterator it = messages.begin();
|
||||
for(; it != messages.end(); it++)
|
||||
{
|
||||
RsNxsMsg* msg = *it;
|
||||
RsGxsMsgMetaData* meta = new RsGxsMsgMetaData();
|
||||
bool ok = meta->deserialise(msg->meta.bin_data, msg->meta.bin_len);
|
||||
toStore.insert(std::make_pair(msg, meta));
|
||||
}
|
||||
|
||||
RsDataService* ds = mTestScenario->getDataService(pid);
|
||||
ds->storeMessage(toStore);
|
||||
}
|
||||
|
||||
|
||||
void rs_nxs_test::NxsTestHub::notifyNewGroups(const RsPeerId& pid, std::vector<RsNxsGrp*>& groups)
|
||||
{
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> toStore;
|
||||
std::vector<RsNxsGrp*>::iterator it = groups.begin();
|
||||
for(; it != groups.end(); it++)
|
||||
{
|
||||
RsNxsGrp* grp = *it;
|
||||
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
||||
bool ok = meta->deserialise(grp->meta.bin_data, grp->meta.bin_len);
|
||||
toStore.insert(std::make_pair(grp, meta));
|
||||
}
|
||||
|
||||
RsDataService* ds = mTestScenario->getDataService(pid);
|
||||
ds->storeGroup(toStore);
|
||||
}
|
||||
|
||||
void rs_nxs_test::NxsTestHub::Wait(int seconds) {
|
||||
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (1000000));
|
||||
#else
|
||||
Sleep((int) (1000));
|
||||
#endif
|
||||
}
|
||||
|
||||
void rs_nxs_test::NxsTestHub::tick()
|
||||
{
|
||||
// for each nxs instance pull out all items from each and then move to destination peer
|
||||
|
||||
typedef std::map<RsPeerId, std::list<RsItem*> > DestMap;
|
||||
|
||||
PeerNxsMap::iterator it = mPeerNxsMap.begin();
|
||||
DestMap destMap;
|
||||
for(; it != mPeerNxsMap.end(); it++)
|
||||
{
|
||||
RsGxsNetService* s = *it;
|
||||
s->tick();
|
||||
RsItem* item = s->recvItem();
|
||||
|
||||
if(item != NULL)
|
||||
destMap[item->PeerId()].push_back(item);
|
||||
}
|
||||
|
||||
DestMap::iterator dit = destMap.begin();
|
||||
|
||||
for(; dit != destMap.end(); dit++ )
|
||||
{
|
||||
std::list<RsItem*> payload = dit->second;
|
||||
const RsPeerId& pid = dit->first;
|
||||
|
||||
if(mPeerNxsMap.count(pid) > 0)
|
||||
{
|
||||
std::list<RsItem*>::iterator pit = payload.begin();
|
||||
for(; pit != payload.end(); pit)
|
||||
mPeerNxsMap[pid]->recvItem(*pit);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Could not find peer: " << pid << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,79 +11,83 @@
|
||||
// of peers
|
||||
|
||||
|
||||
class NxsNetDummyMgr : public RsNxsNetMgr
|
||||
|
||||
namespace rs_nxs_test
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
NxsNetDummyMgr(RsPeerId ownId, std::set<RsPeerId> peers) : mOwnId(ownId), mPeers(peers) {
|
||||
|
||||
}
|
||||
|
||||
const RsPeerId& getOwnId() { return mOwnId; }
|
||||
void getOnlineList(uint32_t serviceId, std::set<RsPeerId>& ssl_peers) { ssl_peers = mPeers; }
|
||||
|
||||
private:
|
||||
|
||||
RsPeerId mOwnId;
|
||||
std::set<RsPeerId> 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:
|
||||
|
||||
|
||||
/*!
|
||||
* This construct the test hub
|
||||
* for a give scenario in mind
|
||||
* 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
|
||||
*/
|
||||
NxsTestHub(NxsTestScenario*, std::set<RsPeerId>& peers);
|
||||
class NxsTestHub : public RsThread
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
/*!
|
||||
*
|
||||
*/
|
||||
virtual ~NxsTestHub();
|
||||
/*!
|
||||
* This constructs the test hub
|
||||
* for a give scenario in mind
|
||||
*/
|
||||
NxsTestHub(NxsTestScenario* testScenario);
|
||||
|
||||
/*!
|
||||
* To be called only after this thread has
|
||||
* been shutdown
|
||||
*/
|
||||
bool testsPassed();
|
||||
/*!
|
||||
* This cleans up what ever testing resources are left
|
||||
* including the test scenario
|
||||
*/
|
||||
virtual ~NxsTestHub();
|
||||
|
||||
/*!
|
||||
* This simulates the p3Service ticker and calls both gxs net services tick methods
|
||||
* Also enables transport of messages between both services
|
||||
*/
|
||||
void run();
|
||||
/*!
|
||||
* To be called only after end test is called
|
||||
* otherwise undefined
|
||||
*/
|
||||
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();
|
||||
|
||||
void cleanUp();
|
||||
private:
|
||||
/*!
|
||||
* Begings test, equivalent to CreateThread(this)
|
||||
*/
|
||||
void StartTest();
|
||||
|
||||
std::map<RsPeerId, p3Service*> mServices;
|
||||
std::map<RsPeerId, RsGxsNetService*> mNetServices;
|
||||
std::map<RsPeerId, NxsMessageTestObserver*> mObservers;
|
||||
/*!
|
||||
* Gracefully ends the test
|
||||
*/
|
||||
void EndTest();
|
||||
|
||||
std::map<RsPeerId, std::vector<RsItem*> > mPeerQueues;
|
||||
/*!
|
||||
* @param messages messages are deleted after function returns
|
||||
*/
|
||||
void notifyNewMessages(const RsPeerId&, std::vector<RsNxsMsg*>& messages);
|
||||
|
||||
NxsTestScenario *mTestScenario;
|
||||
/*!
|
||||
* @param messages messages are deleted after function returns
|
||||
*/
|
||||
void notifyNewGroups(const RsPeerId&, std::vector<RsNxsGrp*>& groups);
|
||||
|
||||
};
|
||||
static void Wait(int seconds);
|
||||
|
||||
private:
|
||||
|
||||
void tick();
|
||||
|
||||
private:
|
||||
|
||||
typedef std::map<RsPeerId, RsGxsNetService* > PeerNxsMap ;
|
||||
PeerNxsMap mPeerNxsMap;
|
||||
NxsTestScenario *mTestScenario;
|
||||
|
||||
};
|
||||
}
|
||||
#endif // NXSTESTHUB_H
|
||||
|
@ -1,177 +0,0 @@
|
||||
/*
|
||||
* nxstestscenario.cc
|
||||
*
|
||||
* Created on: 10 Jul 2012
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "nxstestscenario.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include "data_support.h"
|
||||
#include <stdio.h>
|
||||
|
||||
NxsMessageTest::NxsMessageTest(uint16_t servtype)
|
||||
: mServType(servtype), mMsgTestMtx("mMsgTestMtx")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string NxsMessageTest::getTestName()
|
||||
{
|
||||
return std::string("Nxs Message Test!");
|
||||
}
|
||||
|
||||
NxsMessageTest::~NxsMessageTest(){
|
||||
|
||||
std::map<std::string, RsGeneralDataService*>::iterator mit = mPeerStoreMap.begin();
|
||||
|
||||
for(; mit != mPeerStoreMap.end(); mit++)
|
||||
{
|
||||
delete mit->second;
|
||||
}
|
||||
|
||||
std::set<std::string>::iterator sit = mStoreNames.begin();
|
||||
|
||||
// remove db file
|
||||
for(; sit != mStoreNames.end(); sit++)
|
||||
{
|
||||
const std::string& name = *sit;
|
||||
remove(name.c_str());
|
||||
}
|
||||
}
|
||||
RsGeneralDataService* NxsMessageTest::getDataService(const std::string& peer)
|
||||
{
|
||||
if(mPeerStoreMap.find(peer) != mPeerStoreMap.end()) return NULL;
|
||||
|
||||
RsDataService* dStore = new RsDataService("./", peer, mServType);
|
||||
mStoreNames.insert(peer);
|
||||
mPeerStoreMap.insert(std::make_pair(peer, dStore));
|
||||
populateStore(dStore);
|
||||
|
||||
return dStore;
|
||||
}
|
||||
|
||||
uint16_t NxsMessageTest::getServiceType()
|
||||
{
|
||||
return mServType;
|
||||
}
|
||||
|
||||
void NxsMessageTest::populateStore(RsGeneralDataService* dStore)
|
||||
{
|
||||
|
||||
int nGrp = (rand()%2)+1;
|
||||
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(mServType);
|
||||
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);
|
||||
|
||||
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(mServType);
|
||||
msgMeta = new RsGxsMsgMetaData();
|
||||
init_item(*msg);
|
||||
init_item(msgMeta);
|
||||
std::pair<RsNxsMsg*, RsGxsMsgMetaData*> p(msg, msgMeta);
|
||||
|
||||
// pick a grp at random to associate the msg to
|
||||
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);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void NxsMessageTest::cleanUp()
|
||||
{
|
||||
|
||||
std::map<std::string, RsGeneralDataService*>::iterator mit = mPeerStoreMap.begin();
|
||||
|
||||
for(; mit != mPeerStoreMap.end(); mit++)
|
||||
{
|
||||
RsGeneralDataService* d = mit->second;
|
||||
d->resetDataStore();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
bool NxsMessageTest::testPassed(){
|
||||
return false;
|
||||
}
|
||||
|
||||
/*******************************/
|
||||
|
||||
NxsMessageTestObserver::NxsMessageTestObserver(RsGeneralDataService *dStore)
|
||||
:mStore(dStore)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NxsMessageTestObserver::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
|
||||
{
|
||||
std::vector<RsNxsGrp*>::iterator vit = groups.begin();
|
||||
std::map<RsNxsGrp*, RsGxsGrpMetaData*> grps;
|
||||
|
||||
for(; vit != groups.end(); vit++)
|
||||
{
|
||||
RsNxsGrp* grp = *vit;
|
||||
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
||||
meta->deserialise(grp->meta.bin_data, grp->meta.bin_len);
|
||||
meta->mSubscribeFlags |= GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
|
||||
meta->mGroupId = grp->grpId;
|
||||
grps.insert(std::make_pair(grp, meta));
|
||||
}
|
||||
|
||||
mStore->storeGroup(grps);
|
||||
}
|
||||
|
||||
void NxsMessageTestObserver::notifyNewMessages(std::vector<RsNxsMsg *> &messages)
|
||||
{
|
||||
|
||||
std::vector<RsNxsMsg*>::iterator vit = messages.begin();
|
||||
std::map<RsNxsMsg*, RsGxsMsgMetaData*> msgs;
|
||||
|
||||
for(; vit != messages.end(); vit++)
|
||||
{
|
||||
RsNxsMsg* msg = *vit;
|
||||
RsGxsMsgMetaData* meta = new RsGxsMsgMetaData();
|
||||
meta->mGroupId = msg->grpId;
|
||||
meta->mMsgId = msg->msgId;
|
||||
msgs.insert(std::make_pair(msg, meta));
|
||||
}
|
||||
|
||||
mStore->storeMessage(msgs);
|
||||
}
|
||||
|
@ -9,98 +9,31 @@
|
||||
#define NXSTESTSCENARIO_H_
|
||||
|
||||
#include <map>
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "gxs/rsnxsobserver.h"
|
||||
|
||||
/*!
|
||||
* This scenario module provides data resources
|
||||
*/
|
||||
class NxsTestScenario
|
||||
namespace rs_nxs_test
|
||||
{
|
||||
/*!
|
||||
* This scenario module provides data resources
|
||||
*/
|
||||
class NxsTestScenario
|
||||
{
|
||||
public:
|
||||
|
||||
public:
|
||||
virtual ~NxsTestScenario() {}
|
||||
|
||||
virtual std::string getTestName() = 0;
|
||||
|
||||
/*!
|
||||
* @param peer
|
||||
* @param namePath
|
||||
* @return data service with populated with random grp/msg data, null if peer or pathname exists
|
||||
*/
|
||||
virtual RsGeneralDataService* getDataService(const RsPeerId& peer) = 0;
|
||||
|
||||
|
||||
virtual bool testPassed() = 0;
|
||||
/*!
|
||||
* Service type for this test
|
||||
* should correspond to serialiser service type
|
||||
*/
|
||||
virtual uint16_t getServiceType() = 0;
|
||||
|
||||
/*!
|
||||
* Call to remove files created
|
||||
* in the test directory
|
||||
*/
|
||||
virtual void cleanUp() = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
class NxsMessageTestObserver : public RsNxsObserver
|
||||
{
|
||||
public:
|
||||
|
||||
NxsMessageTestObserver(RsGeneralDataService* dStore);
|
||||
|
||||
/*!
|
||||
* @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:
|
||||
|
||||
RsGeneralDataService* mStore;
|
||||
|
||||
};
|
||||
|
||||
class NxsMessageTest : public NxsTestScenario
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
NxsMessageTest(uint16_t servtype);
|
||||
virtual ~NxsMessageTest();
|
||||
std::string getTestName();
|
||||
uint16_t getServiceType();
|
||||
RsGeneralDataService* getDataService(const RsPeerId& peer);
|
||||
|
||||
/*!
|
||||
* Call to remove files created
|
||||
* in the test directory
|
||||
*/
|
||||
void cleanUp();
|
||||
|
||||
bool testPassed();
|
||||
|
||||
private:
|
||||
void setUpDataBases();
|
||||
void populateStore(RsGeneralDataService* dStore);
|
||||
|
||||
private:
|
||||
|
||||
std::string mTestName;
|
||||
std::map<RsPeerId, RsGeneralDataService*> mPeerStoreMap;
|
||||
std::set<std::string> mStoreNames;
|
||||
uint16_t mServType;
|
||||
|
||||
RsMutex mMsgTestMtx;
|
||||
|
||||
};
|
||||
virtual void getPeers(std::list<RsPeerId>& peerIds) = 0;
|
||||
virtual RsGeneralDataService* getDataService(const RsPeerId& peerId) = 0;
|
||||
virtual bool checkTestPassed() = 0;
|
||||
virtual RsNxsNetMgr* getDummyNetManager(const RsPeerId& peerId) = 0;
|
||||
virtual RsGcxs* getDummyCircles(const RsPeerId& peerId) = 0;
|
||||
virtual RsGixsReputation* getDummyReputations(const RsPeerId& peerId) = 0;
|
||||
virtual uint16_t getServiceType() = 0;
|
||||
virtual RsServiceInfo getServiceInfo() = 0;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* NXSTESTSCENARIO_H_ */
|
||||
|
@ -5,42 +5,19 @@
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "util/utest.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "nxsgrpsync_test.h"
|
||||
#include "nxstesthub.h"
|
||||
#include "nxstestscenario.h"
|
||||
|
||||
INITTEST();
|
||||
|
||||
|
||||
int main()
|
||||
TEST(libretroshare_gxs, gxs_grp_sync)
|
||||
{
|
||||
NxsGrpSync* gsync_test = new NxsGrpSync();
|
||||
rs_nxs_test::NxsTestHub tHub(gsync_test);
|
||||
tHub.StartTest();
|
||||
rs_nxs_test::NxsTestHub::wait(10);
|
||||
tHub.EndTest();
|
||||
|
||||
// first setup
|
||||
NxsMessageTest msgTest(RS_SERVICE_TYPE_PLUGIN_SIMPLE_FORUM);
|
||||
std::set<std::string> peers;
|
||||
peers.insert("PeerA");
|
||||
peers.insert("PeerB");
|
||||
NxsTestHub hub(&msgTest, peers);
|
||||
|
||||
// now get things started
|
||||
createThread(hub);
|
||||
|
||||
double timeDelta = 50;
|
||||
|
||||
// put this thread to sleep for 10 secs
|
||||
// make thread sleep for a bit
|
||||
#ifndef WINDOWS_SYS
|
||||
usleep((int) (timeDelta * 1000000));
|
||||
#else
|
||||
Sleep((int) (timeDelta * 1000));
|
||||
#endif
|
||||
|
||||
hub.join();
|
||||
CHECK(hub.testsPassed());
|
||||
|
||||
hub.cleanUp();
|
||||
|
||||
FINALREPORT("RsGxsNetService Tests");
|
||||
|
||||
return TESTRESULT();
|
||||
ASSERT_TRUE(tHub.testsPassed());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user