CoolFace
Datasetpublic

GSaha567/seq_level_training_data

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes52downloads
shard_000054.csv89305 linesDownload Raw Back to root
1text,length,is_long_context,metric_val,label_metric2"/*3 * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.4 */5 6#include <pthread.h>7 8#include <boost/bind.hpp>9#include <boost/lexical_cast.hpp>10#include <boost/assign/ptr_list_of.hpp>11#include <boost/uuid/uuid.hpp>12 13#include <testing/gunit.h>14#include <base/logging.h>15#include <sandesh/sandesh_types.h>16#include <sandesh/sandesh.h>17#include <sandesh/sandesh_message_builder.h>18#include <sandesh/common/flow_types.h>19 20#include <analytics/viz_types.h>21#include <analytics/viz_constants.h>22#include <analytics/db_handler.h>23#include <analytics/db_handler_impl.h>24#include <analytics/vizd_table_desc.h>25 26#include <analytics/test/cql_if_mock.h>27 28using ::testing::Return;29using ::testing::Field;30using ::testing::AnyOf;31using ::testing::AnyNumber;32using ::testing::_;33using ::testing::Eq;34using ::testing::ElementsAre;35using ::testing::Pointee;36using ::testing::ElementsAreArray;37using namespace pugi;38using namespace GenDb;39 40TtlMap ttl_map = g_viz_constants.TtlValuesDefault;41 42struct DbHandlerCacheParam {43        uint32_t field_cache_t2_;44        std::set<std::string> field_cache_set_[2];45        uint32_t field_cache_old_t2_;46        uint8_t old_t2_index_;47        uint8_t new_t2_index_;48};49 50class DbHandlerTest : public ::testing::Test {51public:52    DbHandlerTest() :53        builder_(SandeshXMLMessageTestBuilder::GetInstance()),54        dbif_mock_(new CqlIfMock()),55        db_handler_(new DbHandler(dbif_mock_, ttl_map)) {56    }57 58    ~DbHandlerTest() {59    }60 61    virtual void SetUp() {62    }63 64    virtual void TearDown() {65    }66 67    CqlIfMock* dbif_mock() {68        return dbif_mock_;69    }70 71    DbHandlerPtr db_handler() {72        return db_handler_;73    }74 75    struct DbHandlerCacheParam GetDbHandlerCacheParam() {76        db_handler_cache_param_.field_cache_t2_ = DbHandler::field_cache_t2_;77        db_handler_cache_param_.field_cache_set_[0] = DbHandler::field_cache_set_[0];78        db_handler_cache_param_.field_cache_set_[1] = DbHandler::field_cache_set_[1];79        db_handler_cache_param_.field_cache_old_t2_ = DbHandler::field_cache_old_t2_;80        db_handler_cache_param_.old_t2_index_ = DbHandler::old_t2_index_;81        db_handler_cache_param_.new_t2_index_ = DbHandler::new_t2_index_;82        return db_handler_cache_param_;83    }84 85    bool WriteToCache(uint32_t temp_t2, std::string fc_entry) {86        return db_handler()->CanRecordDataForT2(temp_t2, fc_entry);87    }88 89protected:90    class SandeshXMLMessageTest : public SandeshXMLMessage {91    public:92        SandeshXMLMessageTest() {}93        virtual ~SandeshXMLMessageTest() {}94 95        virtual bool Parse(const uint8_t *xml_msg, size_t size) {96            xml_parse_result result = xdoc_.load_buffer(xml_msg, size,97                parse_default & ~parse_escapes);98            if (!result) {99                LOG(ERROR, __func__ << "": Unable to load Sandesh XML Test."" <<100                    ""(status="" << result.status << "", offset="" <<101                    result.offset << ""): "" << xml_msg);102                return false;103            }104            message_node_ = xdoc_.first_child();105            message_type_ = message_node_.name();106            size_ = size;107            return true;108        }109 110        void SetHeader(const SandeshHeader &header) { header_ = header; }111    };112 113    class SandeshXMLMessageTestBuilder : public SandeshMessageBuilder {114    public:115        SandeshXMLMessageTestBuilder() {}116 117        virtual SandeshMessage *Create(const uint8_t *xml_msg,118            size_t size) const {119            SandeshXMLMessageTest *msg = new SandeshXMLMessageTest;120            msg->Parse(xml_msg, size);121            return msg;122        }123 124        static SandeshXMLMessageTestBuilder *GetInstance() {125            return &instance_;126        }127 128    private:129        static SandeshXMLMessageTestBuilder instance_;130    };131 132    SandeshMessageBuilder *builder_;133    boost::uuids::random_generator rgen_;134 135    void DbAddColumnCbFn(bool success) {136        assert(success);137    }138 139    void MessageTableOnlyInsert(const VizMsg *vmsgp) {140        db_handler()->MessageTableOnlyInsert(vmsgp,141            boost::bind(&DbHandlerTest::DbAddColumnCbFn, this, _1));142    }143 144    void MessageTableInsert(const VizMsg *vmsgp) {145        db_handler()->MessageTableInsert(vmsgp,146            boost::bind(&DbHandlerTest::DbAddColumnCbFn, this, _1));147    }148 149    void MessageIndexTableInsert(const std::string& cfname,150        const SandeshHeader& header, const std::string& message_type,151        const boost::uuids::uuid& unm, const std::string keyword) {152        db_handler()->MessageIndexTableInsert(cfname, header, message_type,153            unm, keyword,154            boost::bind(&DbHandlerTest::DbAddColumnCbFn, this, _1));155    }156 157    void ObjectTableInsert(const std::string &table,158        const std::string &rowkey_str, uint64_t timestamp,159        const boost::uuids::uuid& unm, const VizMsg *vmsgp) {160        db_handler()->ObjectTableInsert(table, rowkey_str, timestamp,161            unm, vmsgp,162            boost::bind(&DbHandlerTest::DbAddColumnCbFn, this, _1));163    }164 165    void FlowTableInsert(const pugi::xml_node& parent,166        const SandeshHeader &header) {167        db_handler()->FlowTableInsert(parent, header,168            boost::bind(&DbHandlerTest::DbAddColumnCbFn, this, _1));169    }170 171private:172    EventManager evm_;173    CqlIfMock *dbif_mock_;174    DbHandlerPtr db_handler_;175    DbHandlerCacheParam db_handler_cache_param_;176};177 178 179DbHandlerTest::SandeshXMLMessageTestBuilder180    DbHandlerTest::SandeshXMLMessageTestBuilder::instance_;181 182TEST_F(DbHandlerTest, MessageTableOnlyInsertTest) {183    SandeshHeader hdr;184 185    hdr.set_Source(""127.0.0.1"");186    hdr.set_Module(""VizdTest"");187    hdr.set_InstanceId(""Test"");188    hdr.set_NodeType(""Test"");189    hdr.set_Timestamp(UTCTimestampUsec());190    std::string messagetype(""SandeshAsyncTest2"");191    std::string xmlmessage = ""<SandeshAsyncTest2 type=\\""sandesh\\""><file type=\\""string\\"" identifier=\\""-32768\\"">src/analytics/test/viz_collector_test.cc</file><line type=\\""i32\\"" identifier=\\""-32767\\"">80</line><f1 type=\\""struct\\"" identifier=\\""1\\""><SAT2_struct><f1 type=\\""string\\"" identifier=\\""1\\"">sat2string101</f1><f2 type=\\""i32\\"" identifier=\\""2\\"">101</f2></SAT2_struct></f1><f2 type=\\""i32\\"" identifier=\\""2\\"">101</f2></SandeshAsyncTest2>"";192 193    SandeshXMLMessageTest *msg = dynamic_cast<SandeshXMLMessageTest *>(194        builder_->Create(195            reinterpret_cast<const uint8_t *>(xmlmessage.c_str()),196            xmlmessage.size()));197    msg->SetHeader(hdr);198    boost::uuids::uuid unm(rgen_());199    VizMsg vmsgp(msg, unm);200 201    GenDb::DbDataValueVec rowkey;202    rowkey.push_back(unm);203 204    int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600;205    boost::ptr_vector<GenDb::NewCol> msg_table_expected_vector =206        boost::assign::ptr_list_of<GenDb::NewCol>207        (GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), ttl))208        (GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), ttl))209        (GenDb::NewCol(g_viz_constants.MODULE, hdr.get_Module(), ttl))210        (GenDb::NewCol(g_viz_constants.INSTANCE_ID, hdr.get_InstanceId(), ttl))211        (GenDb::NewCol(g_viz_constants.NODE_TYPE, hdr.get_NodeType(), ttl))212        (GenDb::NewCol(g_viz_constants.TIMESTAMP,213            static_cast<uint64_t>(hdr.get_Timestamp()), ttl))214        (GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), ttl))215        (GenDb::NewCol(g_viz_constants.LEVEL,216            static_cast<uint32_t>(0), ttl))217        (GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, ttl))218        (GenDb::NewCol(g_viz_constants.SEQUENCE_NUM,219            static_cast<uint32_t>(0), ttl))220        (GenDb::NewCol(g_viz_constants.VERSION,221            static_cast<uint32_t>(0), ttl))222        (GenDb::NewCol(g_viz_constants.SANDESH_TYPE,223            static_cast<uint8_t>(0), ttl))224        (GenDb::NewCol(g_viz_constants.DATA, xmlmessage, ttl));225 226    EXPECT_CALL(*dbif_mock(),227            Db_AddColumnProxy(228                Pointee(229                    AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.COLLECTOR_GLOBAL_TABLE),230                        Field(&GenDb::ColList::rowkey_, rowkey),231                        Field(&GenDb::ColList::columns_, msg_table_expected_vector)))))232        .Times(1)233        .WillOnce(Return(true));234 235    MessageTableOnlyInsert(&vmsgp);236    vmsgp.msg = NULL;237    delete msg;238}239 240TEST_F(DbHandlerTest, MessageTableOnlyInsertConfigAuditTest) {241    SandeshHeader hdr;242 243    hdr.set_Source(""127.0.0.1"");244    hdr.set_Module(""VizdTest"");245    hdr.set_InstanceId(""Test"");246    hdr.set_NodeType(""Test"");247    hdr.set_Timestamp(UTCTimestampUsec());248    std::string messagetype(""VncApiConfigLog"");249    std::string xmlmessage = ""<VncApiConfigLog type=\\""sandesh\\""><file type=\\""string\\"" identifier=\\""-32768\\"">src/analytics/test/viz_collector_test.cc</file><line type=\\""i32\\"" identifier=\\""-32767\\"">80</line><f1 type=\\""struct\\"" identifier=\\""1\\""><SAT2_struct><f1 type=\\""string\\"" identifier=\\""1\\"">sat2string101</f1><f2 type=\\""i32\\"" identifier=\\""2\\"">101</f2></SAT2_struct></f1><f2 type=\\""i32\\"" identifier=\\""2\\"">101</f2></VncApiConfigLog>"";250 251    SandeshXMLMessageTest *msg = dynamic_cast<SandeshXMLMessageTest *>(252        builder_->Create(253            reinterpret_cast<const uint8_t *>(xmlmessage.c_str()),254            xmlmessage.size()));255    msg->SetHeader(hdr);256    boost::uuids::uuid unm(rgen_());257    VizMsg vmsgp(msg, unm);258 259    GenDb::DbDataValueVec rowkey;260    rowkey.push_back(unm);261 262    int ttl = ttl_map.find(TtlType::CONFIGAUDIT_TTL)->second*3600;263    boost::ptr_vector<GenDb::NewCol> msg_table_expected_vector =264        boost::assign::ptr_list_of<GenDb::NewCol>265        (GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), ttl))266        (GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), ttl))267        (GenDb::NewCol(g_viz_constants.MODULE, hdr.get_Module(), ttl))268        (GenDb::NewCol(g_viz_constants.INSTANCE_ID, hdr.get_InstanceId(), ttl))269        (GenDb::NewCol(g_viz_constants.NODE_TYPE, hdr.get_NodeType(), ttl))270        (GenDb::NewCol(g_viz_constants.TIMESTAMP,271            static_cast<uint64_t>(hdr.get_Timestamp()), ttl))272        (GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), ttl))273        (GenDb::NewCol(g_viz_constants.LEVEL,274            static_cast<uint32_t>(0), ttl))275        (GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, ttl))276        (GenDb::NewCol(g_viz_constants.SEQUENCE_NUM,277            static_cast<uint32_t>(0), ttl))278        (GenDb::NewCol(g_viz_constants.VERSION,279            static_cast<uint32_t>(0), ttl))280        (GenDb::NewCol(g_viz_constants.SANDESH_TYPE,281            static_cast<uint8_t>(0), ttl))282        (GenDb::NewCol(g_viz_constants.DATA, xmlmessage, ttl));283 284    EXPECT_CALL(*dbif_mock(),285            Db_AddColumnProxy(286                Pointee(287                    AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.COLLECTOR_GLOBAL_TABLE),288                        Field(&GenDb::ColList::rowkey_, rowkey),289                        Field(&GenDb::ColList::columns_, msg_table_expected_vector)))))290        .Times(1)291        .WillOnce(Return(true));292 293    MessageTableOnlyInsert(&vmsgp);294    vmsgp.msg = NULL;295    delete msg;296}297 298TEST_F(DbHandlerTest, MessageIndexTableInsertTest) {299    SandeshHeader hdr;300 301    hdr.set_Source(""127.0.0.1"");302    hdr.set_Timestamp(UTCTimestampUsec());303    boost::uuids::uuid unm(rgen_());304 305    int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600;306 307    DbDataValueVec *colname(new DbDataValueVec());308    colname->reserve(3);309    colname->push_back(hdr.get_Source());310    colname->push_back((uint32_t)(hdr.get_Timestamp() & g_viz_constants.RowTimeInMask));311    colname->push_back(unm);312 313    DbDataValueVec *colvalue(new DbDataValueVec());314    boost::ptr_vector<GenDb::NewCol> idx_expected_vector =315        boost::assign::ptr_list_of<GenDb::NewCol>316        (GenDb::NewCol(colname, colvalue, ttl));317    GenDb::DbDataValueVec src_idx_rowkey;318    src_idx_rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits));319    uint8_t partition_no = 1;320    src_idx_rowkey.push_back(partition_no);321    EXPECT_CALL(*dbif_mock(),322            Db_AddColumnProxy(323                Pointee(324                    AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.MESSAGE_TABLE_SOURCE),325                        _,326                        Field(&GenDb::ColList::columns_,327                            idx_expected_vector)))))328        .Times(1)329        .WillOnce(Return(true));330 331    MessageIndexTableInsert(g_viz_constants.MESSAGE_TABLE_SOURCE,332            hdr, """", unm, """");333}334 335TEST_F(DbHandlerTest, MessageTableInsertTest) {336    SandeshHeader hdr;337 338    hdr.set_Source(""127.0.0.1"");339    hdr.set_Module(""VizdTest"");340    std::string messagetype(""SandeshAsyncTest2"");341    hdr.set_InstanceId(""Test"");342    hdr.set_NodeType(""Test"");343    hdr.set_Timestamp(UTCTimestampUsec());344    hdr.set_Type(SandeshType::SYSTEM);345    std::string xmlmessage = ""<SandeshAsyncTest2 type=\\""sandesh\\""><file type=\\""string\\"" identifier=\\""-32768\\"">src/analytics/test/viz_collector_test.cc</file><line type=\\""i32\\"" identifier=\\""-32767\\"">80</line><f1 type=\\""struct\\"" identifier=\\""1\\""><SAT2_struct><f1 type=\\""string\\"" identifier=\\""1\\"">sat2string101</f1><f2 type=\\""i32\\"" identifier=\\""2\\"">101</f2></SAT2_struct></f1><f2 type=\\""i32\\"" identifier=\\""2\\"">101</f2></SandeshAsyncTest2>"";346 347    SandeshXMLMessageTest *msg = dynamic_cast<SandeshXMLMessageTest *>(348        builder_->Create(349            reinterpret_cast<const uint8_t *>(xmlmessage.c_str()),350            xmlmessage.size()));351    msg->SetHeader(hdr);352    boost::uuids::uuid unm(rgen_());353    VizMsg vmsgp(msg, unm);354 355    GenDb::DbDataValueVec rowkey;356    rowkey.push_back(unm);357 358    int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600;359    boost::ptr_vector<GenDb::NewCol> msg_table_expected_vector =360        boost::assign::ptr_list_of<GenDb::NewCol>361        (GenDb::NewCol(g_viz_constants.SOURCE, hdr.get_Source(), ttl))362        (GenDb::NewCol(g_viz_constants.NAMESPACE, std::string(), ttl))363        (GenDb::NewCol(g_viz_constants.MODULE, hdr.get_Module(), ttl))364        (GenDb::NewCol(g_viz_constants.INSTANCE_ID, hdr.get_InstanceId(), ttl))365        (GenDb::NewCol(g_viz_constants.NODE_TYPE, hdr.get_NodeType(), ttl))366        (GenDb::NewCol(g_viz_constants.TIMESTAMP,367            static_cast<uint64_t>(hdr.get_Timestamp()), ttl))368        (GenDb::NewCol(g_viz_constants.CATEGORY, std::string(), ttl))369        (GenDb::NewCol(g_viz_constants.LEVEL,370            static_cast<uint32_t>(0), ttl))371        (GenDb::NewCol(g_viz_constants.MESSAGE_TYPE, messagetype, ttl))372        (GenDb::NewCol(g_viz_constants.SEQUENCE_NUM,373            static_cast<uint32_t>(0), ttl))374        (GenDb::NewCol(g_viz_constants.VERSION,375            static_cast<uint32_t>(0), ttl))376        (GenDb::NewCol(g_viz_constants.SANDESH_TYPE,377            static_cast<uint8_t>(SandeshType::SYSTEM), ttl))378        (GenDb::NewCol(g_viz_constants.DATA, xmlmessage, ttl));379 380    EXPECT_CALL(*dbif_mock(),381            Db_AddColumnProxy(382                Pointee(383                    AllOf(Field(&GenDb::ColList::cfname_,384                        g_viz_constants.COLLECTOR_GLOBAL_TABLE),385                        Field(&GenDb::ColList::rowkey_, rowkey),386                        Field(&GenDb::ColList::columns_,387                            msg_table_expected_vector)))))388        .Times(1)389        .WillOnce(Return(true));390 391    DbDataValueVec *colname(new DbDataValueVec());392    colname->reserve(3);393    colname->push_back(hdr.get_Source());394    colname->push_back((uint32_t)395        (hdr.get_Timestamp() & g_viz_constants.RowTimeInMask));396    colname->push_back(unm);397 398    DbDataValueVec *colvalue(new DbDataValueVec());399    boost::ptr_vector<GenDb::NewCol> idx_expected_vector =400        boost::assign::ptr_list_of<GenDb::NewCol>401        (GenDb::NewCol(colname, colvalue, ttl));402 403    EXPECT_CALL(*dbif_mock(),404            Db_AddColumnProxy(405                Pointee(406                    AllOf(Field(&GenDb::ColList::cfname_,407                              g_viz_constants.MESSAGE_TABLE_SOURCE),408                        _,409                        Field(&GenDb::ColList::columns_,410                            idx_expected_vector)))))411        .Times(1)412        .WillOnce(Return(true));413 414 415    DbDataValueVec *modcolname(new DbDataValueVec());416    modcolname->reserve(3);417    modcolname->push_back(hdr.get_Module());418    modcolname->push_back((uint32_t)419        (hdr.get_Timestamp() & g_viz_constants.RowTimeInMask));420    modcolname->push_back(unm);421    colvalue =new DbDataValueVec();422    boost::ptr_vector<GenDb::NewCol> mod_idx_expected_vector =423        boost::assign::ptr_list_of<GenDb::NewCol>424        (GenDb::NewCol(modcolname, colvalue, ttl));425 426    EXPECT_CALL(*dbif_mock(),427            Db_AddColumnProxy(428                Pointee(429                    AllOf(Field(&GenDb::ColList::cfname_,430                              g_viz_constants.MESSAGE_TABLE_MODULE_ID),431                        _,432                        Field(&GenDb::ColList::columns_,433                            mod_idx_expected_vector)))))434        .Times(1)435        .WillOnce(Return(true));436 437    DbDataValueVec *catcolname(new DbDataValueVec());438    catcolname->reserve(3);439    catcolname->push_back(hdr.get_Category());440    catcolname->push_back((uint32_t)441        (hdr.get_Timestamp() & g_viz_constants.RowTimeInMask));442    catcolname->push_back(unm);443    colvalue =new DbDataValueVec();444    boost::ptr_vector<GenDb::NewCol> cat_idx_expected_vector =445        boost::assign::ptr_list_of<GenDb::NewCol>446        (GenDb::NewCol(catcolname, colvalue, ttl));447 448    EXPECT_CALL(*dbif_mock(),449            Db_AddColumnProxy(450                Pointee(451                    AllOf(Field(&GenDb::ColList::cfname_,452                              g_viz_constants.MESSAGE_TABLE_CATEGORY),453                        _,454                        Field(&GenDb::ColList::columns_,455                            cat_idx_expected_vector)))))456        .Times(1)457        .WillOnce(Return(true));458 459    DbDataValueVec *msgtypecolname(new DbDataValueVec());460    msgtypecolname->reserve(3);461    msgtypecolname->push_back(messagetype);462    msgtypecolname->push_back((uint32_t)463        (hdr.get_Timestamp() & g_viz_constants.RowTimeInMask));464    msgtypecolname->push_back(unm);465    colvalue =new DbDataValueVec();466    boost::ptr_vector<GenDb::NewCol> msg_type_idx_expected_vector =467        boost::assign::ptr_list_of<GenDb::NewCol>468        (GenDb::NewCol(msgtypecolname, colvalue, ttl));469 470    EXPECT_CALL(*dbif_mock(),471            Db_AddColumnProxy(472                Pointee(473                    AllOf(Field(&GenDb::ColList::cfname_,474                              g_viz_constants.MESSAGE_TABLE_MESSAGE_TYPE),475                        _,476                        Field(&GenDb::ColList::columns_,477                            msg_type_idx_expected_vector)))))478        .Times(1)479        .WillOnce(Return(true));480 481    DbDataValueVec *ts_colname(new DbDataValueVec());482    ts_colname->reserve(2);483    ts_colname->push_back((uint32_t)484        (hdr.get_Timestamp() & g_viz_constants.RowTimeInMask));485    ts_colname->push_back(unm);486    colvalue =new DbDataValueVec();487    boost::ptr_vector<GenDb::NewCol> ts_idx_expected_vector =488        boost::assign::ptr_list_of<GenDb::NewCol>489        (GenDb::NewCol(ts_colname, colvalue, ttl));490 491    EXPECT_CALL(*dbif_mock(),492            Db_AddColumnProxy(493                Pointee(494                    AllOf(Field(&GenDb::ColList::cfname_,495                              g_viz_constants.MESSAGE_TABLE_TIMESTAMP),496                        _,497                        Field(&GenDb::ColList::columns_,498                            ts_idx_expected_vector)))))499        .Times(1)500        .WillOnce(Return(true));501 502    EXPECT_CALL(*dbif_mock(),503            Db_AddColumnProxy(504                Pointee(505                    AllOf(Field(&GenDb::ColList::cfname_,506                              g_viz_constants.MESSAGE_TABLE_KEYWORD),507                        _,508                        _))))509        .Times(3)510        .WillRepeatedly(Return(true));511 512    EXPECT_CALL(*dbif_mock(),513            Db_AddColumnProxy(514                Pointee(515                    AllOf(Field(&GenDb::ColList::cfname_,516                              g_viz_constants.STATS_TABLE_BY_STR_TAG),517                        _,518                        _))))519        .Times(6)520        .WillRepeatedly(Return(true));521 522    MessageTableInsert(&vmsgp);523    vmsgp.msg = NULL;524    delete msg;525}526//#endif527 528TEST_F(DbHandlerTest, ObjectTableInsertTest) {529    SandeshHeader hdr;530    hdr.set_Timestamp(UTCTimestampUsec());531    hdr.set_Source(""127.0.0.1"");532    uint64_t timestamp(hdr.get_Timestamp()); 533    boost::uuids::uuid unm(rgen_());534    std::string table(""ObjectTableInsertTest"");535    std::string rowkey_str(""ObjectTableInsertTestRowkey"");536    std::string xmlmessage = ""<VNSwitchErrorMsgObject type=\\""sandesh\\""><length type=\\""i32\\"">0000000020</length><field1 type=\\""string\\"">field1_value</field1><field2 type=\\""struct\\""><field21 type=\\""i16\\"">21</field21><field22 type=\\""string\\"">string22</field22></field2><field3 type=\\""i32\\"">3</field3></VNSwitchErrorMsgObject>"";537    SandeshXMLMessageTest *msg = dynamic_cast<SandeshXMLMessageTest *>(538        builder_->Create(539            reinterpret_cast<const uint8_t *>(xmlmessage.c_str()),540            xmlmessage.size()));541    msg->SetHeader(hdr);542    VizMsg vmsgp(msg, unm);543 544    int ttl = ttl_map.find(TtlType::GLOBAL_TTL)->second*3600;545      {546        DbDataValueVec *colname(new DbDataValueVec());547        colname->reserve(2);548        colname->push_back(""ObjectTableInsertTestRowkey"");549        colname->push_back((uint32_t)(hdr.get_Timestamp() & g_viz_constants.RowTimeInMask));550 551        DbDataValueVec *colvalue(new DbDataValueVec(1, unm));552        boost::ptr_vector<GenDb::NewCol> expected_vector = 553            boost::assign::ptr_list_of<GenDb::NewCol>554            (GenDb::NewCol(colname, colvalue, ttl));555 556        GenDb::DbDataValueVec rowkey;557        rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits));558        rowkey.push_back((uint8_t)0);559        rowkey.push_back(""ObjectTableInsertTest"");560        EXPECT_CALL(*dbif_mock(),561                Db_AddColumnProxy(562                    Pointee(563                        AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.OBJECT_TABLE), 564                            Field(&GenDb::ColList::rowkey_, rowkey),565                            Field(&GenDb::ColList::columns_,566                                expected_vector)))))567            .Times(1)568            .WillOnce(Return(true));569      }570 571      {572        DbDataValueVec *colname(new DbDataValueVec(1,573            (uint32_t)(hdr.get_Timestamp() & g_viz_constants.RowTimeInMask)));574        DbDataValueVec *colvalue(new DbDataValueVec(1,575            ""ObjectTableInsertTestRowkey""));576        boost::ptr_vector<GenDb::NewCol> expected_vector =577            boost::assign::ptr_list_of<GenDb::NewCol>578            (GenDb::NewCol(colname, colvalue, ttl));579 580        GenDb::DbDataValueVec rowkey;581        rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits));582        rowkey.push_back(""ObjectTableInsertTest"");583        EXPECT_CALL(*dbif_mock(),584                Db_AddColumnProxy(585                    Pointee(586                        AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.OBJECT_VALUE_TABLE),587                            Field(&GenDb::ColList::rowkey_, rowkey),588                            Field(&GenDb::ColList::columns_,589                                expected_vector)))))590            .Times(1)591            .WillOnce(Return(true));592      }593 594      {595        GenDb::DbDataValueVec rowkey;596        rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits));597        rowkey.push_back((uint8_t)0);598        rowkey.push_back(""FieldNames"");599        rowkey.push_back(""fields"");600        rowkey.push_back(""name"");601        EXPECT_CALL(*dbif_mock(),602                Db_AddColumnProxy(603                    Pointee(604                        AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.STATS_TABLE_BY_STR_TAG),605                            Field(&GenDb::ColList::rowkey_, rowkey),_))))606            .Times(5)607            .WillRepeatedly(Return(true));608      }609 610      {611        GenDb::DbDataValueVec rowkey;612        rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits));613        rowkey.push_back((uint8_t)0);614        rowkey.push_back(""FieldNames"");615        rowkey.push_back(""fields"");616        rowkey.push_back(""Source"");617        EXPECT_CALL(*dbif_mock(),618                Db_AddColumnProxy(619                    Pointee(620                        AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.STATS_TABLE_BY_STR_TAG),621                            Field(&GenDb::ColList::rowkey_, rowkey),_))))622            .Times(5)623            .WillRepeatedly(Return(true));624      }625 626    ObjectTableInsert(table, rowkey_str, timestamp, unm, &vmsgp);627    vmsgp.msg = NULL;628    delete msg;629}630 631TEST_F(DbHandlerTest, FlowTableInsertTest) {632    init_vizd_tables();633 634    SandeshHeader hdr;635    hdr.set_Timestamp(UTCTimestampUsec());636    hdr.set_Module(""VizdTest"");637    hdr.set_Source(""127.0.0.1"");638    std::string messagetype("""");639    std::vector<std::pair<std::string, std::vector<FlowLogData> > > flow_msgs;640    // Flow sandesh with single flow sample641    {642        std::string xmlmessage = ""<FlowDataIpv4Object type=\\""sandesh\\""><flowdata type=\\""struct\\"" identifier=\\""1\\""><FlowDataIpv4><flowuuid type=\\""string\\"" identifier=\\""1\\"">555788e0-513c-4351-8711-3fc481cf2eb4</flowuuid><direction_ing type=\\""byte\\"" identifier=\\""2\\"">0</direction_ing><sourcevn type=\\""string\\"" identifier=\\""3\\"">default-domain:demo:vn1</sourcevn><sourceip type=\\""i32\\"" identifier=\\""4\\"">-1062731011</sourceip><destvn type=\\""string\\"" identifier=\\""5\\"">default-domain:demo:vn0</destvn><destip type=\\""i32\\"" identifier=\\""6\\"">-1062731267</destip><protocol type=\\""byte\\"" identifier=\\""7\\"">6</protocol><sport type=\\""i16\\"" identifier=\\""8\\"">5201</sport><dport type=\\""i16\\"" identifier=\\""9\\"">-24590</dport><vm type=\\""string\\"" identifier=\\""12\\"">04430130-664a-4b89-9287-39d71f351207</vm><reverse_uuid type=\\""string\\"" identifier=\\""16\\"">58745ee7-d616-4e59-b8f7-96f896487c9f</reverse_uuid><bytes type=\\""i64\\"" identifier=\\""23\\"">0</bytes><packets type=\\""i64\\"" identifier=\\""24\\"">0</packets><diff_bytes type=\\""i64\\"" identifier=\\""26\\"">0</diff_bytes><diff_packets type=\\""i64\\"" identifier=\\""27\\"">0</diff_packets></FlowDataIpv4></flowdata></FlowDataIpv4Object>"";643 644        std::vector<FlowLogData> flowdata_list;645        FlowLogData flow_data1;646        flow_data1.set_flowuuid(""555788e0-513c-4351-8711-3fc481cf2eb4"");647        flow_data1.set_direction_ing(0);648        flow_data1.set_sourcevn(""default-domain:demo:vn1"");649        flow_data1.set_sourceip(Ip4Address((uint32_t)-1062731011));650        flow_data1.set_destvn(""default-domain:demo:vn0"");651        flow_data1.set_destip(Ip4Address((uint32_t)-1062731267));652        flow_data1.set_protocol(6);653        flow_data1.set_sport(5201);654        flow_data1.set_dport(-24590);655        flow_data1.set_diff_bytes(0);656        flow_data1.set_diff_packets(0);657        flowdata_list.push_back(flow_data1);658        flow_msgs.push_back(std::make_pair(xmlmessage, flowdata_list));659    }660 661    // Flow sandesh with list of flow samples662    {663        std::string xmlmessage = ""<FlowDataIpv4Object type=\\""sandesh\\""><flowdata type=\\""list\\"" identifier=\\""1\\""><list type=\\""struct\\"" size=\\""2\\""><FlowDataIpv4><flowuuid type=\\""string\\"" identifier=\\""1\\"">511788e0-513f-4351-8711-3fc481cf2efa</flowuuid><direction_ing type=\\""byte\\"" identifier=\\""2\\"">1</direction_ing><sourcevn type=\\""string\\"" identifier=\\""3\\"">default-domain:contrail:vn0</sourcevn><sourceip type=\\""i32\\"" identifier=\\""4\\"">168430081</sourceip><destvn type=\\""string\\"" identifier=\\""5\\"">default-domain:contrail:vn1</destvn><destip type=\\""i32\\"" identifier=\\""6\\"">-1062731263</destip><protocol type=\\""byte\\"" identifier=\\""7\\"">17</protocol><sport type=\\""i16\\"" identifier=\\""8\\"">12345</sport><dport type=\\""i16\\"" identifier=\\""9\\"">8087</dport><vm type=\\""string\\"" identifier=\\""12\\"">04430130-6641-1b89-9287-39d71f351206</vm><reverse_uuid type=\\""string\\"" identifier=\\""16\\"">58745ee6-d616-4e59-b8f7-96e896587c9f</reverse_uuid><bytes type=\\""i64\\"" identifier=\\""23\\"">1024</bytes><packets type=\\""i64\\"" identifier=\\""24\\"">4</packets><diff_bytes type=\\""i64\\"" identifier=\\""26\\"">256</diff_bytes><diff_packets type=\\""i64\\"" identifier=\\""27\\"">1</diff_packets></FlowDataIpv4><FlowDataIpv4><flowuuid type=\\""string\\"" identifier=\\""1\\"">525538ef-513f-435f-871f-3fc482cf2ebf</flowuuid><direction_ing type=\\""byte\\"" identifier=\\""2\\"">0</direction_ing><sourcevn type=\\""string\\"" identifier=\\""3\\"">default-domain:demo:vn0</sourcevn><sourceip type=\\""i32\\"" identifier=\\""4\\"">-1062731011</sourceip><destvn type=\\""string\\"" identifier=\\""5\\"">default-domain:contrail:vn0</destvn><destip type=\\""i32\\"" identifier=\\""6\\"">168430082</destip><protocol type=\\""byte\\"" identifier=\\""7\\"">6</protocol><sport type=\\""i16\\"" identifier=\\""8\\"">11221</sport><dport type=\\""i16\\"" identifier=\\""9\\"">8086</dport><vm type=\\""string\\"" identifier=\\""12\\"">04430130-664a-4b89-3456-39d71f351207</vm><reverse_uuid type=\\""string\\"" identifier=\\""16\\"">58745ee3-d613-4e53-b8f3-96f896487c93</reverse_uuid><bytes type=\\""i64\\"" identifier=\\""23\\"">512</bytes><packets type=\\""i64\\"" identifier=\\""24\\"">2</packets><diff_bytes type=\\""i64\\"" identifier=\\""26\\"">512</diff_bytes><diff_packets type=\\""i64\\"" identifier=\\""27\\"">2</diff_packets></FlowDataIpv4></list></flowdata></FlowDataIpv4Object>"";664 665        std::vector<FlowLogData> flowdata_list;666        FlowLogData flow_data1;667        flow_data1.set_flowuuid(""511788e0-513f-4351-8711-3fc481cf2efa"");668        flow_data1.set_direction_ing(1);669        flow_data1.set_sourcevn(""default-domain:contrail:vn0"");670        flow_data1.set_sourceip(Ip4Address(168430081));671        flow_data1.set_destvn(""default-domain:contrail:vn1"");672        flow_data1.set_destip(Ip4Address((uint32_t)-1062731263));673        flow_data1.set_protocol(17);674        flow_data1.set_sport(12345);675        flow_data1.set_dport(8087);676        flow_data1.set_diff_bytes(256);677        flow_data1.set_diff_packets(1);678        flowdata_list.push_back(flow_data1);679 680        FlowLogData flow_data2;681        flow_data2.set_flowuuid(""525538ef-513f-435f-871f-3fc482cf2ebf"");682        flow_data2.set_direction_ing(0);683        flow_data2.set_sourcevn(""default-domain:demo:vn0"");684        flow_data2.set_sourceip(Ip4Address((uint32_t)-1062731011));685        flow_data2.set_destvn(""default-domain:contrail:vn0"");686        flow_data2.set_destip(Ip4Address(168430082));687        flow_data2.set_protocol(6);688        flow_data2.set_sport(11221);689        flow_data2.set_dport(8086);690        flow_data2.set_diff_bytes(512);691        flow_data2.set_diff_packets(2);692        flowdata_list.push_back(flow_data2);693        flow_msgs.push_back(std::make_pair(xmlmessage, flowdata_list));694    }695 696    // Flow sandesh with single flow sample -697    // Renamed ""FlowDataIpv4Object"" to ""FlowLogDataObject""698    {699        std::string xmlmessage = ""<FlowLogDataObject type=\\""sandesh\\""><flowdata type=\\""struct\\"" identifier=\\""1\\""><FlowLogData><flowuuid type=\\""string\\"" identifier=\\""1\\"">555788e0-513c-4351-8711-3fc481cf2eb4</flowuuid><direction_ing type=\\""byte\\"" identifier=\\""2\\"">0</direction_ing><sourcevn type=\\""string\\"" identifier=\\""3\\"">default-domain:demo:vn1</sourcevn><sourceip type=\\""i32\\"" identifier=\\""4\\"">-1062731011</sourceip><destvn type=\\""string\\"" identifier=\\""5\\"">default-domain:demo:vn0</destvn><destip type=\\""i32\\"" identifier=\\""6\\"">-1062731267</destip><protocol type=\\""byte\\"" identifier=\\""7\\"">6</protocol><sport type=\\""i16\\"" identifier=\\""8\\"">5201</sport><dport type=\\""i16\\"" identifier=\\""9\\"">-24590</dport><vm type=\\""string\\"" identifier=\\""12\\"">04430130-664a-4b89-9287-39d71f351207</vm><reverse_uuid type=\\""string\\"" identifier=\\""16\\"">58745ee7-d616-4e59-b8f7-96f896487c9f</reverse_uuid><bytes type=\\""i64\\"" identifier=\\""23\\"">0</bytes><packets type=\\""i64\\"" identifier=\\""24\\"">0</packets><diff_bytes type=\\""i64\\"" identifier=\\""26\\"">0</diff_bytes><diff_packets type=\\""i64\\"" identifier=\\""27\\"">0</diff_packets></FlowLogData></flowdata></FlowLogDataObject>"";700 701        std::vector<FlowLogData> flowdata_list;702        FlowLogData flow_data1;703        flow_data1.set_flowuuid(""555788e0-513c-4351-8711-3fc481cf2eb4"");704        flow_data1.set_direction_ing(0);705        flow_data1.set_sourcevn(""default-domain:demo:vn1"");706        flow_data1.set_sourceip(Ip4Address((uint32_t)-1062731011));707        flow_data1.set_destvn(""default-domain:demo:vn0"");708        flow_data1.set_destip(Ip4Address((uint32_t)-1062731267));709        flow_data1.set_protocol(6);710        flow_data1.set_sport(5201);711        flow_data1.set_dport(-24590);712        flow_data1.set_diff_bytes(0);713        flow_data1.set_diff_packets(0);714        flowdata_list.push_back(flow_data1);715        flow_msgs.push_back(std::make_pair(xmlmessage, flowdata_list));716    }717 718    // Flow sandesh with list of flow samples -719    // Renamed ""FlowDataIpv4Object"" to ""FlowLogDataObject""720    {721        std::string xmlmessage = ""<FlowLogDataObject type=\\""sandesh\\""><flowdata type=\\""list\\"" identifier=\\""1\\""><list type=\\""struct\\"" size=\\""2\\""><FlowLogData><flowuuid type=\\""string\\"" identifier=\\""1\\"">511788e0-513f-4351-8711-3fc481cf2efa</flowuuid><direction_ing type=\\""byte\\"" identifier=\\""2\\"">1</direction_ing><sourcevn type=\\""string\\"" identifier=\\""3\\"">default-domain:contrail:vn0</sourcevn><sourceip type=\\""i32\\"" identifier=\\""4\\"">168430081</sourceip><destvn type=\\""string\\"" identifier=\\""5\\"">default-domain:contrail:vn1</destvn><destip type=\\""i32\\"" identifier=\\""6\\"">-1062731263</destip><protocol type=\\""byte\\"" identifier=\\""7\\"">17</protocol><sport type=\\""i16\\"" identifier=\\""8\\"">12345</sport><dport type=\\""i16\\"" identifier=\\""9\\"">8087</dport><vm type=\\""string\\"" identifier=\\""12\\"">04430130-6641-1b89-9287-39d71f351206</vm><reverse_uuid type=\\""string\\"" identifier=\\""16\\"">58745ee6-d616-4e59-b8f7-96e896587c9f</reverse_uuid><bytes type=\\""i64\\"" identifier=\\""23\\"">1024</bytes><packets type=\\""i64\\"" identifier=\\""24\\"">4</packets><diff_bytes type=\\""i64\\"" identifier=\\""26\\"">256</diff_bytes><diff_packets type=\\""i64\\"" identifier=\\""27\\"">1</diff_packets></FlowLogData><FlowLogData><flowuuid type=\\""string\\"" identifier=\\""1\\"">525538ef-513f-435f-871f-3fc482cf2ebf</flowuuid><direction_ing type=\\""byte\\"" identifier=\\""2\\"">0</direction_ing><sourcevn type=\\""string\\"" identifier=\\""3\\"">default-domain:demo:vn0</sourcevn><sourceip type=\\""i32\\"" identifier=\\""4\\"">-1062731011</sourceip><destvn type=\\""string\\"" identifier=\\""5\\"">default-domain:contrail:vn0</destvn><destip type=\\""i32\\"" identifier=\\""6\\"">168430082</destip><protocol type=\\""byte\\"" identifier=\\""7\\"">6</protocol><sport type=\\""i16\\"" identifier=\\""8\\"">11221</sport><dport type=\\""i16\\"" identifier=\\""9\\"">8086</dport><vm type=\\""string\\"" identifier=\\""12\\"">04430130-664a-4b89-3456-39d71f351207</vm><reverse_uuid type=\\""string\\"" identifier=\\""16\\"">58745ee3-d613-4e53-b8f3-96f896487c93</reverse_uuid><bytes type=\\""i64\\"" identifier=\\""23\\"">512</bytes><packets type=\\""i64\\"" identifier=\\""24\\"">2</packets><diff_bytes type=\\""i64\\"" identifier=\\""26\\"">512</diff_bytes><diff_packets type=\\""i64\\"" identifier=\\""27\\"">2</diff_packets></FlowLogData></list></flowdata></FlowLogDataObject>"";722 723        std::vector<FlowLogData> flowdata_list;724        FlowLogData flow_data1;725        flow_data1.set_flowuuid(""511788e0-513f-4351-8711-3fc481cf2efa"");726        flow_data1.set_direction_ing(1);727        flow_data1.set_sourcevn(""default-domain:contrail:vn0"");728        flow_data1.set_sourceip(Ip4Address(168430081));729        flow_data1.set_destvn(""default-domain:contrail:vn1"");730        flow_data1.set_destip(Ip4Address((uint32_t)-1062731263));731        flow_data1.set_protocol(17);732        flow_data1.set_sport(12345);733        flow_data1.set_dport(8087);734        flow_data1.set_diff_bytes(256);735        flow_data1.set_diff_packets(1);736        flowdata_list.push_back(flow_data1);737 738        FlowLogData flow_data2;739        flow_data2.set_flowuuid(""525538ef-513f-435f-871f-3fc482cf2ebf"");740        flow_data2.set_direction_ing(0);741        flow_data2.set_sourcevn(""default-domain:demo:vn0"");742        flow_data2.set_sourceip(Ip4Address((uint32_t)-1062731011));743        flow_data2.set_destvn(""default-domain:contrail:vn0"");744        flow_data2.set_destip(Ip4Address(168430082));745        flow_data2.set_protocol(6);746        flow_data2.set_sport(11221);747        flow_data2.set_dport(8086);748        flow_data2.set_diff_bytes(512);749        flow_data2.set_diff_packets(2);750        flowdata_list.push_back(flow_data2);751        flow_msgs.push_back(std::make_pair(xmlmessage, flowdata_list));752    }753 754    // FieldNames will be call 7 times each for FlowTable and FlowSeriesTable755    // This dataset has 3 unique svn, 3 unique dvn, and a single vrouter756    {757	GenDb::DbDataValueVec rowkey;758	rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits));759	rowkey.push_back((uint8_t)0);760	rowkey.push_back(""FieldNames"");761	rowkey.push_back(""fields"");762	rowkey.push_back(""name"");763	EXPECT_CALL(*dbif_mock(),764		Db_AddColumnProxy(765		    Pointee(766			AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.STATS_TABLE_BY_STR_TAG),767			    Field(&GenDb::ColList::rowkey_, rowkey),_))))768	    .Times(14)769	    .WillRepeatedly(Return(true));770    }771    {772	GenDb::DbDataValueVec rowkey;773	rowkey.push_back((uint32_t)(hdr.get_Timestamp() >> g_viz_constants.RowTimeInBits));774	rowkey.push_back((uint8_t)0);775	rowkey.push_back(""FieldNames"");776	rowkey.push_back(""fields"");777	rowkey.push_back(""Source"");778	EXPECT_CALL(*dbif_mock(),779		Db_AddColumnProxy(780		    Pointee(781			AllOf(Field(&GenDb::ColList::cfname_, g_viz_constants.STATS_TABLE_BY_STR_TAG),782			    Field(&GenDb::ColList::rowkey_, rowkey),_))))783	    .Times(14)784	    .WillRepeatedly(Return(true));785    }786 787    std::vector<std::pair<std::string, std::vector<FlowLogData> > >::788        const_iterator fit;789    for (fit = flow_msgs.begin(); fit != flow_msgs.end(); fit++) {790        std::auto_ptr<SandeshXMLMessageTest> msg(791            dynamic_cast<SandeshXMLMessageTest *>(792                builder_->Create(reinterpret_cast<const uint8_t *>(793                    fit->first.c_str()), fit->first.size())));794        msg->SetHeader(hdr);795        std::vector<FlowLogData>::const_iterator dit;796        for (dit = fit->second.begin(); dit != fit->second.end(); dit++) {797            boost::uuids::uuid flowu = StringToUuid(dit->get_flowuuid());798            // set expectations for FLOW_TABLE799            {800                GenDb::DbDataValueVec rowkey;801                rowkey.push_back(flowu);802 803                EXPECT_CALL(*dbif_mock(),804                    Db_AddColumnProxy(805                        Pointee(806                            AllOf(Field(&GenDb::ColList::cfname_,807                                        g_viz_constants.FLOW_TABLE),808                                Field(&GenDb::ColList::rowkey_, rowkey)))))809                    .Times(1)810                    .WillOnce(Return(true));811            }812 813            int ttl = ttl_map.find(TtlType::FLOWDATA_TTL)->second*3600;814            GenDb::DbDataValueVec ocolvalue;815            std::ostringstream cv_ss;816            const std::vector<std::string> &frnames(817                g_viz_constants.FlowRecordNames);818            cv_ss << ""{"";819            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_DIFF_BYTES]820                << ""\\"":"" << (uint64_t)dit->get_diff_bytes() << "","";821            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_DIFF_PACKETS]822                << ""\\"":"" << (uint64_t)dit->get_diff_packets() << "","";823            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_SHORT_FLOW]824                << ""\\"":"" << 0 << "","";825            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_FLOWUUID]826                << ""\\"":\\"""" << to_string(flowu) << ""\\"","";827            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_VROUTER]828                << ""\\"":\\"""" << hdr.get_Source() << ""\\"","";829            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_SOURCEVN]830                << ""\\"":\\"""" << dit->get_sourcevn() << ""\\"","";831            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_DESTVN]832                << ""\\"":\\"""" << dit->get_destvn() << ""\\"","";833            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_SOURCEIP]834                << ""\\"":\\"""" << dit->get_sourceip() << ""\\"","";835            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_DESTIP]836                << ""\\"":\\"""" << dit->get_destip() << ""\\"","";837            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_PROTOCOL]838                << ""\\"":"" << (uint16_t)dit->get_protocol() << "","";839            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_SPORT]840                << ""\\"":"" << (uint16_t)dit->get_sport() << "","";841            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_DPORT]842                << ""\\"":"" << (uint16_t)dit->get_dport() << "","";843            cv_ss << ""\\"""" << frnames[FlowRecordFields::FLOWREC_JSON]844                << ""\\"":"" << ""\\""\\"""";845            cv_ss << ""}"";846            std::string ocolvalue_s(cv_ss.str());847            ocolvalue.push_back(ocolvalue_s);848            // set expectations for FLOW_TABLE_SVN_SIP849            {850                GenDb::DbDataValueVec *colname(new GenDb::DbDataValueVec);851                colname->reserve(4);852                colname->push_back(dit->get_sourcevn());853                colname->push_back(dit->get_sourceip());854                colname->push_back((uint32_t)(hdr.get_Timestamp() &855                                              g_viz_constants.RowTimeInMask));856                colname->push_back(flowu);857                GenDb::DbDataValueVec *colvalue(858                    new GenDb::DbDataValueVec(ocolvalue));859                boost::ptr_vector<GenDb::NewCol> expected_vector =860                    boost::assign::ptr_list_of<GenDb::NewCol>861                    (GenDb::NewCol(colname, colvalue, ttl));862 863                GenDb::DbDataValueVec rowkey;864                rowkey.push_back((uint32_t)(hdr.get_Timestamp() >>865                                            g_viz_constants.RowTimeInBits));866                uint8_t partition_no = 0;867                rowkey.push_back(partition_no);868                rowkey.push_back((uint8_t)dit->get_direction_ing());869 870                EXPECT_CALL(*dbif_mock(),871                    Db_AddColumnProxy(872                        Pointee(873                            AllOf(Field(&GenDb::ColList::cfname_,874                                        g_viz_constants.FLOW_TABLE_SVN_SIP),875                                Field(&GenDb::ColList::rowkey_, rowkey),876                                Field(&GenDb::ColList::columns_,877                                      expected_vector)))))878                    .Times(1)879                    .WillOnce(Return(true));880            }881 882            // set expectations for FLOW_TABLE_DVN_DIP883            {884                GenDb::DbDataValueVec *colname(new GenDb::DbDataValueVec);885                colname->reserve(4);886                colname->push_back(dit->get_destvn());887                colname->push_back(dit->get_destip());888                colname->push_back((uint32_t)(hdr.get_Timestamp() &889                                              g_viz_constants.RowTimeInMask));890                colname->push_back(flowu);891                GenDb::DbDataValueVec *colvalue(892                    new GenDb::DbDataValueVec(ocolvalue));893                boost::ptr_vector<GenDb::NewCol> expected_vector =894                    boost::assign::ptr_list_of<GenDb::NewCol>895                    (GenDb::NewCol(colname, colvalue, ttl));896 897                GenDb::DbDataValueVec rowkey;898                rowkey.push_back((uint32_t)(hdr.get_Timestamp() >>899                                            g_viz_constants.RowTimeInBits));900                uint8_t partition_no = 0;901                rowkey.push_back(partition_no);902                rowkey.push_back((uint8_t)dit->get_direction_ing());903 904                EXPECT_CALL(*dbif_mock(),905                    Db_AddColumnProxy(906                        Pointee(907                            AllOf(Field(&GenDb::ColList::cfname_,908                                        g_viz_constants.FLOW_TABLE_DVN_DIP),909                                Field(&GenDb::ColList::rowkey_, rowkey),910                                Field(&GenDb::ColList::columns_,911                                      expected_vector)))))912                    .Times(1)913                    .WillOnce(Return(true));914            }915 916            // set expectations for FLOW_TABLE_PROT_SP917            {918                GenDb::DbDataValueVec *colname(new GenDb::DbDataValueVec);919                colname->reserve(4);920                colname->push_back((uint8_t)dit->get_protocol());921                colname->push_back((uint16_t)dit->get_sport());922                colname->push_back((uint32_t)(hdr.get_Timestamp() &923                                              g_viz_constants.RowTimeInMask));924                colname->push_back(flowu);925                GenDb::DbDataValueVec *colvalue(926                    new GenDb::DbDataValueVec(ocolvalue));927                boost::ptr_vector<GenDb::NewCol> expected_vector =928                    boost::assign::ptr_list_of<GenDb::NewCol>929                    (GenDb::NewCol(colname, colvalue, ttl));930 931                GenDb::DbDataValueVec rowkey;932                rowkey.push_back((uint32_t)(hdr.get_Timestamp() >>933                                            g_viz_constants.RowTimeInBits));934                uint8_t partition_no = 0;935                rowkey.push_back(partition_no);936                rowkey.push_back((uint8_t)dit->get_direction_ing());937 938                EXPECT_CALL(*dbif_mock(),939                    Db_AddColumnProxy(940                        Pointee(941                            AllOf(Field(&GenDb::ColList::cfname_,942                                        g_viz_constants.FLOW_TABLE_PROT_SP),943                                Field(&GenDb::ColList::rowkey_, rowkey),944                                Field(&GenDb::ColList::columns_,945                                      expected_vector)))))946                    .Times(1)947                    .WillOnce(Return(true));948            }949 950            // set expectations for FLOW_TABLE_PROT_DP951            {952                GenDb::DbDataValueVec *colname(new GenDb::DbDataValueVec);953                colname->reserve(4);954                colname->push_back((uint8_t)dit->get_protocol());955                colname->push_back((uint16_t)dit->get_dport());956                colname->push_back((uint32_t)(hdr.get_Timestamp() &957                                              g_viz_constants.RowTimeInMask));958                colname->push_back(flowu);959                GenDb::DbDataValueVec *colvalue(960                    new GenDb::DbDataValueVec(ocolvalue));961                boost::ptr_vector<GenDb::NewCol> expected_vector =962                    boost::assign::ptr_list_of<GenDb::NewCol>963                    (GenDb::NewCol(colname, colvalue, ttl));964 965                GenDb::DbDataValueVec rowkey;966                rowkey.push_back((uint32_t)(hdr.get_Timestamp() >>967                                            g_viz_constants.RowTimeInBits));968                uint8_t partition_no = 0;969                rowkey.push_back(partition_no);970                rowkey.push_back((uint8_t)dit->get_direction_ing());971 972                EXPECT_CALL(*dbif_mock(),973                    Db_AddColumnProxy(974                        Pointee(975                            AllOf(Field(&GenDb::ColList::cfname_,976                                        g_viz_constants.FLOW_TABLE_PROT_DP),977                                Field(&GenDb::ColList::rowkey_, rowkey),978                                Field(&GenDb::ColList::columns_,979                                      expected_vector)))))980                    .Times(1)981                    .WillOnce(Return(true));982            }983 984            // set expectations for FLOW_TABLE_VROUTER985            {986                GenDb::DbDataValueVec *colname(new GenDb::DbDataValueVec);987                colname->reserve(4);988                colname->push_back(hdr.get_Source()); //vrouter989                colname->push_back((uint32_t)(hdr.get_Timestamp() &990                                              g_viz_constants.RowTimeInMask));991                colname->push_back(flowu);992                GenDb::DbDataValueVec *colvalue(993                    new GenDb::DbDataValueVec(ocolvalue));994                boost::ptr_vector<GenDb::NewCol> expected_vector =995                    boost::assign::ptr_list_of<GenDb::NewCol>996                    (GenDb::NewCol(colname, colvalue, ttl));997 998                GenDb::DbDataValueVec rowkey;999                rowkey.push_back((uint32_t)(hdr.get_Timestamp() >>1000                                            g_viz_constants.RowTimeInBits));1001                uint8_t partition_no = 0;1002                rowkey.push_back(partition_no);1003                rowkey.push_back((uint8_t)dit->get_direction_ing());1004 1005                EXPECT_CALL(*dbif_mock(),1006                    Db_AddColumnProxy(1007                        Pointee(1008                            AllOf(Field(&GenDb::ColList::cfname_,1009                                        g_viz_constants.FLOW_TABLE_VROUTER),1010                                Field(&GenDb::ColList::rowkey_, rowkey),1011                                Field(&GenDb::ColList::columns_,1012                                      expected_vector)))))1013                    .Times(1)1014                    .WillOnce(Return(true));1015            }1016        }1017 1018        FlowTableInsert(msg->GetMessageNode(), msg->GetHeader());1019    }1020}1021 1022TEST_F(DbHandlerTest, CanRecordDataForT2Test) {1023    uint32_t t1 = GetDbHandlerCacheParam().field_cache_t2_ + 2;1024    std::string fc_entry(""tabname:vn1"");1025    bool ret = WriteToCache(t1, fc_entry);1026    struct DbHandlerCacheParam cache_param = GetDbHandlerCacheParam();1027    // All the field_cache_t2 should be updated1028    EXPECT_EQ(t1, cache_param.field_cache_t2_);1029    EXPECT_EQ(t1-2, cache_param.field_cache_old_t2_);1030    std::set<std::string>  new_test_cache;1031    new_test_cache.insert(fc_entry);1032    EXPECT_THAT(new_test_cache, ::testing::ContainerEq(1033        cache_param.field_cache_set_[cache_param.new_t2_index_]));1034    EXPECT_EQ(true, ret);1035    // only field_cache_old_t2_ should be updated1036    // t2 is older to field_cache_new_t2_ but1037    // t2 is newer to field_cache_old_t2_1038    uint32_t t2 = cache_param.field_cache_old_t2_+1;1039    fc_entry = ""tabname:vn2"";1040    ret = WriteToCache(t2, fc_entry);1041    cache_param = GetDbHandlerCacheParam();1042    std::set<std::string>  new_test_cache1;1043    new_test_cache1.insert(fc_entry);1044    EXPECT_EQ(t1, cache_param.field_cache_t2_);1045    EXPECT_EQ(t2, cache_param.field_cache_old_t2_);1046    EXPECT_THAT(new_test_cache1, ::testing::ContainerEq(1047        cache_param.field_cache_set_[cache_param.old_t2_index_]));1048    EXPECT_EQ(true, ret);1049    // None should be updated and the function returns false1050    uint32_t t3 = cache_param.field_cache_old_t2_ - 1;1051    fc_entry = ""tabname:vn2"";1052    ret = WriteToCache(t3, fc_entry);1053    cache_param = GetDbHandlerCacheParam();1054    EXPECT_EQ(t1, cache_param.field_cache_t2_);1055    EXPECT_EQ(t2, cache_param.field_cache_old_t2_);1056    EXPECT_EQ(false, ret);1057    // New entry with t2=field_cache_t2_ should return true1058    fc_entry=""tabname:vn3"";1059    ret = WriteToCache(t1, fc_entry);1060    new_test_cache.insert(fc_entry);1061    cache_param = GetDbHandlerCacheParam();1062    EXPECT_THAT(new_test_cache, ::testing::ContainerEq(1063        cache_param.field_cache_set_[cache_param.new_t2_index_]));1064    EXPECT_EQ(true, ret);1065    // New entry with t2=field_cache_old_t2_ should return true1066    fc_entry = ""tabname:vn3"";1067    ret = WriteToCache(t2, fc_entry);1068    new_test_cache1.insert(fc_entry);1069    cache_param = GetDbHandlerCacheParam();1070    EXPECT_THAT(new_test_cache1, ::testing::ContainerEq(1071        cache_param.field_cache_set_[cache_param.old_t2_index_]));1072    EXPECT_EQ(true, ret);1073    // New entry with t2=field_cache_t2_ with existing value should return false1074    fc_entry=""tabname:vn3"";1075    ret = WriteToCache(t1, fc_entry);1076    new_test_cache.insert(fc_entry);1077    cache_param = GetDbHandlerCacheParam();1078    EXPECT_THAT(new_test_cache, ::testing::ContainerEq(1079        cache_param.field_cache_set_[cache_param.new_t2_index_]));1080    EXPECT_EQ(false, ret);1081    // New entry with t2=field_cache_old_t2_ with existing value should return1082    // false1083    fc_entry = ""tabname:vn3"";1084    ret = WriteToCache(t2, fc_entry);1085    new_test_cache1.insert(fc_entry);1086    cache_param = GetDbHandlerCacheParam();1087    EXPECT_THAT(new_test_cache1, ::testing::ContainerEq(1088        cache_param.field_cache_set_[cache_param.old_t2_index_]));1089    EXPECT_EQ(false, ret);1090    // New entry with t2>field_cache_t2_ with existing value should return true1091    t1 += 1;1092    fc_entry = ""tabname:vn3"";1093    ret = WriteToCache(t1, fc_entry);1094    new_test_cache.clear();1095    new_test_cache.insert(fc_entry);1096    cache_param = GetDbHandlerCacheParam();1097    EXPECT_EQ(t1, cache_param.field_cache_t2_);1098    EXPECT_THAT(new_test_cache, ::testing::ContainerEq(1099        cache_param.field_cache_set_[cache_param.new_t2_index_]));1100    EXPECT_EQ(true, ret);1101}1102 1103class FlowTableTest: public ::testing::Test {1104};1105 1106static const std::vector<FlowRecordFields::type> FlowIndexTableColumnValues =1107    boost::assign::list_of1108    (FlowRecordFields::FLOWREC_DIFF_BYTES)1109    (FlowRecordFields::FLOWREC_DIFF_PACKETS)1110    (FlowRecordFields::FLOWREC_SHORT_FLOW)1111    (FlowRecordFields::FLOWREC_FLOWUUID)1112    (FlowRecordFields::FLOWREC_VROUTER)1113    (FlowRecordFields::FLOWREC_SOURCEVN)1114    (FlowRecordFields::FLOWREC_DESTVN)1115    (FlowRecordFields::FLOWREC_SOURCEIP)1116    (FlowRecordFields::FLOWREC_DESTIP)1117    (FlowRecordFields::FLOWREC_PROTOCOL)1118    (FlowRecordFields::FLOWREC_SPORT)1119    (FlowRecordFields::FLOWREC_DPORT)1120    (FlowRecordFields::FLOWREC_JSON);1121 1122static const uint64_t diff_bytes_(123456789);1123static const uint64_t diff_packets_(512);1124static const uint8_t short_flow_(1);1125static const boost::uuids::uuid flow_uuid_ = boost::uuids::random_generator()();1126static const std::string flow_uuid_s_(to_string(flow_uuid_));1127static const std::string vrouter_(""VRouter"");1128static const std::string source_vn_(""SourceVN"");1129static const std::string dest_vn_(""DestVN"");1130static const std::string source_ip_(""1.1.1.1"");1131static const std::string dest_ip_(""2.2.2.2"");1132static const uint8_t protocol_(6);1133static const uint16_t sport_(65535);1134static const uint16_t dport_(80);1135static const std::string json_("""");1136 1137static const GenDb::DbDataValueVec FlowIndexTableColumnDbValues =1138    boost::assign::list_of1139    (GenDb::DbDataValue(diff_bytes_))1140    (GenDb::DbDataValue(diff_packets_))1141    (GenDb::DbDataValue(short_flow_))1142    (GenDb::DbDataValue(flow_uuid_))1143    (GenDb::DbDataValue(vrouter_))1144    (GenDb::DbDataValue(source_vn_))1145    (GenDb::DbDataValue(dest_vn_))1146    (GenDb::DbDataValue(source_ip_))1147    (GenDb::DbDataValue(dest_ip_))1148    (GenDb::DbDataValue(protocol_))1149    (GenDb::DbDataValue(sport_))1150    (GenDb::DbDataValue(dport_))1151    (GenDb::DbDataValue(json_));1152 1153static const std::vector<std::string> FlowIndexTableColumnDbValuesJson =1154    boost::assign::list_of1155    (integerToString(diff_bytes_))1156    (integerToString(diff_packets_))1157    (integerToString(short_flow_))1158    (""\\"""" + flow_uuid_s_ + ""\\"""")1159    (""\\"""" + vrouter_ + ""\\"""")1160    (""\\"""" + source_vn_ + ""\\"""")1161    (""\\"""" + dest_vn_ + ""\\"""")1162    (""\\"""" + source_ip_ + ""\\"""")1163    (""\\"""" + dest_ip_ + ""\\"""")1164    (integerToString(protocol_))1165    (integerToString(sport_))1166    (integerToString(dport_))1167    (""\\"""" + json_ + ""\\"""");1168 1169TEST_F(FlowTableTest, ColumnValues) {1170    FlowValueArray fvalues;1171    EXPECT_EQ(FlowIndexTableColumnValues.size(),1172        FlowIndexTableColumnDbValues.size());1173    EXPECT_EQ(FlowIndexTableColumnDbValues.size(),1174        FlowIndexTableColumnDbValuesJson.size());1175    for (int i = 0; i < (int)FlowIndexTableColumnValues.size(); i++) {1176        fvalues[FlowIndexTableColumnValues[i]] =1177            FlowIndexTableColumnDbValues[i];1178    }1179    GenDb::DbDataValueVec actual_db_values;1180    PopulateFlowIndexTableColumnValues(FlowIndexTableColumnValues, fvalues,1181        &actual_db_values, -1, NULL);1182    EXPECT_EQ(1, actual_db_values.size());1183    std::ostringstream expected_ss;1184    expected_ss << ""{"";1185    for (int i = 0; i < (int)FlowIndexTableColumnDbValuesJson.size(); i++) {1186        if (i) {1187            expected_ss << "","";1188        }1189        expected_ss << ""\\"""" <<1190            g_viz_constants.FlowRecordNames[FlowIndexTableColumnValues[i]] <<1191            ""\\"":"" << FlowIndexTableColumnDbValuesJson[i];1192    }1193    expected_ss << ""}"";1194    EXPECT_EQ(GenDb::DB_VALUE_STRING, actual_db_values[0].which());1195    std::ostringstream actual_ss;1196    actual_ss << actual_db_values[0];1197    EXPECT_EQ(expected_ss.str(), actual_ss.str());1198}1199 1200class UUIDRandomGenTest : public ::testing::Test {

Showing the first 1,200 of 89305 lines. Download the file for the rest.