FailingEchoProvider.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2021, 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. import EchoModel
  17. import GRPC
  18. import NIOCore
  19. /// An `Echo_EchoProvider` which always returns failed future for each RPC.
  20. class FailingEchoProvider: Echo_EchoProvider {
  21. let interceptors: Echo_EchoServerInterceptorFactoryProtocol?
  22. init(interceptors: Echo_EchoServerInterceptorFactoryProtocol? = nil) {
  23. self.interceptors = interceptors
  24. }
  25. func get(
  26. request: Echo_EchoRequest,
  27. context: StatusOnlyCallContext
  28. ) -> EventLoopFuture<Echo_EchoResponse> {
  29. return context.eventLoop.makeFailedFuture(GRPCStatus.processingError)
  30. }
  31. func expand(
  32. request: Echo_EchoRequest,
  33. context: StreamingResponseCallContext<Echo_EchoResponse>
  34. ) -> EventLoopFuture<GRPCStatus> {
  35. return context.eventLoop.makeFailedFuture(GRPCStatus.processingError)
  36. }
  37. func collect(
  38. context: UnaryResponseCallContext<Echo_EchoResponse>
  39. ) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void> {
  40. return context.eventLoop.makeFailedFuture(GRPCStatus.processingError)
  41. }
  42. func update(
  43. context: StreamingResponseCallContext<Echo_EchoResponse>
  44. ) -> EventLoopFuture<(StreamEvent<Echo_EchoRequest>) -> Void> {
  45. return context.eventLoop.makeFailedFuture(GRPCStatus.processingError)
  46. }
  47. }