use of org.apache.skywalking.apm.network.proto.Downstream in project incubator-skywalking by apache.
the class GRPCNoServerTest method main.
public static void main(String[] args) throws InterruptedException {
ManagedChannelBuilder<?> channelBuilder = NettyChannelBuilder.forAddress("127.0.0.1", 8080).nameResolverFactory(new DnsNameResolverProvider()).maxInboundMessageSize(1024 * 1024 * 50).usePlaintext(true);
ManagedChannel channel = channelBuilder.build();
TraceSegmentServiceGrpc.TraceSegmentServiceStub serviceStub = TraceSegmentServiceGrpc.newStub(channel);
final Status[] status = { null };
StreamObserver<UpstreamSegment> streamObserver = serviceStub.collect(new StreamObserver<Downstream>() {
@Override
public void onNext(Downstream value) {
}
@Override
public void onError(Throwable t) {
status[0] = ((StatusRuntimeException) t).getStatus();
}
@Override
public void onCompleted() {
}
});
streamObserver.onNext(null);
streamObserver.onCompleted();
Thread.sleep(2 * 1000);
Assert.assertEquals(status[0].getCode(), Status.UNAVAILABLE.getCode());
}
use of org.apache.skywalking.apm.network.proto.Downstream in project incubator-skywalking by apache.
the class TraceSegmentServiceClient method consume.
@Override
public void consume(List<TraceSegment> data) {
if (CONNECTED.equals(status)) {
final GRPCStreamServiceStatus status = new GRPCStreamServiceStatus(false);
StreamObserver<UpstreamSegment> upstreamSegmentStreamObserver = serviceStub.collect(new StreamObserver<Downstream>() {
@Override
public void onNext(Downstream downstream) {
}
@Override
public void onError(Throwable throwable) {
status.finished();
if (logger.isErrorEnable()) {
logger.error(throwable, "Send UpstreamSegment to collector fail with a grpc internal exception.");
}
ServiceManager.INSTANCE.findService(GRPCChannelManager.class).reportError(throwable);
}
@Override
public void onCompleted() {
status.finished();
}
});
for (TraceSegment segment : data) {
try {
UpstreamSegment upstreamSegment = segment.transform();
upstreamSegmentStreamObserver.onNext(upstreamSegment);
} catch (Throwable t) {
logger.error(t, "Transform and send UpstreamSegment to collector fail.");
}
}
upstreamSegmentStreamObserver.onCompleted();
if (status.wait4Finish(TIMEOUT)) {
segmentUplinkedCounter += data.size();
}
} else {
segmentAbandonedCounter += data.size();
}
printUplinkStatus();
}
Aggregations