misc_test.cpp 3.7 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 20
#include "db/meta/SqliteMetaImpl.h"
#include "db/engine/EngineFactory.h"
S
starlord 已提交
21
#include "db/Utils.h"
S
starlord 已提交
22
#include "utils/Status.h"
S
starlord 已提交
23 24
#include "utils/Exception.h"
#include "utils/easylogging++.h"
G
groot 已提交
25

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

using namespace zilliz::milvus;

TEST(DBMiscTest, EXCEPTION_TEST) {
S
starlord 已提交
34
    Exception ex1("");
G
groot 已提交
35 36 37
    std::string what = ex1.what();
    ASSERT_FALSE(what.empty());

S
starlord 已提交
38
    OutOfRangeException ex2;
G
groot 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    what = ex2.what();
    ASSERT_FALSE(what.empty());
}

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 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76

    {
        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 已提交
77 78 79 80 81
}

TEST(DBMiscTest, META_TEST) {
    engine::DBMetaOptions options;
    options.path = "/tmp/milvus_test";
S
starlord 已提交
82
    engine::meta::SqliteMetaImpl impl(options);
G
groot 已提交
83 84 85 86

    time_t tt;
    time( &tt );
    int delta = 10;
87
    engine::meta::DateT dt = engine::utils::GetDate(tt, delta);
G
groot 已提交
88
    ASSERT_GT(dt, 0);
S
starlord 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
}

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

S
starlord 已提交
105 106 107 108 109 110 111
//    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 已提交
112

S
starlord 已提交
113 114 115 116 117 118 119 120 121 122 123 124
    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 已提交
125 126
    status = engine::utils::DeleteTableFilePath(options, file);
    ASSERT_TRUE(status.ok());
G
groot 已提交
127
}