mirror of https://github.com/grpc/grpc-java.git
core: forward toString for forwarding classes
Forward `toString()` method for forwarding classes to improve debug information.
For example, `ForwardingManagedChannel.toString()` will return something like:
```
ForwardingManagedChannel{delegate=ManagedChannelImpl{logId=tag-13247, target=localhost:8080}}
```
This commit is contained in:
parent
f754bff906
commit
f6a032d6b2
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.grpc;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -219,6 +220,11 @@ public abstract class ForwardingChannelBuilder<T extends ForwardingChannelBuilde
|
|||
return delegate().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the correctly typed version of the builder.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.grpc;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
|
|
@ -57,4 +58,9 @@ abstract class PartialForwardingClientCall<ReqT, RespT> extends ClientCall<ReqT,
|
|||
public Attributes getAttributes() {
|
||||
return delegate().getAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package io.grpc;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
/**
|
||||
* A {@link ClientCall.Listener} which forwards all of its methods to another {@link
|
||||
* ClientCall.Listener} which may have a different parameterized type than the
|
||||
|
|
@ -41,4 +43,9 @@ abstract class PartialForwardingClientCallListener<RespT> extends ClientCall.Lis
|
|||
public void onReady() {
|
||||
delegate().onReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package io.grpc;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
/**
|
||||
* A {@link ServerCall} which forwards all of it's methods to another {@link ServerCall} which
|
||||
* may have a different onMessage() message type.
|
||||
|
|
@ -73,4 +75,9 @@ abstract class PartialForwardingServerCall<ReqT, RespT> extends ServerCall<ReqT,
|
|||
public String getAuthority() {
|
||||
return delegate().getAuthority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package io.grpc;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
/**
|
||||
* A {@link ServerCall.Listener} which forwards all of its methods to another {@link
|
||||
* ServerCall.Listener} which may have a different parameterized type than the
|
||||
|
|
@ -47,4 +49,9 @@ abstract class PartialForwardingServerCallListener<ReqT>
|
|||
public void onReady() {
|
||||
delegate().onReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.grpc.internal;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import io.grpc.Attributes;
|
||||
import io.grpc.Compressor;
|
||||
import io.grpc.DecompressorRegistry;
|
||||
|
|
@ -99,4 +100,9 @@ abstract class ForwardingClientStream implements ClientStream {
|
|||
public Attributes getAttributes() {
|
||||
return delegate().getAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.grpc.internal;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.Status;
|
||||
|
||||
|
|
@ -47,4 +48,9 @@ abstract class ForwardingClientStreamListener implements ClientStreamListener {
|
|||
public void onReady() {
|
||||
delegate().onReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.grpc.internal;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import io.grpc.Attributes;
|
||||
import io.grpc.CallOptions;
|
||||
|
|
@ -64,7 +65,7 @@ abstract class ForwardingConnectionClientTransport implements ConnectionClientTr
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "[" + delegate().toString() + "]";
|
||||
return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.grpc.internal;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import io.grpc.CallOptions;
|
||||
import io.grpc.ClientCall;
|
||||
import io.grpc.ConnectivityState;
|
||||
|
|
@ -86,4 +87,9 @@ abstract class ForwardingManagedChannel extends ManagedChannel {
|
|||
public void enterIdle() {
|
||||
delegate.enterIdle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("delegate", delegate).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package io.grpc.internal;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import io.grpc.NameResolver;
|
||||
|
||||
/**
|
||||
|
|
@ -50,4 +51,9 @@ abstract class ForwardingNameResolver extends NameResolver {
|
|||
public void refresh() {
|
||||
delegate.refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("delegate", delegate).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.grpc.internal;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
|
@ -99,4 +100,9 @@ public abstract class ForwardingReadableBuffer implements ReadableBuffer {
|
|||
public void close() {
|
||||
buf.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("delegate", buf).toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@
|
|||
package io.grpc;
|
||||
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mockingDetails;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import com.google.common.base.Defaults;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
|
@ -68,5 +70,19 @@ public final class ForwardingTestUtil {
|
|||
throw new AssertionError(String.format("Method was not forwarded: %s", method));
|
||||
}
|
||||
}
|
||||
|
||||
boolean skipToString = false;
|
||||
for (Method method : skippedMethods) {
|
||||
if (method.getName().equals("toString")) {
|
||||
skipToString = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!skipToString) {
|
||||
String actual = forwarder.toString();
|
||||
String expected =
|
||||
MoreObjects.toStringHelper(forwarder).add("delegate", mockDelegate).toString();
|
||||
assertEquals("Method toString() was not forwarded properly", expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue