Stub implementations for async stubs. DO NOT MOCK: Customizing options doesn't work properly in mocks. Use InProcessChannelBuilder to create a real channel suitable for testing. It is also possible to mock Channel instead. This class is thread-safe. @since 1.26.0
| 32 | * @since 1.26.0 |
| 33 | */ |
| 34 | @CheckReturnValue |
| 35 | public abstract class AbstractAsyncStub<S extends AbstractAsyncStub<S>> extends AbstractStub<S> { |
| 36 | |
| 37 | protected AbstractAsyncStub(Channel channel, CallOptions callOptions) { |
| 38 | super(channel, callOptions); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Returns a new async stub with the given channel for the provided method configurations. |
| 43 | * |
| 44 | * @since 1.26.0 |
| 45 | * @param factory the factory to create an async stub |
| 46 | * @param channel the channel that this stub will use to do communications |
| 47 | */ |
| 48 | public static <T extends AbstractStub<T>> T newStub( |
| 49 | StubFactory<T> factory, Channel channel) { |
| 50 | return newStub(factory, channel, CallOptions.DEFAULT); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns a new async stub with the given channel for the provided method configurations. |
| 55 | * |
| 56 | * @since 1.26.0 |
| 57 | * @param factory the factory to create an async stub |
| 58 | * @param channel the channel that this stub will use to do communications |
| 59 | * @param callOptions the runtime call options to be applied to every call on this stub |
| 60 | */ |
| 61 | public static <T extends AbstractStub<T>> T newStub( |
| 62 | StubFactory<T> factory, Channel channel, CallOptions callOptions) { |
| 63 | T stub = factory.newStub( |
| 64 | channel, callOptions.withOption(ClientCalls.STUB_TYPE_OPTION, StubType.ASYNC)); |
| 65 | assert stub instanceof AbstractAsyncStub |
| 66 | : String.format("Expected AbstractAsyncStub, but got %s.", stub.getClass()); |
| 67 | return stub; |
| 68 | } |
| 69 | } |
nothing calls this directly
no outgoing calls
no test coverage detected