Loading...
Searching...
No Matches
geo_global_executor_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
26#include <future>
27
31
32namespace resdb {
33namespace {
34
35using ::resdb::testing::EqualsProto;
36using ::testing::Test;
37
38class GlobalExecutorTest : public Test {
39 public:
40 GlobalExecutorTest()
41 : // just set the monitor time to 1 second to return early.
42 config_({GenerateReplicaInfo(1, "127.0.0.1", 1234),
43 GenerateReplicaInfo(2, "127.0.0.1", 1235),
44 GenerateReplicaInfo(3, "127.0.0.1", 1236),
45 GenerateReplicaInfo(4, "127.0.0.1", 1237)},
46 GenerateReplicaInfo(1, "127.0.0.1", 1234)) {}
47
48 protected:
49 ResDBConfig config_;
50};
51
52TEST_F(GlobalExecutorTest, ExecuteSuccess) {
53 auto mock_executor = std::make_unique<MockTransactionManager>();
54
55 Request request;
56 request.set_seq(1);
57 BatchUserRequest batch_request;
58 batch_request.add_user_requests()->mutable_request()->set_data(
59 "global_execute_test");
60 batch_request.SerializeToString(request.mutable_data());
61
62 EXPECT_CALL(*mock_executor, ExecuteBatch(EqualsProto(batch_request)))
63 .Times(1);
64
65 GeoGlobalExecutor global_executor(std::move(mock_executor), config_);
66 global_executor.Execute(std::make_unique<Request>(request));
67}
68
69TEST_F(GlobalExecutorTest, ExecuteSkiped) {
70 auto mock_executor = std::make_unique<MockTransactionManager>();
71
72 Request request;
73 request.set_seq(1);
74
75 EXPECT_CALL(*mock_executor, ExecuteBatch).Times(0);
76
77 GeoGlobalExecutor global_executor(std::move(mock_executor), config_);
78 global_executor.Execute(std::make_unique<Request>(request));
79}
80
81TEST_F(GlobalExecutorTest, ExecuteFailed) {
82 auto mock_executor = std::make_unique<MockTransactionManager>();
83
84 Request request;
85 request.set_seq(1);
86 request.mutable_data()->append("append wrong data");
87 EXPECT_CALL(*mock_executor, ExecuteBatch).Times(0);
88
89 GeoGlobalExecutor global_executor(std::move(mock_executor), config_);
90 global_executor.Execute(std::make_unique<Request>(request));
91}
92
93} // namespace
94
95} // namespace resdb
ReplicaInfo GenerateReplicaInfo(int id, const std::string &ip, int port)
TEST_F(ResDBTest, TestPBFTService)
std::unique_ptr< ResDBConfig > config_