xref: /aosp_15_r20/external/grpc-grpc/test/core/event_engine/mock_event_engine.h (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 // Copyright 2022 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 #ifndef GRPC_TEST_CORE_EVENT_ENGINE_MOCK_EVENT_ENGINE_H
16 #define GRPC_TEST_CORE_EVENT_ENGINE_MOCK_EVENT_ENGINE_H
17 
18 #include <memory>
19 
20 #include "absl/functional/any_invocable.h"
21 #include "absl/status/status.h"
22 #include "absl/status/statusor.h"
23 #include "gmock/gmock.h"
24 
25 #include <grpc/event_engine/endpoint_config.h>
26 #include <grpc/event_engine/event_engine.h>
27 #include <grpc/event_engine/memory_allocator.h>
28 
29 namespace grpc_event_engine {
30 namespace experimental {
31 
32 class MockEventEngine : public EventEngine {
33  public:
34   MOCK_METHOD(
35       absl::StatusOr<std::unique_ptr<Listener>>, CreateListener,
36       (Listener::AcceptCallback on_accept,
37        absl::AnyInvocable<void(absl::Status)> on_shutdown,
38        const EndpointConfig& config,
39        std::unique_ptr<MemoryAllocatorFactory> memory_allocator_factory));
40   MOCK_METHOD(ConnectionHandle, Connect,
41               (OnConnectCallback on_connect, const ResolvedAddress& addr,
42                const EndpointConfig& args, MemoryAllocator memory_allocator,
43                Duration timeout));
44   MOCK_METHOD(bool, CancelConnect, (ConnectionHandle handle));
45   MOCK_METHOD(bool, IsWorkerThread, ());
46   MOCK_METHOD(absl::StatusOr<std::unique_ptr<DNSResolver>>, GetDNSResolver,
47               (const DNSResolver::ResolverOptions& options));
48   MOCK_METHOD(void, Run, (Closure * closure));
49   MOCK_METHOD(void, Run, (absl::AnyInvocable<void()> closure));
50   MOCK_METHOD(TaskHandle, RunAfter, (Duration when, Closure* closure));
51   MOCK_METHOD(TaskHandle, RunAfter,
52               (Duration when, absl::AnyInvocable<void()> closure));
53   MOCK_METHOD(bool, Cancel, (TaskHandle handle));
54 };
55 
56 }  // namespace experimental
57 }  // namespace grpc_event_engine
58 
59 #endif  // GRPC_TEST_CORE_EVENT_ENGINE_MOCK_EVENT_ENGINE_H
60