utils.cpp 4.6 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 67 68 69 70 71 72

    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();

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

void DBTest::TearDown() {
    delete db_;
W
wxyu 已提交
79 80 81 82

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

G
groot 已提交
83
    boost::filesystem::remove_all("/tmp/milvus_test");
X
Xu Peng 已提交
84 85
}

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

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

void MetaTest::TearDown() {
100
    impl_->DropAll();
X
Xu Peng 已提交
101
}
Z
update  
zhiru 已提交
102

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

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

Z
update  
zhiru 已提交
115 116
    return options;
}
Z
zhiru 已提交
117

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

Z
zhiru 已提交
125 126 127 128 129 130 131 132 133 134
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 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

    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 已提交
150 151
}

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

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