Skip to content

Commit

Permalink
Work around deprecation warning.
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 committed May 23, 2018
1 parent 3f8b9bf commit 5be264f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/io/grpc/internal/CensusStatsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
* starts earlier than the ServerCall. Therefore, only one tracer is created per stream/call and
* it's the tracer that reports the summary to Census.
*/
@SuppressWarnings("deprecation")
public final class CensusStatsModule {
private static final Logger logger = Logger.getLogger(CensusStatsModule.class.getName());
private static final double NANOS_PER_MILLI = TimeUnit.MILLISECONDS.toNanos(1);
Expand Down
19 changes: 12 additions & 7 deletions core/src/main/java/io/grpc/internal/CensusTracingModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import io.grpc.ServerStreamTracer;
import io.grpc.StreamTracer;
import io.opencensus.trace.EndSpanOptions;
import io.opencensus.trace.NetworkEvent;
import io.opencensus.trace.Span;
import io.opencensus.trace.SpanContext;
import io.opencensus.trace.Status;
Expand All @@ -58,6 +57,7 @@
* starts earlier than the ServerCall. Therefore, only one tracer is created per stream/call and
* it's the tracer that reports the summary to Census.
*/
@SuppressWarnings("deprecation")
final class CensusTracingModule {
private static final Logger logger = Logger.getLogger(CensusTracingModule.class.getName());

Expand Down Expand Up @@ -211,9 +211,10 @@ private static EndSpanOptions createEndSpanOptions(
}

private static void recordNetworkEvent(
Span span, NetworkEvent.Type type,
Span span, io.opencensus.trace.NetworkEvent.Type type,
int seqNo, long optionalWireSize, long optionalUncompressedSize) {
NetworkEvent.Builder eventBuilder = NetworkEvent.builder(type, seqNo);
io.opencensus.trace.NetworkEvent.Builder eventBuilder =
io.opencensus.trace.NetworkEvent.builder(type, seqNo);
if (optionalUncompressedSize != -1) {
eventBuilder.setUncompressedMessageSize(optionalUncompressedSize);
}
Expand Down Expand Up @@ -281,14 +282,16 @@ private static final class ClientTracer extends ClientStreamTracer {
public void outboundMessageSent(
int seqNo, long optionalWireSize, long optionalUncompressedSize) {
recordNetworkEvent(
span, NetworkEvent.Type.SENT, seqNo, optionalWireSize, optionalUncompressedSize);
span, io.opencensus.trace.NetworkEvent.Type.SENT, seqNo, optionalWireSize,
optionalUncompressedSize);
}

@Override
public void inboundMessageRead(
int seqNo, long optionalWireSize, long optionalUncompressedSize) {
recordNetworkEvent(
span, NetworkEvent.Type.RECV, seqNo, optionalWireSize, optionalUncompressedSize);
span, io.opencensus.trace.NetworkEvent.Type.RECV, seqNo, optionalWireSize,
optionalUncompressedSize);
}
}

Expand Down Expand Up @@ -347,14 +350,16 @@ public Context filterContext(Context context) {
public void outboundMessageSent(
int seqNo, long optionalWireSize, long optionalUncompressedSize) {
recordNetworkEvent(
span, NetworkEvent.Type.SENT, seqNo, optionalWireSize, optionalUncompressedSize);
span, io.opencensus.trace.NetworkEvent.Type.SENT, seqNo, optionalWireSize,
optionalUncompressedSize);
}

@Override
public void inboundMessageRead(
int seqNo, long optionalWireSize, long optionalUncompressedSize) {
recordNetworkEvent(
span, NetworkEvent.Type.RECV, seqNo, optionalWireSize, optionalUncompressedSize);
span, io.opencensus.trace.NetworkEvent.Type.RECV, seqNo, optionalWireSize,
optionalUncompressedSize);
}
}

Expand Down
26 changes: 15 additions & 11 deletions core/src/test/java/io/grpc/internal/CensusModulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@
import io.opencensus.tags.TagValue;
import io.opencensus.tags.Tags;
import io.opencensus.trace.EndSpanOptions;
import io.opencensus.trace.NetworkEvent;
import io.opencensus.trace.NetworkEvent.Type;
import io.opencensus.trace.Span;
import io.opencensus.trace.SpanBuilder;
import io.opencensus.trace.SpanContext;
Expand Down Expand Up @@ -102,6 +100,7 @@
* Test for {@link CensusStatsModule} and {@link CensusTracingModule}.
*/
@RunWith(JUnit4.class)
@SuppressWarnings("deprecation")
public class CensusModulesTest {
private static final CallOptions.Key<String> CUSTOM_OPTION =
CallOptions.Key.createWithDefault("option1", "default");
Expand Down Expand Up @@ -174,7 +173,7 @@ public String parse(InputStream stream) {
@Captor
private ArgumentCaptor<Status> statusCaptor;
@Captor
private ArgumentCaptor<NetworkEvent> networkEventCaptor;
private ArgumentCaptor<io.opencensus.trace.NetworkEvent> networkEventCaptor;

private CensusStatsModule censusStats;
private CensusTracingModule censusTracing;
Expand Down Expand Up @@ -475,13 +474,16 @@ public void clientBasicTracingDefaultSpan() {

InOrder inOrder = inOrder(spyClientSpan);
inOrder.verify(spyClientSpan, times(3)).addNetworkEvent(networkEventCaptor.capture());
List<NetworkEvent> events = networkEventCaptor.getAllValues();
List<io.opencensus.trace.NetworkEvent> events = networkEventCaptor.getAllValues();
assertEquals(
NetworkEvent.builder(Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0));
io.opencensus.trace.NetworkEvent.builder(io.opencensus.trace.NetworkEvent.Type.SENT, 0)
.setCompressedMessageSize(882).build(), events.get(0));
assertEquals(
NetworkEvent.builder(Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1));
io.opencensus.trace.NetworkEvent.builder(io.opencensus.trace.NetworkEvent.Type.SENT, 1)
.setUncompressedMessageSize(27).build(), events.get(1));
assertEquals(
NetworkEvent.builder(Type.RECV, 0)
io.opencensus.trace.NetworkEvent.builder(io.opencensus.trace.NetworkEvent.Type.RECV, 0)
.setCompressedMessageSize(255)
.setCompressedMessageSize(255)
.setUncompressedMessageSize(90)
.build(),
Expand Down Expand Up @@ -956,13 +958,15 @@ public void serverBasicTracingNoHeaders() {

InOrder inOrder = inOrder(spyServerSpan);
inOrder.verify(spyServerSpan, times(3)).addNetworkEvent(networkEventCaptor.capture());
List<NetworkEvent> events = networkEventCaptor.getAllValues();
List<io.opencensus.trace.NetworkEvent> events = networkEventCaptor.getAllValues();
assertEquals(
NetworkEvent.builder(Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0));
io.opencensus.trace.NetworkEvent.builder(io.opencensus.trace.NetworkEvent.Type.SENT, 0)
.setCompressedMessageSize(882).build(), events.get(0));
assertEquals(
NetworkEvent.builder(Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1));
io.opencensus.trace.NetworkEvent.builder(io.opencensus.trace.NetworkEvent.Type.SENT, 1)
.setUncompressedMessageSize(27).build(), events.get(1));
assertEquals(
NetworkEvent.builder(Type.RECV, 0)
io.opencensus.trace.NetworkEvent.builder(io.opencensus.trace.NetworkEvent.Type.RECV, 0)
.setCompressedMessageSize(255)
.setUncompressedMessageSize(90)
.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
*
* <p> New tests should avoid using Mockito to support running on AppEngine.</p>
*/
@SuppressWarnings("deprecation")
public abstract class AbstractInteropTest {

@Rule public final Timeout globalTimeout = Timeout.seconds(30);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.EndSpanOptions;
import io.opencensus.trace.Link;
import io.opencensus.trace.NetworkEvent;
import io.opencensus.trace.Sampler;
import io.opencensus.trace.Span;
import io.opencensus.trace.SpanBuilder;
Expand All @@ -58,6 +57,7 @@
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;

@SuppressWarnings("deprecation")
public class StatsTestUtils {
private StatsTestUtils() {
}
Expand Down Expand Up @@ -347,7 +347,7 @@ public void addAnnotation(String description, Map<String, AttributeValue> attrib
public void addAnnotation(Annotation annotation) {}

@Override
public void addNetworkEvent(NetworkEvent networkEvent) {}
public void addNetworkEvent(io.opencensus.trace.NetworkEvent networkEvent) {}

@Override
public void addLink(Link link) {}
Expand Down

0 comments on commit 5be264f

Please sign in to comment.