fullstack_context_mutators.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef TEST_CPP_MICROBENCHMARKS_FULLSTACK_CONTEXT_MUTATORS_H
20 #define TEST_CPP_MICROBENCHMARKS_FULLSTACK_CONTEXT_MUTATORS_H
21 
22 #include <grpc/support/log.h>
23 #include <grpcpp/channel.h>
24 #include <grpcpp/create_channel.h>
27 #include <grpcpp/server.h>
28 #include <grpcpp/server_builder.h>
29 #include <grpcpp/server_context.h>
30 
32 
33 namespace grpc {
34 namespace testing {
35 
36 /*******************************************************************************
37  * CONTEXT MUTATORS
38  */
39 
40 static const int kPregenerateKeyCount = 100000;
41 
42 template <class F>
43 auto MakeVector(size_t length, F f) -> std::vector<decltype(f())> {
44  std::vector<decltype(f())> out;
45  out.reserve(length);
46  for (size_t i = 0; i < length; i++) {
47  out.push_back(f());
48  }
49  return out;
50 }
51 
52 class NoOpMutator {
53  public:
54  template <class ContextType>
55  explicit NoOpMutator(ContextType* /*context*/) {}
56 };
57 
58 template <int length>
60  public:
61  static const std::string& Key() { return kKey; }
62 
63  static const std::string& Value() { return kValues[rand() % kValues.size()]; }
64 
65  private:
66  static const std::string kKey;
67  static const std::vector<std::string> kValues;
68 
70  std::string s;
71  s.reserve(length + 1);
72  for (int i = 0; i < length; i++) {
73  s += static_cast<char>(rand());
74  }
75  return s;
76  }
77 };
78 
79 template <int length>
81  public:
82  static const std::string& Key() { return kKey; }
83 
84  static const std::string& Value() { return kValues[rand() % kValues.size()]; }
85 
86  private:
87  static const std::string kKey;
88  static const std::vector<std::string> kValues;
89 
91  std::string s;
92  s.reserve(length + 1);
93  for (int i = 0; i < length; i++) {
94  s += static_cast<char>(rand() % 26 + 'a');
95  }
96  return s;
97  }
98 };
99 
100 template <class Generator, int kNumKeys>
102  public:
104  for (int i = 0; i < kNumKeys; i++) {
106  }
107  }
108 };
109 
110 template <class Generator, int kNumKeys>
112  public:
114  : NoOpMutator(context) {
115  for (int i = 0; i < kNumKeys; i++) {
116  context->AddInitialMetadata(Generator::Key(), Generator::Value());
117  }
118  }
119 };
120 
121 // static initialization
122 
123 template <int length>
125 
126 template <int length>
127 const std::vector<std::string> RandomBinaryMetadata<length>::kValues =
128  MakeVector(kPregenerateKeyCount, GenerateOneString);
129 
130 template <int length>
132 
133 template <int length>
134 const std::vector<std::string> RandomAsciiMetadata<length>::kValues =
135  MakeVector(kPregenerateKeyCount, GenerateOneString);
136 
137 } // namespace testing
138 } // namespace grpc
139 
140 #endif
testing
Definition: aws_request_signer_test.cc:25
grpc::testing::NoOpMutator::NoOpMutator
NoOpMutator(ContextType *)
Definition: fullstack_context_mutators.h:55
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
grpc::ServerContext
Definition: grpcpp/impl/codegen/server_context.h:566
log.h
grpc::testing::RandomAsciiMetadata::Key
static const std::string & Key()
Definition: fullstack_context_mutators.h:82
grpc::testing::Client_AddMetadata::Client_AddMetadata
Client_AddMetadata(ClientContext *context)
Definition: fullstack_context_mutators.h:103
grpc
Definition: grpcpp/alarm.h:33
grpc::testing::RandomAsciiMetadata
Definition: fullstack_context_mutators.h:80
grpc::testing::RandomBinaryMetadata::Value
static const std::string & Value()
Definition: fullstack_context_mutators.h:63
grpc::testing::RandomAsciiMetadata::kKey
static const std::string kKey
Definition: fullstack_context_mutators.h:87
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::testing::RandomBinaryMetadata::GenerateOneString
static std::string GenerateOneString()
Definition: fullstack_context_mutators.h:69
grpc::ClientContext::AddMetadata
void AddMetadata(const std::string &meta_key, const std::string &meta_value)
Definition: client_context.cc:121
grpc::testing::kPregenerateKeyCount
static const int kPregenerateKeyCount
Definition: fullstack_context_mutators.h:40
grpc::testing::RandomAsciiMetadata::GenerateOneString
static std::string GenerateOneString()
Definition: fullstack_context_mutators.h:90
grpc::testing::RandomAsciiMetadata::kValues
static const std::vector< std::string > kValues
Definition: fullstack_context_mutators.h:88
grpc::testing::RandomAsciiMetadata::Value
static const std::string & Value()
Definition: fullstack_context_mutators.h:84
channel.h
grpc::testing::RandomBinaryMetadata::kValues
static const std::vector< std::string > kValues
Definition: fullstack_context_mutators.h:67
helpers.h
server_credentials.h
grpc::ClientContext
Definition: grpcpp/impl/codegen/client_context.h:195
credentials.h
testing::Key
internal::KeyMatcher< M > Key(M inner_matcher)
Definition: cares/cares/test/gmock-1.8.0/gmock/gmock.h:9141
server_context.h
grpc::testing::RandomBinaryMetadata::Key
static const std::string & Key()
Definition: fullstack_context_mutators.h:61
grpc::testing::Server_AddInitialMetadata::Server_AddInitialMetadata
Server_AddInitialMetadata(ServerContext *context)
Definition: fullstack_context_mutators.h:113
grpc::testing::RandomBinaryMetadata
Definition: fullstack_context_mutators.h:59
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
Value
struct Value Value
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:676
server.h
grpc::testing::RandomBinaryMetadata::kKey
static const std::string kKey
Definition: fullstack_context_mutators.h:66
grpc::testing::Client_AddMetadata
Definition: fullstack_context_mutators.h:101
length
std::size_t length
Definition: abseil-cpp/absl/time/internal/test_util.cc:57
grpc::testing::MakeVector
auto MakeVector(size_t length, F f) -> std::vector< decltype(f())>
Definition: fullstack_context_mutators.h:43
grpc::testing::NoOpMutator
Definition: fullstack_context_mutators.h:52
server_builder.h
grpc::testing::Server_AddInitialMetadata
Definition: fullstack_context_mutators.h:111
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
create_channel.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:22