utils.h 4.0 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.

X
Xu Peng 已提交
18 19 20 21
#pragma once

#include <gtest/gtest.h>
#include <chrono>
S
starlord 已提交
22
#include <memory>
X
Xu Peng 已提交
23 24

#include "db/DB.h"
S
starlord 已提交
25
#include "db/meta/MySQLMetaImpl.h"
Y
youny626 已提交
26
#include "db/meta/SqliteMetaImpl.h"
W
wxyu 已提交
27
#include "scheduler/ResourceFactory.h"
Y
youny626 已提交
28
#include "scheduler/SchedInst.h"
X
Xu Peng 已提交
29 30 31 32 33

#define TIMING

#ifdef TIMING
#define INIT_TIMER auto start = std::chrono::high_resolution_clock::now();
Y
youny626 已提交
34 35 36 37 38 39 40
#define START_TIMER start = std::chrono::high_resolution_clock::now();
#define STOP_TIMER(name)                                                                                            \
    LOG(DEBUG) << "RUNTIME of " << name << ": "                                                                     \
               << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - \
                                                                        start)                                      \
                      .count()                                                                                      \
               << " ms ";
X
Xu Peng 已提交
41 42 43 44 45 46
#else
#define INIT_TIMER
#define START_TIMER
#define STOP_TIMER(name)
#endif

Y
youny626 已提交
47 48
static const char* CONFIG_PATH = "/tmp/milvus_test";
static const char* CONFIG_FILE = "/server_config.yaml";
S
starlord 已提交
49

S
starlord 已提交
50
class BaseTest : public ::testing::Test {
S
starlord 已提交
51
 protected:
Y
youny626 已提交
52 53 54 55 56 57 58 59 60
    void
    InitLog();

    void
    SetUp() override;
    void
    TearDown() override;
    virtual milvus::engine::DBOptions
    GetOptions();
S
starlord 已提交
61 62 63 64
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class DBTest : public BaseTest {
Z
update  
zhiru 已提交
65
 protected:
S
starlord 已提交
66
    milvus::engine::DBPtr db_;
X
Xu Peng 已提交
67

Y
youny626 已提交
68 69 70 71
    void
    SetUp() override;
    void
    TearDown() override;
X
Xu Peng 已提交
72 73
};

S
starlord 已提交
74
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
X
Xu Peng 已提交
75
class DBTest2 : public DBTest {
Z
update  
zhiru 已提交
76
 protected:
Y
youny626 已提交
77 78
    milvus::engine::DBOptions
    GetOptions() override;
X
Xu Peng 已提交
79
};
X
Xu Peng 已提交
80

S
starlord 已提交
81
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
youny626 已提交
82
class EngineTest : public DBTest {};
S
starlord 已提交
83

S
starlord 已提交
84 85
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class MetaTest : public BaseTest {
Z
update  
zhiru 已提交
86
 protected:
S
starlord 已提交
87
    std::shared_ptr<milvus::engine::meta::SqliteMetaImpl> impl_;
X
Xu Peng 已提交
88

Y
youny626 已提交
89 90 91 92
    void
    SetUp() override;
    void
    TearDown() override;
X
Xu Peng 已提交
93
};
Z
update  
zhiru 已提交
94

S
starlord 已提交
95 96
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class MySqlDBTest : public DBTest {
S
starlord 已提交
97
 protected:
Y
youny626 已提交
98 99
    milvus::engine::DBOptions
    GetOptions() override;
Z
update  
zhiru 已提交
100 101
};

S
starlord 已提交
102 103
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class MySqlMetaTest : public BaseTest {
Z
update  
zhiru 已提交
104
 protected:
S
starlord 已提交
105
    std::shared_ptr<milvus::engine::meta::MySQLMetaImpl> impl_;
S
starlord 已提交
106

Y
youny626 已提交
107 108 109 110 111 112
    void
    SetUp() override;
    void
    TearDown() override;
    milvus::engine::DBOptions
    GetOptions() override;
Z
update  
zhiru 已提交
113
};
Z
zhiru 已提交
114

S
starlord 已提交
115
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
youny626 已提交
116
class MemManagerTest : public MetaTest {};
S
starlord 已提交
117 118

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
youny626 已提交
119
class MemManagerTest2 : public DBTest {};