Search in sources :

Example 1 with BidirectionalStream

use of org.chromium.net.BidirectionalStream in project grpc-java by grpc.

the class CronetClientTransportTest method shutdownTransport.

@Test
public void shutdownTransport() throws Exception {
    CronetClientStream stream1 = transport.newStream(descriptor, new Metadata(), CallOptions.DEFAULT, tracers);
    CronetClientStream stream2 = transport.newStream(descriptor, new Metadata(), CallOptions.DEFAULT, tracers);
    // Create a transport and start two streams on it.
    ArgumentCaptor<BidirectionalStream.Callback> callbackCaptor = ArgumentCaptor.forClass(BidirectionalStream.Callback.class);
    when(streamFactory.newBidirectionalStreamBuilder(any(String.class), callbackCaptor.capture(), any(Executor.class))).thenReturn(builder);
    BidirectionalStream cronetStream1 = mock(BidirectionalStream.class);
    when(builder.build()).thenReturn(cronetStream1);
    stream1.start(mock(ClientStreamListener.class));
    BidirectionalStream.Callback callback1 = callbackCaptor.getValue();
    BidirectionalStream cronetStream2 = mock(BidirectionalStream.class);
    when(builder.build()).thenReturn(cronetStream2);
    stream2.start(mock(ClientStreamListener.class));
    BidirectionalStream.Callback callback2 = callbackCaptor.getValue();
    // Shut down the transport. transportShutdown should be called immediately.
    transport.shutdown();
    verify(clientTransportListener).transportShutdown(any(Status.class));
    // Have two live streams. Transport has not been terminated.
    verify(clientTransportListener, times(0)).transportTerminated();
    callback1.onCanceled(cronetStream1, null);
    // Still has one live stream
    verify(clientTransportListener, times(0)).transportTerminated();
    callback2.onCanceled(cronetStream1, null);
    // All streams are gone now.
    verify(clientTransportListener, times(1)).transportTerminated();
}
Also used : Status(io.grpc.Status) Executor(java.util.concurrent.Executor) ClientStreamListener(io.grpc.internal.ClientStreamListener) Metadata(io.grpc.Metadata) BidirectionalStream(org.chromium.net.BidirectionalStream) Test(org.junit.Test)

Aggregations

Metadata (io.grpc.Metadata)1 Status (io.grpc.Status)1 ClientStreamListener (io.grpc.internal.ClientStreamListener)1 Executor (java.util.concurrent.Executor)1 BidirectionalStream (org.chromium.net.BidirectionalStream)1 Test (org.junit.Test)1