1/**
2 * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * \author hongqing.hu
17 * \date Dec 2020
18 * \brief
19 */
20
21
22#include <gtest/gtest.h>
23#define private public
24#define protected public
25#include "agent/collection_counter.h"
26#include "agent/index_agent.h"
27
28#undef protected
29#undef private
30
31using namespace proxima::be;
32using namespace proxima::be::agent;
33
34class CollectionCounterTest : public testing::Test {
35 protected:
36 // Sets up the test fixture.
37 void SetUp() override {}
38
39 // Tears down the test fixture.
40 void TearDown() override {}
41};
42
43TEST_F(CollectionCounterTest, TestGeneral) {
44 CollectionCounterMap map;
45 std::string name("test1");
46 map.add_counter(name);
47
48 auto counter = map.get_counter(name);
49 ASSERT_TRUE(counter != nullptr);
50
51 uint32_t count = 100;
52 counter->add_active_count(count);
53
54 counter->sub_active_count(count - 1);
55
56 counter->dec_active_count();
57
58 ASSERT_EQ(counter->active_count(), (uint32_t)0);
59
60 map.remove_counter(name);
61
62 counter = map.get_counter(name);
63 ASSERT_TRUE(counter == nullptr);
64}
65