2014-04-13 17:52:53 -04:00
|
|
|
/*
|
|
|
|
* nxsmsgsync_test.cc
|
|
|
|
*
|
|
|
|
* Created on: 13 Apr 2014
|
|
|
|
* Author: crispy
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-04-26 06:07:25 -04:00
|
|
|
#include "nxsmsgsync_test.h"
|
|
|
|
#include "retroshare/rstypes.h"
|
|
|
|
#include "gxs/rsdataservice.h"
|
|
|
|
#include "nxsdummyservices.h"
|
|
|
|
#include "../common/data_support.h"
|
2016-04-04 11:18:42 -04:00
|
|
|
//#include <auto_ptr.h> //Already include in memory, a better way.
|
|
|
|
#include <memory>
|
2014-04-13 17:52:53 -04:00
|
|
|
|
2014-04-26 06:07:25 -04:00
|
|
|
using namespace rs_nxs_test;
|
|
|
|
|
|
|
|
rs_nxs_test::NxsMsgSync::NxsMsgSync()
|
2015-12-13 14:48:55 -05:00
|
|
|
: mPgpUtils(NULL), mServType(0) {
|
2014-04-26 06:07:25 -04:00
|
|
|
int numPeers = 2;
|
|
|
|
|
2014-04-26 19:48:33 -04:00
|
|
|
// create 2 peers
|
2014-04-26 06:07:25 -04:00
|
|
|
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
|
2014-05-18 12:44:19 -04:00
|
|
|
RsGeneralDataService* ds = createDataStore(*it, mServType);
|
2014-04-26 06:07:25 -04:00
|
|
|
mDataServices.insert(std::make_pair(*it, ds));
|
|
|
|
|
|
|
|
// net managers
|
|
|
|
std::list<RsPeerId> otherPeers;
|
|
|
|
copy_all_but<RsPeerId>(*it, mPeerIds, otherPeers);
|
|
|
|
RsNxsNetMgr* mgr = new rs_nxs_test::RsNxsNetDummyMgr(*it, otherPeers);
|
|
|
|
mNxsNetMgrs.insert(std::make_pair(*it, mgr));
|
|
|
|
}
|
|
|
|
|
|
|
|
RsNxsSimpleDummyReputation::RepMap reMap;
|
|
|
|
// now reputation service
|
|
|
|
mRep = new RsNxsSimpleDummyReputation(reMap, true);
|
2014-05-27 17:14:05 -04:00
|
|
|
mCircles = new RsNxsSimpleDummyCircles();
|
2014-04-26 06:07:25 -04:00
|
|
|
|
|
|
|
// lets create 2 groups and all peers will have them
|
|
|
|
int nGrps = 2;
|
|
|
|
|
|
|
|
NxsMsgTestScenario::ExpectedMap& expMap = mExpectedResult;
|
|
|
|
for(int i=0; i < nGrps; i++)
|
|
|
|
{
|
|
|
|
std::auto_ptr<RsNxsGrp> grp = std::auto_ptr<RsNxsGrp>(new RsNxsGrp(mServType));
|
|
|
|
|
|
|
|
init_item(*grp);
|
2014-04-26 19:48:33 -04:00
|
|
|
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
|
|
|
init_item(meta);
|
|
|
|
meta->mReputationCutOff = 0;
|
2014-04-26 06:07:25 -04:00
|
|
|
meta->mGroupId = grp->grpId;
|
|
|
|
grp->metaData = meta;
|
|
|
|
meta->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
|
2014-04-26 19:48:33 -04:00
|
|
|
meta->mCircleType = GXS_CIRCLE_TYPE_PUBLIC;
|
2014-04-26 06:07:25 -04:00
|
|
|
|
|
|
|
RsGxsGroupId grpId = grp->grpId;
|
|
|
|
|
2014-04-26 19:48:33 -04:00
|
|
|
// the expected result is that each peer has all messages
|
2014-04-26 06:07:25 -04:00
|
|
|
it = mPeerIds.begin();
|
|
|
|
|
|
|
|
DataMap::iterator mit = mDataServices.begin();
|
|
|
|
|
|
|
|
// add a clone of group into the peer's service
|
|
|
|
// then create 2 msgs for each peer for each group
|
|
|
|
for(; mit != mDataServices.end(); mit++)
|
|
|
|
{
|
|
|
|
// first store grp
|
|
|
|
RsGeneralDataService* ds = mit->second;
|
|
|
|
RsNxsGrp* grp_clone = grp->clone();
|
|
|
|
RsGeneralDataService::GrpStoreMap gsp;
|
|
|
|
gsp.insert(std::make_pair(grp_clone, grp_clone->metaData));
|
|
|
|
ds->storeGroup(gsp);
|
|
|
|
|
|
|
|
RsGxsGroupId grpId = grp->grpId;
|
|
|
|
RsPeerId peerId = mit->first;
|
|
|
|
|
|
|
|
NxsMsgTestScenario::ExpectedMsgs expMsgs;
|
|
|
|
int nMsgs = 2; // and each grp for each peer gets a unique message
|
|
|
|
for(int j=0; j < nMsgs; j++)
|
|
|
|
{
|
|
|
|
RsNxsMsg* msg = new RsNxsMsg(mServType);
|
|
|
|
init_item(*msg);
|
|
|
|
msg->grpId = grp->grpId;
|
|
|
|
RsGxsMsgMetaData* msgMeta = new RsGxsMsgMetaData();
|
|
|
|
init_item(msgMeta);
|
|
|
|
msgMeta->mGroupId = grp->grpId;
|
2014-04-26 19:48:33 -04:00
|
|
|
msgMeta->mMsgId = msg->msgId;
|
2014-04-26 06:07:25 -04:00
|
|
|
RsGeneralDataService::MsgStoreMap msm;
|
|
|
|
msm.insert(std::make_pair(msg , msgMeta));
|
|
|
|
RsGxsMessageId msgId = msg->msgId;
|
|
|
|
ds->storeMessage(msm);
|
|
|
|
|
|
|
|
it = mPeerIds.begin();
|
|
|
|
|
|
|
|
// the expectation is that all peers have the same messages
|
|
|
|
for(; it != mPeerIds.end(); it++)
|
|
|
|
{
|
|
|
|
NxsMsgTestScenario::ExpectedMsgs& expMsgs = expMap[peerId];
|
|
|
|
expMsgs[grpId].push_back(msgId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rs_nxs_test::NxsMsgSync::getPeers(std::list<RsPeerId>& peerIds) {
|
|
|
|
peerIds = mPeerIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsGeneralDataService* rs_nxs_test::NxsMsgSync::getDataService(
|
|
|
|
const RsPeerId& peerId) {
|
|
|
|
return mDataServices[peerId];
|
|
|
|
}
|
|
|
|
|
|
|
|
RsNxsNetMgr* rs_nxs_test::NxsMsgSync::getDummyNetManager(
|
|
|
|
const RsPeerId& peerId) {
|
|
|
|
return mNxsNetMgrs[peerId];
|
|
|
|
}
|
|
|
|
|
|
|
|
RsGcxs* rs_nxs_test::NxsMsgSync::getDummyCircles(const RsPeerId& peerId) {
|
|
|
|
return mCircles;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsGixsReputation* rs_nxs_test::NxsMsgSync::getDummyReputations(
|
|
|
|
const RsPeerId& peerId) {
|
|
|
|
return mRep;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t rs_nxs_test::NxsMsgSync::getServiceType() {
|
|
|
|
return mServType;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsServiceInfo rs_nxs_test::NxsMsgSync::getServiceInfo() {
|
|
|
|
return mServInfo;
|
|
|
|
}
|
|
|
|
|
2014-05-27 17:14:05 -04:00
|
|
|
PgpAuxUtils* rs_nxs_test::NxsMsgSync::getDummyPgpUtils()
|
|
|
|
{
|
|
|
|
return mPgpUtils;
|
|
|
|
}
|
|
|
|
|
2014-04-26 06:07:25 -04:00
|
|
|
const NxsMsgTestScenario::ExpectedMap& rs_nxs_test::NxsMsgSync::getExpectedMap() {
|
|
|
|
return mExpectedResult;
|
|
|
|
}
|