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();
}
Aggregations