test_misc.cpp 3.8 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

G
groot 已提交
18
#include "db/Options.h"
S
starlord 已提交
19
#include "db/Utils.h"
Y
youny626 已提交
20 21
#include "db/engine/EngineFactory.h"
#include "db/meta/SqliteMetaImpl.h"
S
starlord 已提交
22
#include "utils/Exception.h"
Y
youny626 已提交
23
#include "utils/Status.h"
G
groot 已提交
24

S
starlord 已提交
25 26
#include <gtest/gtest.h>
#include <boost/filesystem.hpp>
Y
youny626 已提交
27
#include <thread>
G
groot 已提交
28 29 30
#include <vector>

TEST(DBMiscTest, EXCEPTION_TEST) {
S
starlord 已提交
31
    milvus::Exception ex1(100, "error");
G
groot 已提交
32
    std::string what = ex1.what();
33 34
    ASSERT_EQ(what, "error");
    ASSERT_EQ(ex1.code(), 100);
G
groot 已提交
35

S
starlord 已提交
36 37
    milvus::InvalidArgumentException ex2;
    ASSERT_EQ(ex2.code(), milvus::SERVER_INVALID_ARGUMENT);
G
groot 已提交
38 39 40 41
}

TEST(DBMiscTest, OPTIONS_TEST) {
    try {
S
starlord 已提交
42
        milvus::engine::ArchiveConf archive("$$##");
Y
youny626 已提交
43
    } catch (std::exception& ex) {
G
groot 已提交
44 45 46 47
        ASSERT_TRUE(true);
    }

    {
S
starlord 已提交
48
        milvus::engine::ArchiveConf archive("delete", "no");
G
groot 已提交
49 50 51 52
        ASSERT_TRUE(archive.GetCriterias().empty());
    }

    {
S
starlord 已提交
53
        milvus::engine::ArchiveConf archive("delete", "1:2");
G
groot 已提交
54 55 56 57
        ASSERT_TRUE(archive.GetCriterias().empty());
    }

    {
S
starlord 已提交
58
        milvus::engine::ArchiveConf archive("delete", "1:2:3");
G
groot 已提交
59 60
        ASSERT_TRUE(archive.GetCriterias().empty());
    }
G
groot 已提交
61 62

    {
S
starlord 已提交
63
        milvus::engine::ArchiveConf archive("delete");
Y
youny626 已提交
64
        milvus::engine::ArchiveConf::CriteriaT criterial = {{"disk", 1024}, {"days", 100}};
G
groot 已提交
65 66 67 68 69 70
        archive.SetCriterias(criterial);

        auto crit = archive.GetCriterias();
        ASSERT_EQ(criterial["disk"], 1024);
        ASSERT_EQ(criterial["days"], 100);
    }
G
groot 已提交
71 72 73
}

TEST(DBMiscTest, META_TEST) {
S
starlord 已提交
74
    milvus::engine::DBMetaOptions options;
S
starlord 已提交
75
    options.path_ = "/tmp/milvus_test";
S
starlord 已提交
76
    milvus::engine::meta::SqliteMetaImpl impl(options);
G
groot 已提交
77 78

    time_t tt;
S
starlord 已提交
79
    time(&tt);
G
groot 已提交
80
    int delta = 10;
S
starlord 已提交
81
    milvus::engine::meta::DateT dt = milvus::engine::utils::GetDate(tt, delta);
G
groot 已提交
82
    ASSERT_GT(dt, 0);
S
starlord 已提交
83 84 85
}

TEST(DBMiscTest, UTILS_TEST) {
S
starlord 已提交
86
    milvus::engine::DBMetaOptions options;
S
starlord 已提交
87 88 89
    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");
S
starlord 已提交
90 91

    const std::string TABLE_NAME = "test_tbl";
S
starlord 已提交
92
    auto status = milvus::engine::utils::CreateTablePath(options, TABLE_NAME);
S
starlord 已提交
93
    ASSERT_TRUE(status.ok());
S
starlord 已提交
94
    ASSERT_TRUE(boost::filesystem::exists(options.path_));
Y
youny626 已提交
95
    for (auto& path : options.slave_paths_) {
S
starlord 已提交
96
        ASSERT_TRUE(boost::filesystem::exists(path));
S
starlord 已提交
97 98
    }

Y
youny626 已提交
99 100 101 102 103 104 105
    //    options.slave_paths.push_back("/");
    //    status =  engine::utils::CreateTablePath(options, TABLE_NAME);
    //    ASSERT_FALSE(status.ok());
    //
    //    options.path = "/";
    //    status =  engine::utils::CreateTablePath(options, TABLE_NAME);
    //    ASSERT_FALSE(status.ok());
S
starlord 已提交
106

S
starlord 已提交
107
    milvus::engine::meta::TableFileSchema file;
S
starlord 已提交
108 109 110 111
    file.id_ = 50;
    file.table_id_ = TABLE_NAME;
    file.file_type_ = 3;
    file.date_ = 155000;
S
starlord 已提交
112
    status = milvus::engine::utils::GetTableFilePath(options, file);
S
starlord 已提交
113 114 115
    ASSERT_FALSE(status.ok());
    ASSERT_TRUE(file.location_.empty());

S
starlord 已提交
116
    status = milvus::engine::utils::DeleteTablePath(options, TABLE_NAME);
S
starlord 已提交
117 118
    ASSERT_TRUE(status.ok());

S
starlord 已提交
119
    status = milvus::engine::utils::DeleteTableFilePath(options, file);
S
starlord 已提交
120
    ASSERT_TRUE(status.ok());
S
starlord 已提交
121
}