Loading...
Searching...
No Matches
lock_free_collector_pool_test.cpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
21
22#include <glog/logging.h>
23#include <gmock/gmock.h>
24#include <gtest/gtest.h>
25
27
28namespace resdb {
29namespace {
30
31using ::testing::Test;
32
33class CollectorPoolTest : public Test {
34 public:
35 int AddRequest(LockFreeCollectorPool* pool, uint64_t seq) {
36 Request request;
37 request.set_seq(seq);
38
39 TransactionCollector* collector = pool->GetCollector(seq);
40 if (collector == nullptr) {
41 return 1;
42 }
43 return collector->AddRequest(
44 std::make_unique<Request>(request), SignatureInfo(), false,
45 [](const Request&, int, TransactionCollector::CollectorDataType*,
46 std::atomic<TransactionStatue>*, bool) {});
47 }
48};
49
50TEST_F(CollectorPoolTest, AddRequest) {
51 LockFreeCollectorPool pool("test", 2, nullptr);
52 for (int i = 0; i < 16; ++i) {
53 int ret = AddRequest(&pool, i);
54 EXPECT_EQ(ret, 0);
55 }
56 int ret = AddRequest(&pool, 16);
57 EXPECT_EQ(ret, -2);
58 pool.Update(8);
59 EXPECT_EQ(AddRequest(&pool, 16), 0);
60}
61
62} // namespace
63
64} // namespace resdb
std::list< std::unique_ptr< RequestInfo > > CollectorDataType
TEST_F(ResDBTest, TestPBFTService)