/src/grpc-swift/Sources/GRPC/_EmbeddedThroughput.swift
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2020, gRPC Authors All rights reserved. |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | import Logging |
18 | | import NIOCore |
19 | | import NIOEmbedded |
20 | | import SwiftProtobuf |
21 | | |
22 | | extension EmbeddedChannel { |
23 | | /// Configures an `EmbeddedChannel` for the `EmbeddedClientThroughput` benchmark. |
24 | | /// |
25 | | /// - Important: This is **not** part of the public API. |
26 | | public func _configureForEmbeddedThroughputTest<Request: Message, Response: Message>( |
27 | | callType: GRPCCallType, |
28 | | logger: Logger, |
29 | | requestType: Request.Type = Request.self, |
30 | | responseType: Response.Type = Response.self |
31 | 0 | ) -> EventLoopFuture<Void> { |
32 | 0 | return self.pipeline.addHandlers([ |
33 | 0 | GRPCClientChannelHandler( |
34 | 0 | callType: callType, |
35 | 0 | maximumReceiveMessageLength: .max, |
36 | 0 | logger: logger |
37 | 0 | ), |
38 | 0 | GRPCClientCodecHandler( |
39 | 0 | serializer: ProtobufSerializer<Request>(), |
40 | 0 | deserializer: ProtobufDeserializer<Response>() |
41 | 0 | ), |
42 | 0 | ]) |
43 | 0 | } |
44 | | |
45 | | public func _configureForEmbeddedServerTest( |
46 | | servicesByName serviceProviders: [Substring: CallHandlerProvider], |
47 | | encoding: ServerMessageEncoding, |
48 | | normalizeHeaders: Bool, |
49 | | logger: Logger |
50 | 0 | ) -> EventLoopFuture<Void> { |
51 | 0 | let codec = HTTP2ToRawGRPCServerCodec( |
52 | 0 | servicesByName: serviceProviders, |
53 | 0 | encoding: encoding, |
54 | 0 | errorDelegate: nil, |
55 | 0 | normalizeHeaders: normalizeHeaders, |
56 | 0 | maximumReceiveMessageLength: .max, |
57 | 0 | logger: logger |
58 | 0 | ) |
59 | 0 | return self.pipeline.addHandler(codec) |
60 | 0 | } |
61 | | |
62 | 18.1k | public func _configureForServerFuzzing(configuration: Server.Configuration) throws { |
63 | 18.1k | let configurator = GRPCServerPipelineConfigurator(configuration: configuration) |
64 | 18.1k | // We're always on an `EmbeddedEventLoop`, this is fine. |
65 | 18.1k | try self.pipeline.syncOperations.addHandler(configurator) |
66 | 18.1k | } |
67 | | } |