From 5399618cefbe83fc414a8c8a06c9067b58c2e1a1 Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Sun, 20 Jul 2014 11:21:06 +0000 Subject: [PATCH] completed addition of get statistic feature of gxs git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7461 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/gxs/rsgenexchange.cc | 8 +- libretroshare/src/gxs/rsgxsdataaccess.cc | 14 ++- libretroshare/src/retroshare/rstokenservice.h | 2 + .../gxs/gen_exchange/genexchangetester.cc | 4 +- .../gxs/gen_exchange/gxsteststats.cpp | 102 +++++++++++++++++- .../gxs/gen_exchange/rsgenexchange_test.cc | 16 +++ tests/unittests/unittests.pro | 2 + 7 files changed, 138 insertions(+), 10 deletions(-) diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 40621cc1f..844dac7fd 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -976,14 +976,14 @@ bool RsGenExchange::subscribeToGroup(uint32_t& token, const RsGxsGroupId& grpId, return true; } -bool RsGenExchange::getGroupStatistic(const uint32_t& /*token*/, GxsGroupStatistic& /*stats*/) +bool RsGenExchange::getGroupStatistic(const uint32_t& token, GxsGroupStatistic& stats) { - return false; + return mDataAccess->getGroupStatistic(token, stats); } -bool RsGenExchange::getServiceStatistic(const uint32_t& /*token*/, GxsServiceStatistic& /*stats*/) +bool RsGenExchange::getServiceStatistic(const uint32_t& token, GxsServiceStatistic& stats) { - return false; + return mDataAccess->getServiceStatistic(token, stats); } bool RsGenExchange::updated(bool willCallGrpChanged, bool willCallMsgChanged) diff --git a/libretroshare/src/gxs/rsgxsdataaccess.cc b/libretroshare/src/gxs/rsgxsdataaccess.cc index e9ece5f40..2be2aeab4 100644 --- a/libretroshare/src/gxs/rsgxsdataaccess.cc +++ b/libretroshare/src/gxs/rsgxsdataaccess.cc @@ -26,6 +26,7 @@ #include #include "rsgxsdataaccess.h" +#include "retroshare/rsgxsflags.h" // This bit will be filled out over time. #define RS_TOKREQOPT_MSG_VERSIONS 0x0001 // MSGRELATED: Returns All MsgIds with OrigMsgId = MsgId. @@ -293,7 +294,9 @@ void RsGxsDataAccess::requestServiceStatistic(uint32_t& token) generateToken(token); - setReq(req, token, 0, RsTokReqOptions()); + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_SERVICE_STATS; + setReq(req, token, 0, opts); storeRequest(req); } @@ -304,7 +307,9 @@ void RsGxsDataAccess::requestGroupStatistic(uint32_t& token, const RsGxsGroupId& generateToken(token); - setReq(req, token, 0, RsTokReqOptions()); + RsTokReqOptions opts; + opts.mReqType = GXS_REQUEST_TYPE_GROUP_STATS; + setReq(req, token, 0, opts); storeRequest(req); } @@ -860,7 +865,7 @@ bool RsGxsDataAccess::getServiceStatistic(const uint32_t &token, GxsServiceStati if(req == NULL){ - std::cerr << "RsGxsDataAccess::getServiceStatistic() Unable to retrieve grp stats" << std::endl; + std::cerr << "RsGxsDataAccess::getServiceStatistic() Unable to retrieve service stats" << std::endl; return false; }else if(req->status == GXS_REQUEST_V2_STATUS_COMPLETE){ @@ -1479,6 +1484,7 @@ bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req) req->mServiceStatistic.mNumGrps = grpMeta.size(); req->mServiceStatistic.mSizeOfGrps = 0; req->mServiceStatistic.mSizeOfMsgs = 0; + req->mServiceStatistic.mNumGrpsSubscribed = 0; for(; mit != grpMeta.end(); mit++) { @@ -1489,6 +1495,8 @@ bool RsGxsDataAccess::getServiceStatistic(ServiceStatisticRequest *req) getGroupStatistic(&gr); req->mServiceStatistic.mNumMsgs += gr.mGroupStatistic.mNumMsgs; req->mServiceStatistic.mSizeOfMsgs += gr.mGroupStatistic.mTotalSizeOfMsgs; + req->mServiceStatistic.mNumGrpsSubscribed += m->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED ? 1 : 0; + delete m; } diff --git a/libretroshare/src/retroshare/rstokenservice.h b/libretroshare/src/retroshare/rstokenservice.h index 1f22d6ffc..97f406222 100644 --- a/libretroshare/src/retroshare/rstokenservice.h +++ b/libretroshare/src/retroshare/rstokenservice.h @@ -44,6 +44,8 @@ #define GXS_REQUEST_TYPE_MSG_RELATED_META 0x00800000 #define GXS_REQUEST_TYPE_MSG_RELATED_IDS 0x01000000 +#define GXS_REQUEST_TYPE_GROUP_STATS 0x01600000 +#define GXS_REQUEST_TYPE_SERVICE_STATS 0x03200000 // This bit will be filled out over time. diff --git a/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetester.cc b/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetester.cc index 2123e27ea..f0bad0e38 100644 --- a/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetester.cc +++ b/tests/unittests/libretroshare/gxs/gen_exchange/genexchangetester.cc @@ -19,12 +19,12 @@ GenExchangeTest::~GenExchangeTest() bool GenExchangeTest::getServiceStatistic(const uint32_t &token, GxsServiceStatistic &servStatistic) { - mTestService->getServiceStatisticTS(token, servStatistic); + return mTestService->getServiceStatisticTS(token, servStatistic); } bool GenExchangeTest::getGroupStatistic(const uint32_t &token, GxsGroupStatistic &grpStatistic) { - mTestService->getGroupStatisticTS(token, grpStatistic); + return mTestService->getGroupStatisticTS(token, grpStatistic); } diff --git a/tests/unittests/libretroshare/gxs/gen_exchange/gxsteststats.cpp b/tests/unittests/libretroshare/gxs/gen_exchange/gxsteststats.cpp index c7b810a9d..8cfad6538 100644 --- a/tests/unittests/libretroshare/gxs/gen_exchange/gxsteststats.cpp +++ b/tests/unittests/libretroshare/gxs/gen_exchange/gxsteststats.cpp @@ -1,4 +1,5 @@ #include "gxsteststats.h" +#include "libretroshare/serialiser/support.h" #define POLLING_TIME_OUT 5 @@ -12,14 +13,113 @@ GxsTestStats::~GxsTestStats() void GxsTestStats::runTests() { - testGroupStatistics(); + //testGroupStatistics(); + testServiceStatistics(); } void GxsTestStats::testGroupStatistics() { + setUp(); + + GenExchangeTestService* testService = getTestService(); + RsTokenService* tokenService = getTokenService(); + + // create some random grps to allow msg testing + + RsDummyGrp* dgrp1 = new RsDummyGrp(); + + init(*dgrp1); + RsTokReqOptions opts; + opts.mReqType = 45000; + uint32_t token; + RsGxsGroupId grpId; + + testService->publishDummyGrp(token, dgrp1); + pollForGrpAcknowledgement(token, grpId); + + RsDummyMsg* msg1 = new RsDummyMsg(); + init(*msg1); + + RsDummyMsg* msg2 = new RsDummyMsg(); + init(*msg2); + + msg1->meta.mGroupId = grpId; + getTestService()->publishDummyMsg(token, msg1); + + RsGxsGrpMsgIdPair msgId; + pollForMsgAcknowledgement(token, msgId); + + msg2->meta.mGroupId = grpId; + getTestService()->publishDummyMsg(token, msg2); + + pollForMsgAcknowledgement(token, msgId); + + tokenService->requestGroupStatistic(token, grpId); + + opts.mReqType = GXS_REQUEST_TYPE_GROUP_STATS; + pollForToken(token, opts); + + GxsGroupStatistic stats; + ASSERT_TRUE(getGroupStatistic(token, stats)); + + ASSERT_TRUE(stats.mNumMsgs == 2); + breakDown(); + } void GxsTestStats::testServiceStatistics() { + setUp(); + + GenExchangeTestService* testService = getTestService(); + RsTokenService* tokenService = getTokenService(); + + // create some random grps to allow msg testing + + RsDummyGrp* dgrp1 = new RsDummyGrp(); + RsDummyGrp* dgrp2 = new RsDummyGrp(); + + init(*dgrp1); + RsTokReqOptions opts; + opts.mReqType = 45000; + uint32_t token; + RsGxsGroupId grpId; + + testService->publishDummyGrp(token, dgrp1); + pollForGrpAcknowledgement(token, grpId); + + testService->publishDummyGrp(token, dgrp2); + pollForGrpAcknowledgement(token, grpId); + + RsDummyMsg* msg1 = new RsDummyMsg(); + init(*msg1); + + RsDummyMsg* msg2 = new RsDummyMsg(); + init(*msg2); + + msg1->meta.mGroupId = grpId; + getTestService()->publishDummyMsg(token, msg1); + + RsGxsGrpMsgIdPair msgId; + pollForMsgAcknowledgement(token, msgId); + + msg2->meta.mGroupId = grpId; + getTestService()->publishDummyMsg(token, msg2); + + pollForMsgAcknowledgement(token, msgId); + + tokenService->requestServiceStatistic(token); + + opts.mReqType = GXS_REQUEST_TYPE_SERVICE_STATS; + pollForToken(token, opts); + + GxsServiceStatistic stats; + ASSERT_TRUE(getServiceStatistic(token, stats)); + + ASSERT_TRUE(stats.mNumMsgs == 2); + ASSERT_TRUE(stats.mNumGrps == 2); + ASSERT_TRUE(stats.mNumGrpsSubscribed == 2); + + breakDown(); } diff --git a/tests/unittests/libretroshare/gxs/gen_exchange/rsgenexchange_test.cc b/tests/unittests/libretroshare/gxs/gen_exchange/rsgenexchange_test.cc index 8e28c17d1..9e0a37f26 100644 --- a/tests/unittests/libretroshare/gxs/gen_exchange/rsgenexchange_test.cc +++ b/tests/unittests/libretroshare/gxs/gen_exchange/rsgenexchange_test.cc @@ -6,6 +6,7 @@ #include "gxspublishmsgtest.h" #include "gxs/rsdataservice.h" #include "rsdummyservices.h" +#include "gxsteststats.h" /*! @@ -39,3 +40,18 @@ TEST(libretroshare_gxs, RsGenExchange) //GxsPublishMsgTest testMsgPublishing(&testService, dataStore); //testMsgPublishing.runTests(); } + +TEST(libretroshare_gxs, GetStats) +{ + + RsGeneralDataService* dataStore = new RsDataService("./", "testServiceDb", RS_SERVICE_TYPE_DUMMY, NULL, ""); + + // we want to use default authentication which is NO authentication :) + GenExchangeTestService testService(dataStore, NULL, NULL); + + GxsTestStats testStats(&testService, dataStore); + testStats.runTests(); + + //GxsPublishMsgTest testMsgPublishing(&testService, dataStore); + //testMsgPublishing.runTests(); +} diff --git a/tests/unittests/unittests.pro b/tests/unittests/unittests.pro index b37ce8dbe..0114d4a04 100644 --- a/tests/unittests/unittests.pro +++ b/tests/unittests/unittests.pro @@ -286,10 +286,12 @@ HEADERS += libretroshare/gxs/gen_exchange/genexchangetester.h \ libretroshare/gxs/gen_exchange/genexchangetestservice.h \ libretroshare/gxs/gen_exchange/gxspublishgrouptest.h \ libretroshare/gxs/gen_exchange/rsdummyservices.h \ + libretroshare/gxs/gen_exchange/gxsteststats.cpp # libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.h \ SOURCES += libretroshare/gxs/gen_exchange/gxspublishgrouptest.cc \ + libretroshare/gxs/gen_exchange/gxsteststats.cpp \ libretroshare/gxs/gen_exchange/gxspublishmsgtest.cc \ libretroshare/gxs/gen_exchange/rsdummyservices.cc \ libretroshare/gxs/gen_exchange/rsgenexchange_test.cc \