utils.cpp 3.4 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 62
    return options;
}

void DBTest::SetUp() {
    InitLog();
    auto options = GetOptions();
G
groot 已提交
63
    db_ = engine::DBFactory::Build(options);
X
Xu Peng 已提交
64 65 66 67
}

void DBTest::TearDown() {
    delete db_;
G
groot 已提交
68
    boost::filesystem::remove_all("/tmp/milvus_test");
X
Xu Peng 已提交
69 70
}

X
Xu Peng 已提交
71 72
engine::Options DBTest2::GetOptions() {
    auto options = engine::OptionsFactory::Build();
G
groot 已提交
73
    options.meta.path = "/tmp/milvus_test";
X
Xu Peng 已提交
74
    options.meta.archive_conf = engine::ArchiveConf("delete", "disk:1");
Z
update  
zhiru 已提交
75
    options.meta.backend_uri = "sqlite://:@:/";
X
Xu Peng 已提交
76 77 78
    return options;
}

X
Xu Peng 已提交
79
void MetaTest::SetUp() {
X
Xu Peng 已提交
80
    InitLog();
X
Xu Peng 已提交
81 82 83 84
    impl_ = engine::DBMetaImplFactory::Build();
}

void MetaTest::TearDown() {
85
    impl_->DropAll();
X
Xu Peng 已提交
86
}
Z
update  
zhiru 已提交
87 88

zilliz::milvus::engine::DBMetaOptions MySQLTest::getDBMetaOptions() {
Z
zhiru 已提交
89 90 91
//    std::string path = "/tmp/milvus_test";
//    engine::DBMetaOptions options = engine::DBMetaOptionsFactory::Build(path);
    zilliz::milvus::engine::DBMetaOptions options;
Z
update  
zhiru 已提交
92
    options.path = "/tmp/milvus_test";
Z
zhiru 已提交
93
    options.backend_uri = DBTestEnvironment::getURI();
G
groot 已提交
94 95 96 97 98
    
    if(options.backend_uri.empty()) {
        throw std::exception();
    }

Z
update  
zhiru 已提交
99 100
    return options;
}
Z
zhiru 已提交
101 102 103 104

zilliz::milvus::engine::Options MySQLDBTest::GetOptions() {
    auto options = engine::OptionsFactory::Build();
    options.meta.path = "/tmp/milvus_test";
Z
zhiru 已提交
105
    options.meta.backend_uri = DBTestEnvironment::getURI();
Z
zhiru 已提交
106 107
    return options;
}
Z
zhiru 已提交
108

Z
zhiru 已提交
109 110 111 112 113 114 115 116 117 118 119 120
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();
}

Z
zhiru 已提交
121 122 123 124 125 126 127 128 129
int main(int argc, char **argv) {
    ::testing::InitGoogleTest(&argc, argv);
    if (argc > 1) {
        uri = argv[1];
    }
//    std::cout << uri << std::endl;
    ::testing::AddGlobalTestEnvironment(new DBTestEnvironment);
    return RUN_ALL_TESTS();
}