misc_test.cpp 3.9 KB
Newer Older
G
groot 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include <gtest/gtest.h>
#include <thread>
#include <easylogging++.h>
#include <boost/filesystem.hpp>

#include "db/Exception.h"
#include "db/Status.h"
#include "db/Options.h"
S
starlord 已提交
14 15
#include "db/meta/SqliteMetaImpl.h"
#include "db/engine/EngineFactory.h"
S
starlord 已提交
16
#include "db/Utils.h"
G
groot 已提交
17 18 19 20 21

#include <vector>

using namespace zilliz::milvus;

G
groot 已提交
22 23 24 25 26 27 28
namespace {
    void CopyStatus(engine::Status& st1, engine::Status& st2) {
        st1 = st2;
    }

}

G
groot 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
TEST(DBMiscTest, EXCEPTION_TEST) {
    engine::Exception ex1("");
    std::string what = ex1.what();
    ASSERT_FALSE(what.empty());

    engine::OutOfRangeException ex2;
    what = ex2.what();
    ASSERT_FALSE(what.empty());
}

TEST(DBMiscTest, STATUS_TEST) {
    engine::Status status = engine::Status::OK();
    std::string str = status.ToString();
    ASSERT_FALSE(str.empty());

    status = engine::Status::Error("wrong", "mistake");
    ASSERT_TRUE(status.IsError());
    str = status.ToString();
    ASSERT_FALSE(str.empty());

    status = engine::Status::NotFound("wrong", "mistake");
    ASSERT_TRUE(status.IsNotFound());
    str = status.ToString();
    ASSERT_FALSE(str.empty());

    status = engine::Status::DBTransactionError("wrong", "mistake");
    ASSERT_TRUE(status.IsDBTransactionError());
    str = status.ToString();
    ASSERT_FALSE(str.empty());
G
groot 已提交
58 59 60 61

    engine::Status status_copy = engine::Status::OK();
    CopyStatus(status_copy, status);
    ASSERT_TRUE(status.IsDBTransactionError());
G
groot 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
}

TEST(DBMiscTest, OPTIONS_TEST) {
    try {
        engine::ArchiveConf archive("$$##");
    } catch (std::exception& ex) {
        ASSERT_TRUE(true);
    }

    {
        engine::ArchiveConf archive("delete", "no");
        ASSERT_TRUE(archive.GetCriterias().empty());
    }

    {
        engine::ArchiveConf archive("delete", "1:2");
        ASSERT_TRUE(archive.GetCriterias().empty());
    }

    {
        engine::ArchiveConf archive("delete", "1:2:3");
        ASSERT_TRUE(archive.GetCriterias().empty());
    }
G
groot 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97

    {
        engine::ArchiveConf archive("delete");
        engine::ArchiveConf::CriteriaT criterial = {
            {"disk", 1024},
            {"days", 100}
        };
        archive.SetCriterias(criterial);

        auto crit = archive.GetCriterias();
        ASSERT_EQ(criterial["disk"], 1024);
        ASSERT_EQ(criterial["days"], 100);
    }
G
groot 已提交
98 99 100 101 102
}

TEST(DBMiscTest, META_TEST) {
    engine::DBMetaOptions options;
    options.path = "/tmp/milvus_test";
S
starlord 已提交
103
    engine::meta::SqliteMetaImpl impl(options);
G
groot 已提交
104 105 106 107

    time_t tt;
    time( &tt );
    int delta = 10;
108
    engine::meta::DateT dt = engine::utils::GetDate(tt, delta);
G
groot 已提交
109
    ASSERT_GT(dt, 0);
S
starlord 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
}

TEST(DBMiscTest, UTILS_TEST) {
    engine::DBMetaOptions options;
    options.path = "/tmp/milvus_test/main";
    options.slave_paths.push_back("/tmp/milvus_test/slave_1");
    options.slave_paths.push_back("/tmp/milvus_test/slave_2");

    const std::string TABLE_NAME = "test_tbl";
    auto status =  engine::utils::CreateTablePath(options, TABLE_NAME);
    ASSERT_TRUE(status.ok());
    ASSERT_TRUE(boost::filesystem::exists(options.path));
    for(auto& path : options.slave_paths) {
       ASSERT_TRUE(boost::filesystem::exists(path));
    }

    engine::meta::TableFileSchema file;
    file.id_ = 50;
    file.table_id_ = TABLE_NAME;
    file.file_type_ = 3;
    file.date_ = 155000;
    status = engine::utils::GetTableFilePath(options, file);
    ASSERT_FALSE(status.ok());
    ASSERT_TRUE(file.location_.empty());

    status = engine::utils::DeleteTablePath(options, TABLE_NAME);
    ASSERT_TRUE(status.ok());

S
starlord 已提交
138 139 140 141
    status = engine::utils::DeleteTableFilePath(options, file);
    ASSERT_TRUE(status.ok());


G
groot 已提交
142
}