utils.cpp 4.8 KB
Newer Older
X
Xu Peng 已提交
1 2 3 4 5 6 7 8
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <easylogging++.h>
X
Xu Peng 已提交
9 10
#include <thread>
#include <boost/filesystem.hpp>
X
Xu Peng 已提交
11 12

#include "utils.h"
X
Xu Peng 已提交
13
#include "db/Factories.h"
Z
update  
zhiru 已提交
14
#include "db/Options.h"
X
Xu Peng 已提交
15

Z
zhiru 已提交
16 17
INITIALIZE_EASYLOGGINGPP

J
jinhai 已提交
18
using namespace zilliz::milvus;
X
Xu Peng 已提交
19

Z
zhiru 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
static std::string uri;

class DBTestEnvironment : public ::testing::Environment {
public:

//    explicit DBTestEnvironment(std::string uri) : uri_(uri) {}

    static std::string getURI() {
        return uri;
    }

    void SetUp() override {
        getURI();
    }

};

X
Xu Peng 已提交
37 38 39 40 41 42 43
void ASSERT_STATS(engine::Status& stat) {
    ASSERT_TRUE(stat.ok());
    if(!stat.ok()) {
        std::cout << stat.ToString() << std::endl;
    }
}

Z
zhiru 已提交
44

X
Xu Peng 已提交
45
void DBTest::InitLog() {
X
Xu Peng 已提交
46 47 48 49 50 51
    el::Configurations defaultConf;
    defaultConf.setToDefault();
    defaultConf.set(el::Level::Debug,
            el::ConfigurationType::Format, "[%thread-%datetime-%level]: %msg (%fbase:%line)");
    el::Loggers::reconfigureLogger("default", defaultConf);
}
X
Xu Peng 已提交
52

X
Xu Peng 已提交
53
engine::Options DBTest::GetOptions() {
X
Xu Peng 已提交
54
    auto options = engine::OptionsFactory::Build();
G
groot 已提交
55
    options.meta.path = "/tmp/milvus_test";
Z
update  
zhiru 已提交
56
    options.meta.backend_uri = "sqlite://:@:/";
X
Xu Peng 已提交
57 58 59 60 61
    return options;
}

void DBTest::SetUp() {
    InitLog();
W
wxyu 已提交
62 63 64 65 66

    auto res_mgr = engine::ResMgrInst::GetInstance();
    res_mgr->Clear();
    res_mgr->Add(engine::ResourceFactory::Create("disk", "DISK", 0, true, false));
    res_mgr->Add(engine::ResourceFactory::Create("cpu", "CPU", 0, true, true));
Y
Yu Kun 已提交
67
    res_mgr->Add(engine::ResourceFactory::Create("gtx1660", "GPU", 0, true, true));
W
wxyu 已提交
68 69

    auto default_conn = engine::Connection("IO", 500.0);
Y
Yu Kun 已提交
70
    auto PCIE = engine::Connection("IO", 11000.0);
W
wxyu 已提交
71
    res_mgr->Connect("disk", "cpu", default_conn);
Y
Yu Kun 已提交
72
    res_mgr->Connect("cpu", "gtx1660", PCIE);
W
wxyu 已提交
73 74 75
    res_mgr->Start();
    engine::SchedInst::GetInstance()->Start();

X
Xu Peng 已提交
76
    auto options = GetOptions();
G
groot 已提交
77
    db_ = engine::DBFactory::Build(options);
X
Xu Peng 已提交
78 79 80 81
}

void DBTest::TearDown() {
    delete db_;
W
wxyu 已提交
82 83 84 85

    engine::ResMgrInst::GetInstance()->Stop();
    engine::SchedInst::GetInstance()->Stop();

G
groot 已提交
86
    boost::filesystem::remove_all("/tmp/milvus_test");
X
Xu Peng 已提交
87 88
}

X
Xu Peng 已提交
89 90
engine::Options DBTest2::GetOptions() {
    auto options = engine::OptionsFactory::Build();
G
groot 已提交
91
    options.meta.path = "/tmp/milvus_test";
X
Xu Peng 已提交
92
    options.meta.archive_conf = engine::ArchiveConf("delete", "disk:1");
Z
update  
zhiru 已提交
93
    options.meta.backend_uri = "sqlite://:@:/";
X
Xu Peng 已提交
94 95 96
    return options;
}

X
Xu Peng 已提交
97
void MetaTest::SetUp() {
X
Xu Peng 已提交
98
    InitLog();
X
Xu Peng 已提交
99 100 101 102
    impl_ = engine::DBMetaImplFactory::Build();
}

void MetaTest::TearDown() {
103
    impl_->DropAll();
X
Xu Peng 已提交
104
}
Z
update  
zhiru 已提交
105

Z
zhiru 已提交
106
zilliz::milvus::engine::DBMetaOptions DISABLED_MySQLTest::getDBMetaOptions() {
Z
zhiru 已提交
107 108 109
//    std::string path = "/tmp/milvus_test";
//    engine::DBMetaOptions options = engine::DBMetaOptionsFactory::Build(path);
    zilliz::milvus::engine::DBMetaOptions options;
Z
update  
zhiru 已提交
110
    options.path = "/tmp/milvus_test";
Z
zhiru 已提交
111
    options.backend_uri = DBTestEnvironment::getURI();
G
groot 已提交
112

G
groot 已提交
113
    if(options.backend_uri.empty()) {
G
groot 已提交
114 115
//        throw std::exception();
        options.backend_uri = "mysql://root:Fantast1c@192.168.1.194:3306/";
G
groot 已提交
116 117
    }

Z
update  
zhiru 已提交
118 119
    return options;
}
Z
zhiru 已提交
120

Z
zhiru 已提交
121
zilliz::milvus::engine::Options DISABLED_MySQLDBTest::GetOptions() {
Z
zhiru 已提交
122 123
    auto options = engine::OptionsFactory::Build();
    options.meta.path = "/tmp/milvus_test";
Z
zhiru 已提交
124
    options.meta.backend_uri = DBTestEnvironment::getURI();
Z
zhiru 已提交
125 126
    return options;
}
Z
zhiru 已提交
127

Z
zhiru 已提交
128 129 130 131 132 133 134 135 136 137
void NewMemManagerTest::InitLog() {
    el::Configurations defaultConf;
    defaultConf.setToDefault();
    defaultConf.set(el::Level::Debug,
                    el::ConfigurationType::Format, "[%thread-%datetime-%level]: %msg (%fbase:%line)");
    el::Loggers::reconfigureLogger("default", defaultConf);
}

void NewMemManagerTest::SetUp() {
    InitLog();
W
wxyu 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

    auto res_mgr = engine::ResMgrInst::GetInstance();
    res_mgr->Clear();
    res_mgr->Add(engine::ResourceFactory::Create("disk", "DISK", 0, true, false));
    res_mgr->Add(engine::ResourceFactory::Create("cpu", "CPU", 0, true, true));

    auto default_conn = engine::Connection("IO", 500.0);
    res_mgr->Connect("disk", "cpu", default_conn);
    res_mgr->Start();
    engine::SchedInst::GetInstance()->Start();
}

void NewMemManagerTest::TearDown() {
    engine::ResMgrInst::GetInstance()->Stop();
    engine::SchedInst::GetInstance()->Stop();
Z
zhiru 已提交
153 154
}

Z
zhiru 已提交
155 156 157 158 159
int main(int argc, char **argv) {
    ::testing::InitGoogleTest(&argc, argv);
    if (argc > 1) {
        uri = argv[1];
    }
G
groot 已提交
160 161 162 163

//    if(uri.empty()) {
//        uri = "mysql://root:Fantast1c@192.168.1.194:3306/";
//    }
Z
zhiru 已提交
164 165 166 167
//    std::cout << uri << std::endl;
    ::testing::AddGlobalTestEnvironment(new DBTestEnvironment);
    return RUN_ALL_TESTS();
}