mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Added msg sync unit test
- not passing yet but almost, more tweaking needed TODO: identity and circle vet test - added retrieve msg id for convenience - updated .pro file git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7303 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
4cab2aaa65
commit
c6059906d0
@ -191,6 +191,8 @@ RsDataService::RsDataService(const std::string &serviceDir, const std::string &d
|
||||
mMsgOffSetColumns.push_back(KEY_NXS_FILE_LEN);
|
||||
|
||||
grpIdColumn.push_back(KEY_GRP_ID);
|
||||
|
||||
mMsgIdColumn.push_back(KEY_MSG_ID);
|
||||
}
|
||||
|
||||
RsDataService::~RsDataService(){
|
||||
@ -1344,6 +1346,32 @@ int RsDataService::retrieveGroupIds(std::vector<RsGxsGroupId> &grpIds)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int RsDataService::retrieveMsgIds(const RsGxsGroupId& grpId,
|
||||
RsGxsMessageId::std_vector& msgIds) {
|
||||
|
||||
RetroCursor* c = mDb->sqlQuery(MSG_TABLE_NAME, mMsgIdColumn, KEY_GRP_ID+ "='" + grpId.toStdString() + "'", "");
|
||||
|
||||
if(c)
|
||||
{
|
||||
bool valid = c->moveToFirst();
|
||||
|
||||
while(valid)
|
||||
{
|
||||
std::string msgId;
|
||||
c->getString(0, msgId);
|
||||
msgIds.push_back(RsGxsMessageId(msgId));
|
||||
valid = c->moveToNext();
|
||||
}
|
||||
delete c;
|
||||
}else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
bool RsDataService::locked_updateMessageEntries(const MsgUpdates& updates)
|
||||
{
|
||||
// start a transaction
|
||||
|
@ -113,6 +113,14 @@ public:
|
||||
*/
|
||||
int retrieveGroupIds(std::vector<RsGxsGroupId> &grpIds);
|
||||
|
||||
/*!
|
||||
* Retrives all msg ids in store
|
||||
* @param grpId groupId of message ids to retrieve
|
||||
* @param msgId msgsids retrieved
|
||||
* @return error code
|
||||
*/
|
||||
int retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_vector& msgId);
|
||||
|
||||
/*!
|
||||
* @return the cache size set for this RsGeneralDataService in bytes
|
||||
*/
|
||||
@ -249,6 +257,7 @@ private:
|
||||
std::list<std::string> msgColumns;
|
||||
std::list<std::string> msgMetaColumns;
|
||||
std::list<std::string> mMsgOffSetColumns;
|
||||
std::list<std::string> mMsgIdColumn;
|
||||
|
||||
std::list<std::string> grpColumns;
|
||||
std::list<std::string> grpMetaColumns;
|
||||
|
@ -118,6 +118,7 @@ public:
|
||||
public:
|
||||
|
||||
typedef std::map<RsNxsGrp*, RsGxsGrpMetaData*> GrpStoreMap;
|
||||
typedef std::map<RsNxsMsg*, RsGxsMsgMetaData*> MsgStoreMap;
|
||||
|
||||
RsGeneralDataService(){}
|
||||
virtual ~RsGeneralDataService(){return;}
|
||||
@ -179,6 +180,14 @@ public:
|
||||
*/
|
||||
virtual int retrieveGroupIds(std::vector<RsGxsGroupId>& grpIds) = 0;
|
||||
|
||||
/*!
|
||||
* Retrives all msg ids in store
|
||||
* @param grpId groupId of message ids to retrieve
|
||||
* @param msgId msgsids retrieved
|
||||
* @return error code
|
||||
*/
|
||||
virtual int retrieveMsgIds(const RsGxsGroupId& grpId, RsGxsMessageId::std_vector& msgId) = 0;
|
||||
|
||||
/*!
|
||||
* @return the cache size set for this RsGeneralDataService in bytes
|
||||
*/
|
||||
|
@ -13,14 +13,7 @@
|
||||
|
||||
using namespace rs_nxs_test;
|
||||
|
||||
template<typename T>
|
||||
void copy_all_but(T& ex, const std::list<T>& s, std::list<T>& d)
|
||||
{
|
||||
typename std::list<T>::const_iterator cit = s.begin();
|
||||
for(; cit != s.end(); cit++)
|
||||
if(*cit != ex)
|
||||
d.push_back(*cit);
|
||||
}
|
||||
|
||||
|
||||
NxsGrpSync::NxsGrpSync()
|
||||
{
|
||||
@ -48,13 +41,15 @@ NxsGrpSync::NxsGrpSync()
|
||||
RsNxsNetMgr* mgr = new rs_nxs_test::RsNxsNetDummyMgr(*it, otherPeers);
|
||||
mNxsNetMgrs.insert(std::make_pair(*it, mgr));
|
||||
|
||||
RsNxsSimpleDummyReputation::RepMap reMap;
|
||||
std::list<RsNxsSimpleDummyCircles::Membership> membership;
|
||||
// now reputation service
|
||||
mRep = new RsNxsSimpleDummyReputation(reMap, true);
|
||||
mCircles = new RsNxsSimpleDummyCircles(membership, true);
|
||||
}
|
||||
|
||||
RsNxsSimpleDummyReputation::RepMap reMap;
|
||||
std::list<RsNxsSimpleDummyCircles::Membership> membership;
|
||||
// now reputation service
|
||||
mRep = new RsNxsSimpleDummyReputation(reMap, true);
|
||||
mCircles = new RsNxsSimpleDummyCircles(membership, true);
|
||||
|
||||
|
||||
// lets create some a group each for all peers
|
||||
DataMap::iterator mit = mDataServices.begin();
|
||||
for(; mit != mDataServices.end(); mit++)
|
||||
|
@ -20,8 +20,8 @@ public:
|
||||
NxsGrpTestScenario();
|
||||
virtual ~NxsGrpTestScenario();
|
||||
|
||||
bool checkTestPassed();
|
||||
bool checkDeepTestPassed();
|
||||
virtual bool checkTestPassed();
|
||||
virtual bool checkDeepTestPassed();
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -7,4 +7,143 @@
|
||||
|
||||
|
||||
|
||||
#include "nxsmsgsync_test.h"
|
||||
#include "retroshare/rstypes.h"
|
||||
#include "gxs/rsdataservice.h"
|
||||
#include "nxsdummyservices.h"
|
||||
#include "../common/data_support.h"
|
||||
#include <auto_ptr.h>
|
||||
|
||||
using namespace rs_nxs_test;
|
||||
|
||||
rs_nxs_test::NxsMsgSync::NxsMsgSync()
|
||||
{
|
||||
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(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;
|
||||
std::list<RsNxsSimpleDummyCircles::Membership> membership;
|
||||
// now reputation service
|
||||
mRep = new RsNxsSimpleDummyReputation(reMap, true);
|
||||
mCircles = new RsNxsSimpleDummyCircles(membership, true);
|
||||
|
||||
// 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);
|
||||
RsGxsGrpMetaData* meta = new RsGxsGrpMetaData();
|
||||
init_item(meta);
|
||||
meta->mReputationCutOff = 0;
|
||||
meta->mGroupId = grp->grpId;
|
||||
grp->metaData = meta;
|
||||
meta->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED;
|
||||
|
||||
RsGxsGroupId grpId = grp->grpId;
|
||||
|
||||
// the expected result is that each peer has the group of the others
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
const NxsMsgTestScenario::ExpectedMap& rs_nxs_test::NxsMsgSync::getExpectedMap() {
|
||||
return mExpectedResult;
|
||||
}
|
||||
|
@ -8,28 +8,31 @@
|
||||
#ifndef NXSMSGSYNC_TEST_H_
|
||||
#define NXSMSGSYNC_TEST_H_
|
||||
|
||||
#include "nxstestscenario.h"
|
||||
#include "nxsmsgtestscenario.h"
|
||||
|
||||
namespace rs_nxs_test {
|
||||
|
||||
class NxsMessageTest : public rs_nxs_test::NxsTestScenario
|
||||
class NxsMsgSync : public NxsMsgTestScenario
|
||||
{
|
||||
public:
|
||||
|
||||
NxsMessageTest();
|
||||
NxsMsgSync();
|
||||
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();
|
||||
RsServiceInfo getServiceInfo();
|
||||
|
||||
protected:
|
||||
|
||||
const ExpectedMap& getExpectedMap();
|
||||
|
||||
private:
|
||||
|
||||
std::list<RsPeerId> mPeerIds;
|
||||
typedef std::map<RsPeerId, RsGeneralDataService*> DataMap;
|
||||
typedef std::map<RsPeerId, std::list<RsNxsGrp*> > ExpectedMap;
|
||||
|
||||
DataMap mDataServices;
|
||||
std::map<RsPeerId, RsNxsNetMgr*> mNxsNetMgrs;
|
||||
@ -37,13 +40,13 @@
|
||||
RsGcxs* mCircles;
|
||||
RsServiceInfo mServInfo;
|
||||
|
||||
ExpectedMap mExpectedResult;
|
||||
NxsMsgTestScenario::ExpectedMap mExpectedResult;
|
||||
|
||||
uint16_t mServType;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* NXSMSGSYNC_TEST_H_ */
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* nxsmsgtestscenario.cpp
|
||||
*
|
||||
* Created on: 26 Apr 2014
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#include "nxsmsgtestscenario.h"
|
||||
|
||||
namespace rs_nxs_test {
|
||||
|
||||
NxsMsgTestScenario::NxsMsgTestScenario() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
NxsMsgTestScenario::~NxsMsgTestScenario() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
||||
bool NxsMsgTestScenario::checkTestPassed() {
|
||||
|
||||
// so we expect all peers to all messages for each group
|
||||
const ExpectedMap& exMap = getExpectedMap();
|
||||
|
||||
ExpectedMap::const_iterator mit = exMap.begin();
|
||||
|
||||
bool passed = true;
|
||||
|
||||
|
||||
for(; mit != exMap.end(); mit++)
|
||||
{
|
||||
const RsPeerId& pid = mit->first;
|
||||
|
||||
const ExpectedMsgs& exMsgs = mit->second;
|
||||
ExpectedMsgs::const_iterator cit = exMsgs.begin();
|
||||
RsGeneralDataService* ds = getDataService(pid);
|
||||
|
||||
for(; cit != exMsgs.end(); cit++)
|
||||
{
|
||||
const RsGxsGroupId& grpId = cit->first;
|
||||
RsGxsMessageId::std_vector expMsgIds = cit->second;
|
||||
RsGxsMessageId::std_vector msgIds;
|
||||
|
||||
ds->retrieveMsgIds(grpId, msgIds);
|
||||
|
||||
RsGxsMessageId::std_vector result(expMsgIds.size()+msgIds.size());
|
||||
|
||||
std::sort(msgIds.begin(), msgIds.end());
|
||||
std::sort(expMsgIds.begin(), expMsgIds.end());
|
||||
|
||||
RsGxsMessageId::std_vector::iterator it = std::set_difference(msgIds.begin(), msgIds.end(),
|
||||
expMsgIds.begin(), expMsgIds.end(), result.begin());
|
||||
|
||||
result.resize(it - result.begin());
|
||||
|
||||
passed &= result.size() == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return passed;
|
||||
|
||||
}
|
||||
|
||||
bool NxsMsgTestScenario::checkDeepTestPassed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* namespace rs_nxs_test */
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* nxsmsgtestscenario.h
|
||||
*
|
||||
* Created on: 26 Apr 2014
|
||||
* Author: crispy
|
||||
*/
|
||||
|
||||
#ifndef NXSMSGTESTSCENARIO_H_
|
||||
#define NXSMSGTESTSCENARIO_H_
|
||||
|
||||
#include "nxstestscenario.h"
|
||||
|
||||
namespace rs_nxs_test {
|
||||
|
||||
class NxsMsgTestScenario : public NxsTestScenario {
|
||||
public:
|
||||
NxsMsgTestScenario();
|
||||
virtual ~NxsMsgTestScenario();
|
||||
|
||||
typedef std::map<RsGxsGroupId, RsGxsMessageId::std_vector> ExpectedMsgs;
|
||||
typedef std::map<RsPeerId, ExpectedMsgs> ExpectedMap;
|
||||
|
||||
bool checkTestPassed();
|
||||
bool checkDeepTestPassed();
|
||||
|
||||
protected:
|
||||
|
||||
RsDataService* createDataStore(const RsPeerId& peerId);
|
||||
virtual const ExpectedMap& getExpectedMap() = 0;
|
||||
};
|
||||
|
||||
} /* namespace rs_nxs_test */
|
||||
#endif /* NXSMSGTESTSCENARIO_H_ */
|
@ -8,6 +8,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "nxsgrpsync_test.h"
|
||||
#include "nxsmsgsync_test.h"
|
||||
#include "nxstesthub.h"
|
||||
|
||||
TEST(libretroshare_gxs, gxs_grp_sync)
|
||||
@ -18,7 +19,22 @@ TEST(libretroshare_gxs, gxs_grp_sync)
|
||||
tHub.StartTest();
|
||||
|
||||
// wait for ten seconds
|
||||
rs_nxs_test::NxsTestHub::Wait(15);
|
||||
rs_nxs_test::NxsTestHub::Wait(10);
|
||||
|
||||
tHub.EndTest();
|
||||
|
||||
ASSERT_TRUE(tHub.testsPassed());
|
||||
}
|
||||
|
||||
TEST(libretroshare_gxs, gxs_msg_sync)
|
||||
{
|
||||
rs_nxs_test::NxsTestScenario::pointer gsync_test = rs_nxs_test::NxsTestScenario::pointer(
|
||||
new rs_nxs_test::NxsMsgSync);
|
||||
rs_nxs_test::NxsTestHub tHub(gsync_test);
|
||||
tHub.StartTest();
|
||||
|
||||
// wait for ten seconds
|
||||
rs_nxs_test::NxsTestHub::Wait(10);
|
||||
|
||||
tHub.EndTest();
|
||||
|
||||
|
@ -3,7 +3,7 @@ CONFIG += bitdht
|
||||
|
||||
CONFIG += gxs debug
|
||||
|
||||
LIBS += -lgtest
|
||||
LIBS += -lgtest.a
|
||||
|
||||
gxs {
|
||||
DEFINES += RS_ENABLE_GXS
|
||||
@ -27,7 +27,7 @@ linux-* {
|
||||
LIBS += -lssl -lupnp -lixml -lXss -lgnome-keyring
|
||||
LIBS *= -lcrypto -ldl -lX11 -lz
|
||||
|
||||
gxs {
|
||||
gxs {
|
||||
LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a
|
||||
|
||||
# We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database.
|
||||
@ -261,12 +261,16 @@ HEADERS += libretroshare/gxs/common/data_support.h \
|
||||
SOURCES += libretroshare/gxs/common/data_support.cc \
|
||||
|
||||
HEADERS += libretroshare/gxs/nxs_test/nxsdummyservices.h \
|
||||
libretroshare/gxs/nxs_test/nxsgrptestscenario.h \
|
||||
libretroshare/gxs/nxs_test/nxsmsgtestscenario.h \
|
||||
libretroshare/gxs/nxs_test/nxsgrpsync_test.h \
|
||||
libretroshare/gxs/nxs_test/nxsmsgsync_test.h \
|
||||
libretroshare/gxs/nxs_test/nxstesthub.h \
|
||||
libretroshare/gxs/nxs_test/nxstestscenario.h
|
||||
|
||||
SOURCES += libretroshare/gxs/nxs_test/nxsdummyservices.cc \
|
||||
libretroshare/gxs/nxs_test/nxsgrptestscenario.cc \
|
||||
libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc \
|
||||
libretroshare/gxs/nxs_test/nxsgrpsync_test.cc \
|
||||
libretroshare/gxs/nxs_test/nxsmsgsync_test.cc \
|
||||
libretroshare/gxs/nxs_test/nxstesthub.cc \
|
||||
|
Loading…
Reference in New Issue
Block a user