xref: /aosp_15_r20/external/grpc-grpc/test/core/channel/server_call_tracer_factory_test.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 // Copyright 2023 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <memory>
16 
17 #include "gtest/gtest.h"
18 
19 #include "src/core/lib/channel/call_tracer.h"
20 #include "src/core/lib/channel/channel_args.h"
21 #include "src/core/lib/gprpp/crash.h"
22 #include "src/core/lib/resource_quota/arena.h"
23 
24 namespace grpc_core {
25 namespace {
26 
27 class TestServerCallTracerFactory : public ServerCallTracerFactory {
28  public:
CreateNewServerCallTracer(Arena *,const ChannelArgs &)29   ServerCallTracer* CreateNewServerCallTracer(
30       Arena* /*arena*/, const ChannelArgs& /*args*/) override {
31     Crash("Not implemented");
32   }
33 };
34 
TEST(ServerCallTracerFactoryTest,GlobalRegistration)35 TEST(ServerCallTracerFactoryTest, GlobalRegistration) {
36   TestServerCallTracerFactory factory;
37   ServerCallTracerFactory::RegisterGlobal(&factory);
38   EXPECT_EQ(ServerCallTracerFactory::Get(ChannelArgs()), &factory);
39 }
40 
TEST(ServerCallTracerFactoryTest,UsingChannelArgs)41 TEST(ServerCallTracerFactoryTest, UsingChannelArgs) {
42   TestServerCallTracerFactory factory;
43   ChannelArgs args = ChannelArgs().SetObject(&factory);
44   EXPECT_EQ(ServerCallTracerFactory::Get(args), &factory);
45 }
46 
47 }  // namespace
48 }  // namespace grpc_core
49 
main(int argc,char ** argv)50 int main(int argc, char** argv) {
51   ::testing::InitGoogleTest(&argc, argv);
52   return RUN_ALL_TESTS();
53 }
54