utils.h 3.4 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 22

#pragma once

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

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

#define TIMING

#ifdef TIMING
#define INIT_TIMER auto start = std::chrono::high_resolution_clock::now();
#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>( \
S
starlord 已提交
38
            std::chrono::high_resolution_clock::now()-start).count() << " ms ";
X
Xu Peng 已提交
39 40 41 42 43 44
#else
#define INIT_TIMER
#define START_TIMER
#define STOP_TIMER(name)
#endif

S
starlord 已提交
45
class BaseTest : public ::testing::Test {
S
starlord 已提交
46
 protected:
S
starlord 已提交
47
    void InitLog();
S
starlord 已提交
48

S
starlord 已提交
49 50
    void SetUp() override;
    void TearDown() override;
S
starlord 已提交
51
    virtual milvus::engine::DBOptions GetOptions();
S
starlord 已提交
52 53 54 55
};

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

S
starlord 已提交
59 60
    void SetUp() override;
    void TearDown() override;
X
Xu Peng 已提交
61 62
};

S
starlord 已提交
63
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
X
Xu Peng 已提交
64
class DBTest2 : public DBTest {
Z
update  
zhiru 已提交
65
 protected:
S
starlord 已提交
66
    milvus::engine::DBOptions GetOptions() override;
X
Xu Peng 已提交
67
};
X
Xu Peng 已提交
68

S
starlord 已提交
69 70 71 72
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class EngineTest : public DBTest {
};

S
starlord 已提交
73 74
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class MetaTest : public BaseTest {
Z
update  
zhiru 已提交
75
 protected:
S
starlord 已提交
76
    std::shared_ptr<milvus::engine::meta::SqliteMetaImpl> impl_;
X
Xu Peng 已提交
77

S
starlord 已提交
78 79
    void SetUp() override;
    void TearDown() override;
X
Xu Peng 已提交
80
};
Z
update  
zhiru 已提交
81

S
starlord 已提交
82 83
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class MySqlDBTest : public DBTest {
S
starlord 已提交
84
 protected:
S
starlord 已提交
85
    milvus::engine::DBOptions GetOptions() override;
Z
update  
zhiru 已提交
86 87
};

S
starlord 已提交
88 89
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class MySqlMetaTest : public BaseTest {
Z
update  
zhiru 已提交
90
 protected:
S
starlord 已提交
91
    std::shared_ptr<milvus::engine::meta::MySQLMetaImpl> impl_;
S
starlord 已提交
92

S
starlord 已提交
93 94
    void SetUp() override;
    void TearDown() override;
S
starlord 已提交
95
    milvus::engine::DBOptions GetOptions() override;
Z
update  
zhiru 已提交
96
};
Z
zhiru 已提交
97

S
starlord 已提交
98
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
S
starlord 已提交
99
class MemManagerTest : public MetaTest {
S
starlord 已提交
100 101 102 103
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class MemManagerTest2 : public DBTest {
Z
zhiru 已提交
104
};