Search in sources :

Example 1 with ManagedClientTransport

use of io.grpc.internal.ManagedClientTransport in project grpc-java by grpc.

the class AbstractTransportTest method doPingPong.

/**
   * Helper that simply does an RPC. It can be used similar to a sleep for negative testing: to give
   * time for actions _not_ to happen. Since it is based on doing an actual RPC with actual
   * callbacks, it generally provides plenty of time for Runnables to execute. But it is also faster
   * on faster machines and more reliable on slower machines.
   */
private void doPingPong(MockServerListener serverListener) throws InterruptedException {
    ManagedClientTransport client = newClientTransport(server);
    runIfNotNull(client.start(mock(ManagedClientTransport.Listener.class)));
    ClientStream clientStream = client.newStream(methodDescriptor, new Metadata());
    ClientStreamListener mockClientStreamListener = mock(ClientStreamListener.class);
    clientStream.start(mockClientStreamListener);
    MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
    ServerStream serverStream = serverStreamCreation.stream;
    ServerStreamListener mockServerStreamListener = serverStreamCreation.listener;
    serverStream.close(Status.OK, new Metadata());
    verify(mockClientStreamListener, timeout(TIMEOUT_MS)).closed(any(Status.class), any(Metadata.class));
    verify(mockServerStreamListener, timeout(TIMEOUT_MS)).closed(any(Status.class));
    client.shutdown();
}
Also used : Status(io.grpc.Status) ManagedClientTransport(io.grpc.internal.ManagedClientTransport) ClientStreamListener(io.grpc.internal.ClientStreamListener) ServerStreamListener(io.grpc.internal.ServerStreamListener) Metadata(io.grpc.Metadata) ServerStream(io.grpc.internal.ServerStream) ClientStream(io.grpc.internal.ClientStream)

Aggregations

Metadata (io.grpc.Metadata)1 Status (io.grpc.Status)1 ClientStream (io.grpc.internal.ClientStream)1 ClientStreamListener (io.grpc.internal.ClientStreamListener)1 ManagedClientTransport (io.grpc.internal.ManagedClientTransport)1 ServerStream (io.grpc.internal.ServerStream)1 ServerStreamListener (io.grpc.internal.ServerStreamListener)1