Remove Trailers

This commit is contained in:
Carl Mastrangelo 2015-08-13 14:11:55 -07:00
parent 3c924fda85
commit 572f4332a7
40 changed files with 135 additions and 142 deletions

View File

@ -134,7 +134,7 @@ public class ClientAuthInterceptorTests {
Metadata.Headers headers = new Metadata.Headers();
interceptedCall.start(listener, headers);
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
Mockito.verify(listener).onClose(statusCaptor.capture(), isA(Metadata.Trailers.class));
Mockito.verify(listener).onClose(statusCaptor.capture(), isA(Metadata.class));
Assert.assertNull(headers.getAll(AUTHORIZATION));
Mockito.verify(call, never()).start(listener, headers);
Assert.assertEquals(Status.Code.UNAUTHENTICATED, statusCaptor.getValue().getCode());

View File

@ -254,7 +254,7 @@ public abstract class AbstractBenchmark {
@Override
public void onHalfClose() {
call.close(Status.OK, new Metadata.Trailers());
call.close(Status.OK, new Metadata());
}
@Override
@ -287,7 +287,7 @@ public abstract class AbstractBenchmark {
@Override
public void onHalfClose() {
call.close(Status.OK, new Metadata.Trailers());
call.close(Status.OK, new Metadata());
}
@Override
@ -323,7 +323,7 @@ public abstract class AbstractBenchmark {
@Override
public void onHalfClose() {
call.close(Status.OK, new Metadata.Trailers());
call.close(Status.OK, new Metadata());
}
@Override

View File

@ -475,7 +475,7 @@ public final class ChannelImpl extends Channel {
@Override
public ClientStream newStream(
MethodDescriptor<?, ?> method, Headers headers, ClientStreamListener listener) {
listener.closed(shutdownStatus, new Metadata.Trailers());
listener.closed(shutdownStatus, new Metadata());
return new ClientCallImpl.NoopClientStream();
}

View File

@ -91,7 +91,7 @@ public abstract class ClientCall<RequestT, ResponseT> {
* @param status the result of the remote call.
* @param trailers metadata provided at call completion.
*/
public abstract void onClose(Status status, Metadata.Trailers trailers);
public abstract void onClose(Status status, Metadata trailers);
/**
* This indicates that the ClientCall is now capable of sending additional messages (via

View File

@ -201,7 +201,7 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
private void closeCallPrematurely(ClientStreamListener listener, Status status) {
Preconditions.checkState(stream == null, "Stream already created");
stream = new NoopClientStream();
listener.closed(status, new Metadata.Trailers());
listener.closed(status, new Metadata());
}
private ScheduledFuture<?> startDeadlineTimer(long timeoutMicros) {
@ -267,7 +267,7 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
}
@Override
public void closed(Status status, Metadata.Trailers trailers) {
public void closed(Status status, Metadata trailers) {
if (status.getCode() == Status.Code.CANCELLED && deadlineNanoTime != null) {
// When the server's deadline expires, it can only reset the stream with CANCEL and no
// description. Since our timer may be delayed in firing, we double-check the deadline and
@ -276,11 +276,11 @@ final class ClientCallImpl<ReqT, RespT> extends ClientCall<ReqT, RespT> {
if (deadlineNanoTime <= System.nanoTime()) {
status = Status.DEADLINE_EXCEEDED;
// Replace trailers to prevent mixing sources of status and trailers.
trailers = new Metadata.Trailers();
trailers = new Metadata();
}
}
final Status savedStatus = status;
final Metadata.Trailers savedTrailers = trailers;
final Metadata savedTrailers = trailers;
callExecutor.execute(new Runnable() {
@Override
public void run() {

View File

@ -164,7 +164,7 @@ public class ClientInterceptors {
// to a NO-OP one to prevent the IllegalStateException. The user will finally get notified
// about the error through the listener.
delegate = (ClientCall<ReqT, RespT>) NOOP_CALL;
responseListener.onClose(Status.fromThrowable(e), new Metadata.Trailers());
responseListener.onClose(Status.fromThrowable(e), new Metadata());
}
}
}

View File

@ -52,7 +52,7 @@ public abstract class ForwardingClientCallListener<RespT> extends ClientCall.Lis
}
@Override
public void onClose(Status status, Metadata.Trailers trailers) {
public void onClose(Status status, Metadata trailers) {
delegate().onClose(status, trailers);
}

View File

@ -61,7 +61,7 @@ public abstract class ForwardingServerCall<RespT> extends ServerCall<RespT> {
}
@Override
public void close(Status status, Metadata.Trailers trailers) {
public void close(Status status, Metadata trailers) {
delegate().close(status, trailers);
}

View File

@ -56,7 +56,7 @@ import javax.annotation.concurrent.NotThreadSafe;
* </p>
*/
@NotThreadSafe
public abstract class Metadata {
public class Metadata {
/**
* All binary headers should have this suffix in their names. Vice versa.
@ -108,7 +108,7 @@ public abstract class Metadata {
* Constructor called by the transport layer when it receives binary metadata.
*/
// TODO(louiscryan): Convert to use ByteString so we can cache transformations
private Metadata(byte[]... binaryValues) {
public Metadata(byte[]... binaryValues) {
for (int i = 0; i < binaryValues.length; i++) {
String name = new String(binaryValues[i], US_ASCII);
storeAdd(name, new MetadataEntry(name.endsWith(BINARY_HEADER_SUFFIX), binaryValues[++i]));
@ -118,7 +118,7 @@ public abstract class Metadata {
/**
* Constructor called by the application layer when it wants to send metadata.
*/
private Metadata() {}
public Metadata() {}
private void storeAdd(String name, MetadataEntry value) {
List<MetadataEntry> values = store.get(name);
@ -286,6 +286,11 @@ public abstract class Metadata {
}
}
@Override
public String toString() {
return "Metadata(" + toStringInternal() + ")";
}
private String toStringInternal() {
return store.toString();
}
@ -375,31 +380,19 @@ public abstract class Metadata {
/**
* Concrete instance for metadata attached to the end of the call. Only provided by
* servers.
*
* @deprecated use Metadata instead.
*/
@Deprecated
public static class Trailers extends Metadata {
/**
* Called by the transport layer to create trailers from their binary serialized values.
*
* <p>This method does not copy the provided byte arrays. The byte arrays must not be mutated.
*/
public Trailers(byte[]... headers) {
super(headers);
}
/**
* Called by the application layer to construct trailers prior to passing them to the
* transport for serialization.
*/
public Trailers() {
}
@Override
public String toString() {
return "Trailers(" + super.toStringInternal() + ")";
}
}
/**
* Marshaller for metadata values that are serialized into raw binary.
*/

View File

@ -149,12 +149,12 @@ public abstract class ServerCall<ResponseT> {
* status} is not equal to {@link Status#OK}, then the call is said to have failed.
*
* <p>If {@code status} is not {@link Status#CANCELLED} and no errors or cancellations are known
* to have occured, then a {@link Listener#onComplete} notification should be expected.
* to have occurred, then a {@link Listener#onComplete} notification should be expected.
* Otherwise {@link Listener#onCancel} has been or will be called.
*
* @throws IllegalStateException if call is already {@code close}d
*/
public abstract void close(Status status, Metadata.Trailers trailers);
public abstract void close(Status status, Metadata trailers);
/**
* Returns {@code true} when the call is cancelled and the server is encouraged to abort

View File

@ -308,14 +308,14 @@ public final class ServerImpl extends Server {
if (method == null) {
stream.close(
Status.UNIMPLEMENTED.withDescription("Method not found: " + methodName),
new Metadata.Trailers());
new Metadata());
timeout.cancel(true);
return;
}
listener = startCall(stream, methodName, method.getMethodDefinition(), timeout,
headers);
} catch (Throwable t) {
stream.close(Status.fromThrowable(t), new Metadata.Trailers());
stream.close(Status.fromThrowable(t), new Metadata());
timeout.cancel(true);
throw Throwables.propagate(t);
} finally {
@ -410,9 +410,9 @@ public final class ServerImpl extends Server {
}
/**
* Like {@link ServerCall#close(Status, Metadata.Trailers)}, but thread-safe for internal use.
* Like {@link ServerCall#close(Status, Metadata)}, but thread-safe for internal use.
*/
private void internalClose(Status status, Metadata.Trailers trailers) {
private void internalClose(Status status, Metadata trailers) {
// TODO(ejona86): this is not thread-safe :)
stream.close(status, trailers);
}
@ -425,7 +425,7 @@ public final class ServerImpl extends Server {
try {
getListener().messageRead(message);
} catch (Throwable t) {
internalClose(Status.fromThrowable(t), new Metadata.Trailers());
internalClose(Status.fromThrowable(t), new Metadata());
throw Throwables.propagate(t);
}
}
@ -440,7 +440,7 @@ public final class ServerImpl extends Server {
try {
getListener().halfClosed();
} catch (Throwable t) {
internalClose(Status.fromThrowable(t), new Metadata.Trailers());
internalClose(Status.fromThrowable(t), new Metadata());
throw Throwables.propagate(t);
}
}
@ -504,7 +504,7 @@ public final class ServerImpl extends Server {
stream.writeMessage(resp);
stream.flush();
} catch (Throwable t) {
close(Status.fromThrowable(t), new Metadata.Trailers());
close(Status.fromThrowable(t), new Metadata());
throw Throwables.propagate(t);
}
}
@ -515,7 +515,7 @@ public final class ServerImpl extends Server {
}
@Override
public void close(Status status, Metadata.Trailers trailers) {
public void close(Status status, Metadata trailers) {
Preconditions.checkState(!closeCalled, "call already closed");
closeCalled = true;
stream.close(status, trailers);

View File

@ -107,7 +107,7 @@ class InProcessTransport implements ServerTransport, ClientTransport {
public synchronized ClientStream newStream(MethodDescriptor<?, ?> method,
Metadata.Headers headers, ClientStreamListener clientStreamListener) {
if (shutdownStatus != null) {
clientStreamListener.closed(shutdownStatus, new Metadata.Trailers());
clientStreamListener.closed(shutdownStatus, new Metadata());
return new NoopClientStream();
}
InProcessStream stream = new InProcessStream();
@ -195,7 +195,7 @@ class InProcessTransport implements ServerTransport, ClientTransport {
@GuardedBy("this")
private Status clientNotifyStatus;
@GuardedBy("this")
private Metadata.Trailers clientNotifyTrailers;
private Metadata clientNotifyTrailers;
// Only is intended to prevent double-close when client cancels.
@GuardedBy("this")
private boolean closed;
@ -266,7 +266,7 @@ class InProcessTransport implements ServerTransport, ClientTransport {
}
@Override
public void close(Status status, Metadata.Trailers trailers) {
public void close(Status status, Metadata trailers) {
synchronized (this) {
if (closed) {
return;
@ -306,7 +306,7 @@ class InProcessTransport implements ServerTransport, ClientTransport {
log.log(Level.WARNING, "Exception closing stream", t);
}
}
clientStreamListener.closed(status, new Metadata.Trailers());
clientStreamListener.closed(status, new Metadata());
return true;
}
}

View File

@ -59,7 +59,7 @@ public abstract class AbstractClientStream<IdT> extends AbstractStream<IdT>
// Stored status & trailers to report when deframer completes or
// transportReportStatus is directly called.
private Status status;
private Metadata.Trailers trailers;
private Metadata trailers;
private Runnable closeListenerTask;
@ -100,7 +100,7 @@ public abstract class AbstractClientStream<IdT> extends AbstractStream<IdT>
}
// For transport errors we immediately report status to the application layer
// and do not wait for additional payloads.
transportReportStatus(errorStatus, false, new Metadata.Trailers());
transportReportStatus(errorStatus, false, new Metadata());
}
/**
@ -165,7 +165,7 @@ public abstract class AbstractClientStream<IdT> extends AbstractStream<IdT>
* @param trailers the received trailers
* @param status the status extracted from the trailers
*/
protected void inboundTrailersReceived(Metadata.Trailers trailers, Status status) {
protected void inboundTrailersReceived(Metadata trailers, Status status) {
Preconditions.checkNotNull(trailers, "trailers");
if (inboundPhase() == Phase.STATUS) {
log.log(Level.INFO, "Received trailers on closed stream {0}\n {1}\n {2}",
@ -212,7 +212,7 @@ public abstract class AbstractClientStream<IdT> extends AbstractStream<IdT>
* @param trailers new instance of {@code Trailers}, either empty or those returned by the server
*/
public void transportReportStatus(final Status newStatus, boolean stopDelivery,
final Metadata.Trailers trailers) {
final Metadata trailers) {
Preconditions.checkNotNull(newStatus, "newStatus");
boolean closingLater = closeListenerTask != null && !stopDelivery;
@ -240,7 +240,7 @@ public abstract class AbstractClientStream<IdT> extends AbstractStream<IdT>
/**
* Creates a new {@link Runnable} to close the listener with the given status/trailers.
*/
private Runnable newCloseListenerTask(final Status status, final Metadata.Trailers trailers) {
private Runnable newCloseListenerTask(final Status status, final Metadata trailers) {
return new Runnable() {
@Override
public void run() {
@ -252,7 +252,7 @@ public abstract class AbstractClientStream<IdT> extends AbstractStream<IdT>
/**
* Closes the listener if not previously closed.
*/
private void closeListener(Status newStatus, Metadata.Trailers trailers) {
private void closeListener(Status newStatus, Metadata trailers) {
if (!listenerClosed) {
listenerClosed = true;
closeDeframer();

View File

@ -61,7 +61,7 @@ public abstract class AbstractServerStream<IdT> extends AbstractStream<IdT>
*/
private boolean gracefulClose;
/** Saved trailers from close() that need to be sent once the framer has sent all messages. */
private Metadata.Trailers stashedTrailers;
private Metadata stashedTrailers;
protected AbstractServerStream(WritableBufferAllocator bufferAllocator) {
super(bufferAllocator);
@ -109,7 +109,7 @@ public abstract class AbstractServerStream<IdT> extends AbstractStream<IdT>
}
@Override
public final void close(Status status, Metadata.Trailers trailers) {
public final void close(Status status, Metadata trailers) {
Preconditions.checkNotNull(status, "status");
Preconditions.checkNotNull(trailers, "trailers");
if (outboundPhase(Phase.STATUS) != Phase.STATUS) {
@ -187,7 +187,7 @@ public abstract class AbstractServerStream<IdT> extends AbstractStream<IdT>
* @param trailers metadata to be sent to end point
* @param headersSent {@code true} if response headers have already been sent.
*/
protected abstract void sendTrailers(Metadata.Trailers trailers, boolean headersSent);
protected abstract void sendTrailers(Metadata trailers, boolean headersSent);
/**
* Indicates the stream is considered completely closed and there is no further opportunity for
@ -216,7 +216,7 @@ public abstract class AbstractServerStream<IdT> extends AbstractStream<IdT>
* Aborts the stream with an error status, cleans up resources and notifies the listener if
* necessary.
*
* <p>Unlike {@link #close(Status, Metadata.Trailers)}, this method is only called from the
* <p>Unlike {@link #close(Status, Metadata)}, this method is only called from the
* transport. The transport should use this method instead of {@code close(Status)} for internal
* errors to prevent exposing unexpected states and exceptions to the application.
*
@ -232,7 +232,7 @@ public abstract class AbstractServerStream<IdT> extends AbstractStream<IdT>
if (notifyClient) {
// TODO(louiscryan): Remove
if (stashedTrailers == null) {
stashedTrailers = new Metadata.Trailers();
stashedTrailers = new Metadata();
}
writeStatusToTrailers(status);
closeFramer();

View File

@ -40,7 +40,7 @@ public interface ClientStreamListener extends StreamListener {
* Called upon receiving all header information from the remote end-point. Note that transports
* are not required to call this method if no header information is received, this would occur
* when a stream immediately terminates with an error and only
* {@link #closed(io.grpc.Status, Metadata.Trailers)} is called.
* {@link #closed(io.grpc.Status, Metadata)} is called.
*
* <p>This method should return quickly, as the same thread may be used to process other streams.
*
@ -60,5 +60,5 @@ public interface ClientStreamListener extends StreamListener {
* @param status details about the remote closure
* @param trailers trailing metadata
*/
void closed(Status status, Metadata.Trailers trailers);
void closed(Status status, Metadata trailers);
}

View File

@ -145,7 +145,7 @@ public abstract class Http2ClientStream extends AbstractClientStream<Integer> {
*
* @param trailers the received terminal trailer metadata
*/
protected void transportTrailersReceived(Metadata.Trailers trailers) {
protected void transportTrailersReceived(Metadata trailers) {
Preconditions.checkNotNull(trailers);
if (transportError != null) {
// Already received a transport error so just augment it.
@ -176,7 +176,7 @@ public abstract class Http2ClientStream extends AbstractClientStream<Integer> {
/**
* Extract the response status from trailers.
*/
private Status statusFromTrailers(Metadata.Trailers trailers) {
private Status statusFromTrailers(Metadata trailers) {
Status status = trailers.get(Status.CODE_KEY);
if (status == null) {
status = statusFromHttpStatus(trailers);

View File

@ -58,7 +58,7 @@ public interface ServerStream extends Stream {
* @param status details of the closure
* @param trailers an additional block of metadata to pass to the client on stream closure.
*/
void close(Status status, Metadata.Trailers trailers);
void close(Status status, Metadata trailers);
/**

View File

@ -137,7 +137,7 @@ public class ChannelImplTest {
channel.newCall(method, CallOptions.DEFAULT.withDeadlineNanoTime(System.nanoTime()));
call.start(mockCallListener, new Metadata.Headers());
verify(mockCallListener, timeout(1000)).onClose(
same(Status.DEADLINE_EXCEEDED), any(Metadata.Trailers.class));
same(Status.DEADLINE_EXCEEDED), any(Metadata.class));
}
@Test
@ -179,7 +179,7 @@ public class ChannelImplTest {
verify(mockTransport)
.newStream(same(method), same(headers2), streamListenerCaptor.capture());
ClientStreamListener streamListener2 = streamListenerCaptor.getValue();
Metadata.Trailers trailers = new Metadata.Trailers();
Metadata trailers = new Metadata();
streamListener2.closed(Status.CANCELLED, trailers);
verify(mockCallListener2, timeout(1000)).onClose(Status.CANCELLED, trailers);
@ -194,7 +194,7 @@ public class ChannelImplTest {
call3.start(mockCallListener3, new Metadata.Headers());
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(mockCallListener3, timeout(1000))
.onClose(statusCaptor.capture(), any(Metadata.Trailers.class));
.onClose(statusCaptor.capture(), any(Metadata.class));
assertSame(Status.Code.UNAVAILABLE, statusCaptor.getValue().getCode());
// Finish shutdown
@ -227,7 +227,7 @@ public class ChannelImplTest {
verify(mockTransport).start(any(ClientTransport.Listener.class));
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
verify(mockCallListener, timeout(1000))
.onClose(statusCaptor.capture(), any(Metadata.Trailers.class));
.onClose(statusCaptor.capture(), any(Metadata.class));
assertSame(goldenStatus, statusCaptor.getValue());
// Have transport shutdown immediately during start
@ -251,7 +251,7 @@ public class ChannelImplTest {
verify(mockTransportFactory, times(2)).newClientTransport();
verify(mockTransport2).start(any(ClientTransport.Listener.class));
verify(mockTransport2).newStream(same(method), same(headers2), streamListenerCaptor.capture());
Metadata.Trailers trailers2 = new Metadata.Trailers();
Metadata trailers2 = new Metadata();
streamListenerCaptor.getValue().closed(Status.CANCELLED, trailers2);
verify(mockCallListener2, timeout(1000)).onClose(Status.CANCELLED, trailers2);
@ -267,7 +267,7 @@ public class ChannelImplTest {
verify(mockTransportFactory, times(3)).newClientTransport();
verify(mockTransport3).start(transportListenerCaptor.capture());
verify(mockTransport3).newStream(same(method), same(headers3), streamListenerCaptor.capture());
Metadata.Trailers trailers3 = new Metadata.Trailers();
Metadata trailers3 = new Metadata();
streamListenerCaptor.getValue().closed(Status.CANCELLED, trailers3);
verify(mockCallListener3, timeout(1000)).onClose(Status.CANCELLED, trailers3);

View File

@ -347,7 +347,7 @@ public class ClientInterceptorsTest {
interceptedCall.request(1);
verifyNoMoreInteractions(call);
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
verify(listener).onClose(captor.capture(), any(Metadata.Trailers.class));
verify(listener).onClose(captor.capture(), any(Metadata.class));
assertSame(error, captor.getValue().getCause());
}

View File

@ -203,13 +203,13 @@ public class MetadataTest {
assertEquals("Headers(path=/path,authority=myauthority,"
+ "metadata={test-bin=[Fish(binary)], test=[ascii]})", h.toString());
Metadata.Trailers t = new Metadata.Trailers();
Metadata t = new Metadata();
t.put(Metadata.Key.of("test", Metadata.ASCII_STRING_MARSHALLER), "ascii");
assertEquals("Trailers({test=[ascii]})", t.toString());
assertEquals("Metadata({test=[ascii]})", t.toString());
t = new Metadata.Trailers("test".getBytes(US_ASCII), "ascii".getBytes(US_ASCII),
t = new Metadata("test".getBytes(US_ASCII), "ascii".getBytes(US_ASCII),
"test-bin".getBytes(US_ASCII), "binary".getBytes(US_ASCII));
assertEquals("Trailers({test=[ascii], test-bin=[[98, 105, 110, 97, 114, 121]]})", t.toString());
assertEquals("Metadata({test=[ascii], test-bin=[[98, 105, 110, 97, 114, 121]]})", t.toString());
}
@Test

View File

@ -227,7 +227,7 @@ public class ServerImplTest {
verify(stream, times(2)).flush();
assertEquals(50, INTEGER_MARSHALLER.parse(inputCaptor.getValue()).intValue());
Metadata.Trailers trailers = new Metadata.Trailers();
Metadata trailers = new Metadata();
trailers.put(metadataKey, 3);
Status status = Status.OK.withDescription("A okay");
call.close(status, trailers);
@ -268,7 +268,7 @@ public class ServerImplTest {
barrier.await();
executeBarrier(executor).await();
verify(stream).close(same(status), notNull(Metadata.Trailers.class));
verify(stream).close(same(status), notNull(Metadata.class));
verifyNoMoreInteractions(stream);
}

View File

@ -78,7 +78,7 @@ public class HeaderServerInterceptor implements ServerInterceptor {
}
@Override
public void close(Status status, Metadata.Trailers trailers) {
public void close(Status status, Metadata trailers) {
super.close(status, trailers);
}
}, requestHeaders);

View File

@ -456,7 +456,7 @@ public abstract class AbstractTransportTest {
}
@Override
public void onClose(Status status, Metadata.Trailers trailers) {
public void onClose(Status status, Metadata trailers) {
queue.add(status);
}
}, new Metadata.Headers());
@ -527,7 +527,7 @@ public abstract class AbstractTransportTest {
fixedHeaders.put(METADATA_KEY, contextValue);
stub = MetadataUtils.attachHeaders(stub, fixedHeaders);
// .. and expect it to be echoed back in trailers
AtomicReference<Metadata.Trailers> trailersCapture = new AtomicReference<Metadata.Trailers>();
AtomicReference<Metadata> trailersCapture = new AtomicReference<Metadata>();
AtomicReference<Metadata.Headers> headersCapture = new AtomicReference<Metadata.Headers>();
stub = MetadataUtils.captureMetadata(stub, headersCapture, trailersCapture);
@ -550,7 +550,7 @@ public abstract class AbstractTransportTest {
fixedHeaders.put(METADATA_KEY, contextValue);
stub = MetadataUtils.attachHeaders(stub, fixedHeaders);
// .. and expect it to be echoed back in trailers
AtomicReference<Metadata.Trailers> trailersCapture = new AtomicReference<Metadata.Trailers>();
AtomicReference<Metadata> trailersCapture = new AtomicReference<Metadata>();
AtomicReference<Metadata.Headers> headersCapture = new AtomicReference<Metadata.Headers>();
stub = MetadataUtils.captureMetadata(stub, headersCapture, trailersCapture);

View File

@ -216,7 +216,7 @@ class NettyClientHandler extends Http2ConnectionHandler {
private void onRstStreamRead(int streamId, long errorCode) throws Http2Exception {
NettyClientStream stream = clientStream(requireHttp2Stream(streamId));
Status status = HttpUtil.Http2Error.statusForCode((int) errorCode);
stream.transportReportStatus(status, false, new Metadata.Trailers());
stream.transportReportStatus(status, false, new Metadata());
}
@Override
@ -238,7 +238,7 @@ class NettyClientHandler extends Http2ConnectionHandler {
connection().forEachActiveStream(new Http2StreamVisitor() {
@Override
public boolean visit(Http2Stream stream) throws Http2Exception {
clientStream(stream).transportReportStatus(goAwayStatus, false, new Metadata.Trailers());
clientStream(stream).transportReportStatus(goAwayStatus, false, new Metadata());
return true;
}
});
@ -274,7 +274,7 @@ class NettyClientHandler extends Http2ConnectionHandler {
Http2Stream stream = connection().stream(http2Ex.streamId());
if (stream != null) {
clientStream(stream).transportReportStatus(Status.fromThrowable(cause), false,
new Metadata.Trailers());
new Metadata());
}
// Delegate to the base class to send a RST_STREAM.
@ -315,10 +315,10 @@ class NettyClientHandler extends Http2ConnectionHandler {
if (future.cause() instanceof GoAwayClosedStreamException) {
GoAwayClosedStreamException e = (GoAwayClosedStreamException) future.cause();
goAwayStatus(statusFromGoAway(e.errorCode(), e.debugData()));
stream.transportReportStatus(goAwayStatus, false, new Metadata.Trailers());
stream.transportReportStatus(goAwayStatus, false, new Metadata());
} else {
stream.transportReportStatus(Status.fromThrowable(future.cause()), true,
new Metadata.Trailers());
new Metadata());
}
}
}
@ -331,7 +331,7 @@ class NettyClientHandler extends Http2ConnectionHandler {
private void cancelStream(ChannelHandlerContext ctx, CancelClientStreamCommand cmd,
ChannelPromise promise) {
NettyClientStream stream = cmd.stream();
stream.transportReportStatus(cmd.reason(), true, new Metadata.Trailers());
stream.transportReportStatus(cmd.reason(), true, new Metadata());
encoder().writeRstStream(ctx, stream.id(), Http2Error.CANCEL.code(), promise);
}
@ -402,7 +402,7 @@ class NettyClientHandler extends Http2ConnectionHandler {
public boolean visit(Http2Stream stream) throws Http2Exception {
if (stream.id() > lastKnownStream) {
clientStream(stream)
.transportReportStatus(goAwayStatus, false, new Metadata.Trailers());
.transportReportStatus(goAwayStatus, false, new Metadata());
stream.close();
}
return true;

View File

@ -139,7 +139,7 @@ class NettyClientTransport implements ClientTransport {
if (!future.isSuccess()) {
// Stream creation failed. Close the stream if not already closed.
stream.transportReportStatus(Status.fromThrowable(future.cause()), true,
new Metadata.Trailers());
new Metadata());
}
}
};

View File

@ -112,7 +112,7 @@ class NettyServerStream extends AbstractServerStream<Integer> {
}
@Override
protected void sendTrailers(Metadata.Trailers trailers, boolean headersSent) {
protected void sendTrailers(Metadata trailers, boolean headersSent) {
Http2Headers http2Trailers = Utils.convertTrailers(trailers, headersSent);
writeQueue.enqueue(new SendResponseHeadersCommand(id(), http2Trailers, true), true);
}

View File

@ -142,11 +142,11 @@ class Utils {
return http2Headers;
}
public static Metadata.Trailers convertTrailers(Http2Headers http2Headers) {
return new Metadata.Trailers(convertHeadersToArray(http2Headers));
public static Metadata convertTrailers(Http2Headers http2Headers) {
return new Metadata(convertHeadersToArray(http2Headers));
}
public static Http2Headers convertTrailers(Metadata.Trailers trailers, boolean headersSent) {
public static Http2Headers convertTrailers(Metadata trailers, boolean headersSent) {
Http2Headers http2Trailers = convertMetadata(trailers);
if (!headersSent) {
http2Trailers.set(Utils.CONTENT_TYPE_HEADER, Utils.CONTENT_TYPE_GRPC);

View File

@ -183,7 +183,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase {
assertTrue(createPromise.isSuccess());
verify(stream).transportReportStatus(eq(Status.CANCELLED), eq(true),
any(Metadata.Trailers.class));
any(Metadata.class));
}
@Test
@ -341,7 +341,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase {
assertTrue(promise.isDone());
assertFalse(promise.isSuccess());
verify(stream).transportReportStatus(any(Status.class), eq(false),
notNull(Metadata.Trailers.class));
notNull(Metadata.class));
}
@Test
@ -353,7 +353,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase {
goAwayFrame(0, 8 /* Cancel */, Unpooled.copiedBuffer("this is a test", UTF_8)));
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
verify(stream).transportReportStatus(captor.capture(), eq(false),
notNull(Metadata.Trailers.class));
notNull(Metadata.class));
assertEquals(Status.CANCELLED.getCode(), captor.getValue().getCode());
assertEquals("HTTP/2 error code: CANCEL\nthis is a test",
captor.getValue().getDescription());
@ -371,7 +371,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase {
goAwayFrame(0, 8 /* Cancel */, Unpooled.copiedBuffer("this is a test", UTF_8)));
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
verify(stream).transportReportStatus(captor.capture(), eq(false),
notNull(Metadata.Trailers.class));
notNull(Metadata.class));
assertEquals(Status.CANCELLED.getCode(), captor.getValue().getCode());
assertEquals("HTTP/2 error code: CANCEL\nthis is a test",
captor.getValue().getDescription());
@ -385,7 +385,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase {
when(stream.id()).thenReturn(3);
writeQueue.enqueue(new CancelClientStreamCommand(stream, Status.CANCELLED), true);
verify(stream).transportReportStatus(eq(Status.CANCELLED), eq(true),
any(Metadata.Trailers.class));
any(Metadata.class));
}
@Test
@ -406,7 +406,7 @@ public class NettyClientHandlerTest extends NettyHandlerTestBase {
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
InOrder inOrder = inOrder(stream);
inOrder.verify(stream, calls(1)).transportReportStatus(captor.capture(), eq(false),
notNull(Metadata.Trailers.class));
notNull(Metadata.class));
assertEquals(Status.UNAVAILABLE.getCode(), captor.getValue().getCode());
}

View File

@ -160,35 +160,35 @@ public class NettyClientStreamTest extends NettyStreamTestBase {
@Test
public void setStatusWithOkShouldCloseStream() {
stream().id(STREAM_ID);
stream().transportReportStatus(Status.OK, true, new Metadata.Trailers());
verify(listener).closed(same(Status.OK), any(Metadata.Trailers.class));
stream().transportReportStatus(Status.OK, true, new Metadata());
verify(listener).closed(same(Status.OK), any(Metadata.class));
assertTrue(stream.isClosed());
}
@Test
public void setStatusWithErrorShouldCloseStream() {
Status errorStatus = Status.INTERNAL;
stream().transportReportStatus(errorStatus, true, new Metadata.Trailers());
verify(listener).closed(eq(errorStatus), any(Metadata.Trailers.class));
stream().transportReportStatus(errorStatus, true, new Metadata());
verify(listener).closed(eq(errorStatus), any(Metadata.class));
assertTrue(stream.isClosed());
}
@Test
public void setStatusWithOkShouldNotOverrideError() {
Status errorStatus = Status.INTERNAL;
stream().transportReportStatus(errorStatus, true, new Metadata.Trailers());
stream().transportReportStatus(Status.OK, true, new Metadata.Trailers());
verify(listener).closed(any(Status.class), any(Metadata.Trailers.class));
stream().transportReportStatus(errorStatus, true, new Metadata());
stream().transportReportStatus(Status.OK, true, new Metadata());
verify(listener).closed(any(Status.class), any(Metadata.class));
assertTrue(stream.isClosed());
}
@Test
public void setStatusWithErrorShouldNotOverridePreviousError() {
Status errorStatus = Status.INTERNAL;
stream().transportReportStatus(errorStatus, true, new Metadata.Trailers());
stream().transportReportStatus(errorStatus, true, new Metadata());
stream().transportReportStatus(Status.fromThrowable(new RuntimeException("fake")), true,
new Metadata.Trailers());
verify(listener).closed(any(Status.class), any(Metadata.Trailers.class));
new Metadata());
verify(listener).closed(any(Status.class), any(Metadata.class));
assertTrue(stream.isClosed());
}
@ -226,7 +226,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase {
stream().transportHeadersReceived(grpcResponseTrailers(Status.INTERNAL), true);
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
verify(listener).closed(captor.capture(), any(Metadata.Trailers.class));
verify(listener).closed(captor.capture(), any(Metadata.class));
assertEquals(Status.INTERNAL.getCode(), captor.getValue().getCode());
assertTrue(stream.isClosed());
}
@ -239,7 +239,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase {
// Remove once b/16290036 is fixed.
headers.status(new AsciiString("500"));
stream().transportHeadersReceived(headers, false);
verify(listener, never()).closed(any(Status.class), any(Metadata.Trailers.class));
verify(listener, never()).closed(any(Status.class), any(Metadata.class));
// We are now waiting for 100 bytes of error context on the stream, cancel has not yet been
// sent
@ -251,7 +251,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase {
// Now verify that cancel is sent and an error is reported to the listener
verify(writeQueue).enqueue(any(CancelClientStreamCommand.class), eq(true));
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
verify(listener).closed(captor.capture(), any(Metadata.Trailers.class));
verify(listener).closed(captor.capture(), any(Metadata.class));
assertEquals(Status.UNKNOWN.getCode(), captor.getValue().getCode());
assertTrue(stream.isClosed());
@ -261,7 +261,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase {
public void nonGrpcResponseShouldSetStatus() throws Exception {
stream().transportDataReceived(Unpooled.copiedBuffer(MESSAGE, UTF_8), true);
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
verify(listener).closed(captor.capture(), any(Metadata.Trailers.class));
verify(listener).closed(captor.capture(), any(Metadata.class));
assertEquals(Status.Code.INTERNAL, captor.getValue().getCode());
}
@ -288,7 +288,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase {
verify(listener).messageRead(any(InputStream.class));
// Now set the error status.
Metadata.Trailers trailers = Utils.convertTrailers(grpcResponseTrailers(Status.CANCELLED));
Metadata trailers = Utils.convertTrailers(grpcResponseTrailers(Status.CANCELLED));
stream().transportReportStatus(Status.CANCELLED, true, trailers);
// Now allow the delivery of the second.
@ -314,7 +314,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase {
verify(listener).messageRead(any(InputStream.class));
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
verify(listener).closed(captor.capture(), any(Metadata.Trailers.class));
verify(listener).closed(captor.capture(), any(Metadata.class));
assertEquals(Status.Code.INTERNAL, captor.getValue().getCode());
}
@ -372,7 +372,7 @@ public class NettyClientStreamTest extends NettyStreamTestBase {
}
private Http2Headers grpcResponseTrailers(Status status) {
Metadata.Trailers trailers = new Metadata.Trailers();
Metadata trailers = new Metadata();
trailers.put(Status.CODE_KEY, status);
return Utils.convertTrailers(trailers, true);
}

View File

@ -282,7 +282,7 @@ public class NettyClientTransportTest {
}
@Override
public void closed(Status status, Metadata.Trailers trailers) {
public void closed(Status status, Metadata trailers) {
if (status.isOk()) {
closedFuture.set(null);
} else {
@ -328,7 +328,7 @@ public class NettyClientTransportTest {
@Override
public void halfClosed() {
// Just close when the client closes.
stream.close(Status.OK, new Metadata.Trailers());
stream.close(Status.OK, new Metadata());
}
@Override

View File

@ -76,7 +76,7 @@ public class NettyServerStreamTest extends NettyStreamTestBase {
@Mock
private NettyServerHandler handler;
private Metadata.Trailers trailers = new Metadata.Trailers();
private Metadata trailers = new Metadata();
@Before
@Override
@ -126,7 +126,7 @@ public class NettyServerStreamTest extends NettyStreamTestBase {
@Test
public void closeBeforeClientHalfCloseShouldSucceed() throws Exception {
stream().close(Status.OK, new Metadata.Trailers());
stream().close(Status.OK, new Metadata());
verify(writeQueue).enqueue(
new SendResponseHeadersCommand(STREAM_ID, new DefaultHttp2Headers()
.status(new AsciiString("200"))
@ -224,7 +224,7 @@ public class NettyServerStreamTest extends NettyStreamTestBase {
@Test
public void emptyFramerShouldSendNoPayload() throws Exception {
stream().close(Status.OK, new Metadata.Trailers());
stream().close(Status.OK, new Metadata());
verify(writeQueue).enqueue(
new SendResponseHeadersCommand(STREAM_ID, new DefaultHttp2Headers()
.status(new AsciiString("200"))
@ -265,7 +265,7 @@ public class NettyServerStreamTest extends NettyStreamTestBase {
@Override
protected void closeStream() {
stream().close(Status.ABORTED, new Metadata.Trailers());
stream().close(Status.ABORTED, new Metadata());
}
@Override

View File

@ -245,7 +245,7 @@ class OkHttpClientStream extends Http2ClientStream {
data.buffer.clear();
}
pendingData = null;
transportReportStatus(reason, true, new Metadata.Trailers());
transportReportStatus(reason, true, new Metadata());
} else {
transport.finishStream(id(), reason, ErrorCode.CANCEL);
}

View File

@ -254,7 +254,7 @@ class OkHttpClientTransport implements ClientTransport {
synchronized (lock) {
if (goAway) {
clientStream.transportReportStatus(goAwayStatus, true, new Metadata.Trailers());
clientStream.transportReportStatus(goAwayStatus, true, new Metadata());
} else if (streams.size() >= maxConcurrentStreams) {
pendingStreams.add(clientStream);
} else {
@ -459,12 +459,12 @@ class OkHttpClientTransport implements ClientTransport {
Map.Entry<Integer, OkHttpClientStream> entry = it.next();
if (entry.getKey() > lastKnownStreamId) {
it.remove();
entry.getValue().transportReportStatus(status, false, new Metadata.Trailers());
entry.getValue().transportReportStatus(status, false, new Metadata());
}
}
for (OkHttpClientStream stream : pendingStreams) {
stream.transportReportStatus(status, true, new Metadata.Trailers());
stream.transportReportStatus(status, true, new Metadata());
}
pendingStreams.clear();
}
@ -501,7 +501,7 @@ class OkHttpClientTransport implements ClientTransport {
if (status != null) {
boolean isCancelled = (status.getCode() == Code.CANCELLED
|| status.getCode() == Code.DEADLINE_EXCEEDED);
stream.transportReportStatus(status, isCancelled, new Metadata.Trailers());
stream.transportReportStatus(status, isCancelled, new Metadata());
}
if (!startPendingStreams()) {
stopIfNecessary();

View File

@ -49,8 +49,8 @@ class Utils {
return new Metadata.Headers(convertHeadersToArray(http2Headers));
}
public static Metadata.Trailers convertTrailers(List<Header> http2Headers) {
return new Metadata.Trailers(convertHeadersToArray(http2Headers));
public static Metadata convertTrailers(List<Header> http2Headers) {
return new Metadata(convertHeadersToArray(http2Headers));
}
private static byte[][] convertHeadersToArray(List<Header> http2Headers) {

View File

@ -1254,7 +1254,7 @@ public class OkHttpClientTransportTest {
private static class MockStreamListener implements ClientStreamListener {
Status status;
Metadata.Headers headers;
Metadata.Trailers trailers;
Metadata trailers;
CountDownLatch closed = new CountDownLatch(1);
ArrayList<String> messages = new ArrayList<String>();
boolean onReadyCalled;
@ -1276,7 +1276,7 @@ public class OkHttpClientTransportTest {
}
@Override
public void closed(Status status, Metadata.Trailers trailers) {
public void closed(Status status, Metadata trailers) {
this.status = status;
this.trailers = trailers;
closed.countDown();

View File

@ -257,7 +257,7 @@ public class ClientCalls {
}
@Override
public void onClose(Status status, Metadata.Trailers trailers) {
public void onClose(Status status, Metadata trailers) {
if (status.isOk()) {
observer.onCompleted();
} else {
@ -291,7 +291,7 @@ public class ClientCalls {
}
@Override
public void onClose(Status status, Metadata.Trailers trailers) {
public void onClose(Status status, Metadata trailers) {
if (status.isOk()) {
if (value == null) {
// No value received so mark the future as an error
@ -403,7 +403,7 @@ public class ClientCalls {
}
@Override
public void onClose(Status status, Metadata.Trailers trailers) {
public void onClose(Status status, Metadata trailers) {
Preconditions.checkState(!done, "ClientCall already closed");
if (status.isOk()) {
buffer.add(BlockingResponseStream.this);

View File

@ -98,7 +98,7 @@ public class MetadataUtils {
public static <T extends AbstractStub> T captureMetadata(
T stub,
AtomicReference<Metadata.Headers> headersCapture,
AtomicReference<Metadata.Trailers> trailersCapture) {
AtomicReference<Metadata> trailersCapture) {
return (T) stub.withInterceptors(
newCaptureMetadataInterceptor(headersCapture, trailersCapture));
}
@ -112,7 +112,7 @@ public class MetadataUtils {
*/
public static ClientInterceptor newCaptureMetadataInterceptor(
final AtomicReference<Metadata.Headers> headersCapture,
final AtomicReference<Metadata.Trailers> trailersCapture) {
final AtomicReference<Metadata> trailersCapture) {
return new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
@ -132,7 +132,7 @@ public class MetadataUtils {
}
@Override
public void onClose(Status status, Metadata.Trailers trailers) {
public void onClose(Status status, Metadata trailers) {
trailersCapture.set(trailers);
super.onClose(status, trailers);
}

View File

@ -142,7 +142,7 @@ public class ServerCalls {
call.close(
Status.INVALID_ARGUMENT.withDescription(
"More than one request messages for unary call or server streaming call"),
new Metadata.Trailers());
new Metadata());
}
}
@ -152,7 +152,7 @@ public class ServerCalls {
method.invoke(request, responseObserver);
} else {
call.close(Status.INVALID_ARGUMENT.withDescription("Half-closed without a request"),
new Metadata.Trailers());
new Metadata());
}
}
@ -239,7 +239,7 @@ public class ServerCalls {
@Override
public void onError(Throwable t) {
call.close(Status.fromThrowable(t), new Metadata.Trailers());
call.close(Status.fromThrowable(t), new Metadata());
}
@Override
@ -247,7 +247,7 @@ public class ServerCalls {
if (cancelled) {
throw Status.CANCELLED.asRuntimeException();
} else {
call.close(Status.OK, new Metadata.Trailers());
call.close(Status.OK, new Metadata());
}
}
}

View File

@ -74,7 +74,7 @@ public class ClientCallsTest {
verify(call).sendMessage(req);
verify(call).halfClose();
listener.onMessage("bar");
listener.onClose(Status.OK, new Metadata.Trailers());
listener.onClose(Status.OK, new Metadata());
assertEquals("bar", future.get());
}
@ -84,7 +84,7 @@ public class ClientCallsTest {
ArgumentCaptor<ClientCall.Listener<String>> listenerCaptor = ArgumentCaptor.forClass(null);
verify(call).start(listenerCaptor.capture(), any(Metadata.Headers.class));
ClientCall.Listener<String> listener = listenerCaptor.getValue();
listener.onClose(Status.INVALID_ARGUMENT, new Metadata.Trailers());
listener.onClose(Status.INVALID_ARGUMENT, new Metadata());
try {
future.get();
fail("Should fail");
@ -103,7 +103,7 @@ public class ClientCallsTest {
future.cancel(true);
verify(call).cancel();
listener.onMessage("bar");
listener.onClose(Status.OK, new Metadata.Trailers());
listener.onClose(Status.OK, new Metadata());
try {
future.get();
fail("Should fail");

View File

@ -106,7 +106,7 @@ public class TestUtils {
}
@Override
public void close(Status status, Metadata.Trailers trailers) {
public void close(Status status, Metadata trailers) {
trailers.merge(requestHeaders, keySet);
super.close(status, trailers);
}