utils.cpp 2.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";
X
Xu Peng 已提交
56 57 58 59 60 61
    return options;
}

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

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

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

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

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

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

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

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