use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractTransportTest method openStreamPreventsTermination.
@Test
public void openStreamPreventsTermination() throws Exception {
server.start(serverListener);
int port = -1;
SocketAddress addr = server.getListenSocketAddress();
if (addr instanceof InetSocketAddress) {
port = ((InetSocketAddress) addr).getPort();
}
client = newClientTransport(server);
startTransport(client, mockClientTransportListener);
MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
serverTransport = serverTransportListener.transport;
ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions, tracers);
ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase();
clientStream.start(clientStreamListener);
verify(mockClientTransportListener, timeout(TIMEOUT_MS)).transportInUse(true);
StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
ServerStream serverStream = serverStreamCreation.stream;
ServerStreamListenerBase serverStreamListener = serverStreamCreation.listener;
client.shutdown(Status.UNAVAILABLE);
client = null;
server.shutdown();
serverTransport.shutdown();
serverTransport = null;
verify(mockClientTransportListener, timeout(TIMEOUT_MS)).transportShutdown(any(Status.class));
assertTrue(serverListener.waitForShutdown(TIMEOUT_MS, TimeUnit.MILLISECONDS));
// A new server should be able to start listening, since the current server has given up
// resources. There may be cases this is impossible in the future, but for now it is a useful
// property.
serverListener = new MockServerListener();
server = newServer(port, Arrays.asList(serverStreamTracerFactory));
server.start(serverListener);
// Try to "flush" out any listener notifications on client and server. This also ensures that
// the stream still functions.
serverStream.writeHeaders(new Metadata());
clientStream.halfClose();
assertNotNull(clientStreamListener.headers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
assertTrue(serverStreamListener.awaitHalfClosed(TIMEOUT_MS, TimeUnit.MILLISECONDS));
verify(mockClientTransportListener, never()).transportTerminated();
verify(mockClientTransportListener, never()).transportInUse(false);
assertFalse(serverTransportListener.isTerminated());
clientStream.cancel(Status.CANCELLED);
verify(mockClientTransportListener, timeout(TIMEOUT_MS)).transportTerminated();
verify(mockClientTransportListener, timeout(TIMEOUT_MS)).transportInUse(false);
assertTrue(serverTransportListener.waitForTermination(TIMEOUT_MS, TimeUnit.MILLISECONDS));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractTransportTest method transportTracer_client_streamEnded_nonOk.
@Test
public void transportTracer_client_streamEnded_nonOk() throws Exception {
server.start(serverListener);
client = newClientTransport(server);
startTransport(client, mockClientTransportListener);
ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions, tracers);
ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase();
clientStream.start(clientStreamListener);
MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
if (!haveTransportTracer()) {
return;
}
TransportStats serverBefore = getTransportStats(serverTransportListener.transport);
assertEquals(0, serverBefore.streamsFailed);
assertEquals(0, serverBefore.streamsSucceeded);
TransportStats clientBefore = getTransportStats(client);
assertEquals(0, clientBefore.streamsFailed);
assertEquals(0, clientBefore.streamsSucceeded);
clientStream.cancel(Status.UNKNOWN);
// do not validate stats until close() has been called on server
assertNotNull(serverStreamCreation.listener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
TransportStats serverAfter = getTransportStats(serverTransportListener.transport);
assertEquals(1, serverAfter.streamsFailed);
assertEquals(0, serverAfter.streamsSucceeded);
TransportStats clientAfter = getTransportStats(client);
assertEquals(1, clientAfter.streamsFailed);
assertEquals(0, clientAfter.streamsSucceeded);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractTransportTest method transportTracer_server_streamEnded_nonOk.
@Test
public void transportTracer_server_streamEnded_nonOk() throws Exception {
server.start(serverListener);
client = newClientTransport(server);
startTransport(client, mockClientTransportListener);
ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions, tracers);
ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase();
clientStream.start(clientStreamListener);
MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
ServerStream serverStream = serverStreamCreation.stream;
if (!haveTransportTracer()) {
return;
}
TransportStats serverBefore = getTransportStats(serverTransportListener.transport);
assertEquals(0, serverBefore.streamsFailed);
assertEquals(0, serverBefore.streamsSucceeded);
TransportStats clientBefore = getTransportStats(client);
assertEquals(0, clientBefore.streamsFailed);
assertEquals(0, clientBefore.streamsSucceeded);
serverStream.close(Status.UNKNOWN, new Metadata());
// do not validate stats until close() has been called on client
assertNotNull(clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
assertNotNull(clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
TransportStats serverAfter = getTransportStats(serverTransportListener.transport);
assertEquals(1, serverAfter.streamsFailed);
assertEquals(0, serverAfter.streamsSucceeded);
TransportStats clientAfter = getTransportStats(client);
assertEquals(1, clientAfter.streamsFailed);
assertEquals(0, clientAfter.streamsSucceeded);
client.shutdown(Status.UNAVAILABLE);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractTransportTest method clientChecksInboundMetadataSize_trailer.
/**
* This assumes the client limits metadata size to GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE.
*/
@Test
public void clientChecksInboundMetadataSize_trailer() throws Exception {
server.start(serverListener);
client = newClientTransport(server);
startTransport(client, mockClientTransportListener);
MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
serverTransport = serverTransportListener.transport;
Metadata.Key<String> tellTaleKey = Metadata.Key.of("tell-tale", Metadata.ASCII_STRING_MARSHALLER);
Metadata tooLargeMetadata = new Metadata();
tooLargeMetadata.put(tellTaleKey, "true");
tooLargeMetadata.put(Metadata.Key.of("foo-bin", Metadata.BINARY_BYTE_MARSHALLER), new byte[GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE]);
ClientStream clientStream = client.newStream(methodDescriptor, new Metadata(), callOptions, tracers);
ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase();
clientStream.start(clientStreamListener);
clientStream.writeMessage(methodDescriptor.streamRequest("foo"));
clientStream.halfClose();
clientStream.request(1);
StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
serverStreamCreation.stream.request(1);
serverStreamCreation.stream.writeHeaders(new Metadata());
serverStreamCreation.stream.writeMessage(methodDescriptor.streamResponse("response"));
serverStreamCreation.stream.close(Status.OK, tooLargeMetadata);
Status status = clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
List<Status.Code> codeOptions = Arrays.asList(Status.Code.UNKNOWN, Status.Code.RESOURCE_EXHAUSTED, Status.Code.INTERNAL);
if (!codeOptions.contains(status.getCode())) {
fail("Status code was not expected: " + status);
}
Metadata metadata = clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertNull(metadata.get(tellTaleKey));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grpc-java by grpc.
the class AbstractTransportTest method frameAfterRstStreamShouldNotBreakClientChannel.
// TODO(ejona):
// multiple streams on same transport
// multiple client transports to same server
// halfClose to trigger flush (client and server)
// flow control pushes back (client and server)
// flow control provides precisely number of messages requested (client and server)
// onReady called when buffer drained (on server and client)
// test no start reentrancy (esp. during failure) (transport and call)
// multiple requests/responses (verifying contents received)
// server transport shutdown triggers client shutdown (via GOAWAY)
// queued message InputStreams are closed on stream cancel
// (and maybe exceptions handled)
/**
* Test for issue https://github.com/grpc/grpc-java/issues/1682
*/
@Test
public void frameAfterRstStreamShouldNotBreakClientChannel() throws Exception {
server.start(serverListener);
client = newClientTransport(server);
startTransport(client, mockClientTransportListener);
MockServerTransportListener serverTransportListener = serverListener.takeListenerOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
serverTransport = serverTransportListener.transport;
// Try to create a sequence of frames so that the client receives a HEADERS or DATA frame
// after having sent a RST_STREAM to the server. Previously, this would have broken the
// Netty channel.
ClientStream stream = client.newStream(methodDescriptor, new Metadata(), callOptions, noopTracers);
ClientStreamListenerBase clientStreamListener = new ClientStreamListenerBase();
stream.start(clientStreamListener);
StreamCreation serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
stream.flush();
stream.writeMessage(methodDescriptor.streamRequest("foo"));
stream.flush();
stream.cancel(Status.CANCELLED);
stream.flush();
serverStreamCreation.stream.writeHeaders(new Metadata());
serverStreamCreation.stream.flush();
serverStreamCreation.stream.writeMessage(methodDescriptor.streamResponse("bar"));
serverStreamCreation.stream.flush();
assertEquals(Status.CANCELLED, clientStreamListener.status.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
assertNotNull(clientStreamListener.trailers.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
ClientStreamListener mockClientStreamListener2 = mock(ClientStreamListener.class);
// Test that the channel is still usable i.e. we can receive headers from the server on a
// new stream.
stream = client.newStream(methodDescriptor, new Metadata(), callOptions, noopTracers);
stream.start(mockClientStreamListener2);
serverStreamCreation = serverTransportListener.takeStreamOrFail(TIMEOUT_MS, TimeUnit.MILLISECONDS);
serverStreamCreation.stream.writeHeaders(new Metadata());
serverStreamCreation.stream.flush();
verify(mockClientStreamListener2, timeout(TIMEOUT_MS)).headersRead(any(Metadata.class));
}
Aggregations