use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project spring_boot by hryou0922.
the class RouteGuideClient method listFeatures.
/**
* Blocking server-streaming example. Calls listFeatures with a rectangle of interest. Prints each
* response feature as it arrives.
*/
public void listFeatures(int lowLat, int lowLon, int hiLat, int hiLon) {
info("*** ListFeatures: lowLat={0} lowLon={1} hiLat={2} hiLon={3}", lowLat, lowLon, hiLat, hiLon);
Rectangle request = Rectangle.newBuilder().setLo(Point.newBuilder().setLatitude(lowLat).setLongitude(lowLon).build()).setHi(Point.newBuilder().setLatitude(hiLat).setLongitude(hiLon).build()).build();
Iterator<Feature> features;
try {
features = blockingStub.listFeatures(request);
for (int i = 1; features.hasNext(); i++) {
Feature feature = features.next();
info("Result #" + i + ": {0}", feature);
if (testHelper != null) {
testHelper.onMessage(feature);
}
}
} catch (StatusRuntimeException e) {
warning("RPC failed: {0}", e.getStatus());
if (testHelper != null) {
testHelper.onRpcError(e);
}
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project spring_boot by hryou0922.
the class HelloStreamClient method simpleRpc.
/**
* 一元服务调用
*/
public void simpleRpc(int num) {
logger.info("request simpleRpc: num={}", num);
Simple simple = Simple.newBuilder().setName("simpleRpc").setNum(num).build();
SimpleFeature feature;
try {
feature = blockingStub.simpleRpc(simple);
} catch (StatusRuntimeException e) {
logger.info("RPC failed: {0}", e.getStatus());
return;
}
logger.info("simpleRpc end called {}", feature);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project incubator-skywalking by apache.
the class GRPCChannelManagerTest method changeStatusToConnectedWithReportError.
@Test
public void changeStatusToConnectedWithReportError() throws Throwable {
grpcChannelManager.reportError(new StatusRuntimeException(Status.ABORTED));
grpcChannelManager.run();
verify(listener, times(1)).statusChanged(GRPCChannelStatus.CONNECTED);
assertThat(listener.status, is(GRPCChannelStatus.CONNECTED));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException 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.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException in project fabric-sdk-java by hyperledger.
the class Channel method sendProposalToPeers.
private Collection<ProposalResponse> sendProposalToPeers(Collection<Peer> peers, SignedProposal signedProposal, TransactionContext transactionContext) throws InvalidArgumentException, ProposalException {
checkPeers(peers);
if (transactionContext.getVerify()) {
try {
loadCACertificates();
} catch (Exception e) {
throw new ProposalException(e);
}
}
class Pair {
private final Peer peer;
private final Future<FabricProposalResponse.ProposalResponse> future;
private Pair(Peer peer, Future<FabricProposalResponse.ProposalResponse> future) {
this.peer = peer;
this.future = future;
}
}
List<Pair> peerFuturePairs = new ArrayList<>();
for (Peer peer : peers) {
logger.debug(format("Channel %s send proposal to peer %s at url %s", name, peer.getName(), peer.getUrl()));
if (null != diagnosticFileDumper) {
logger.trace(format("Sending to channel %s, peer: %s, proposal: %s", name, peer.getName(), diagnosticFileDumper.createDiagnosticProtobufFile(signedProposal.toByteArray())));
}
Future<FabricProposalResponse.ProposalResponse> proposalResponseListenableFuture;
try {
proposalResponseListenableFuture = peer.sendProposalAsync(signedProposal);
} catch (Exception e) {
proposalResponseListenableFuture = new CompletableFuture<>();
((CompletableFuture) proposalResponseListenableFuture).completeExceptionally(e);
}
peerFuturePairs.add(new Pair(peer, proposalResponseListenableFuture));
}
Collection<ProposalResponse> proposalResponses = new ArrayList<>();
for (Pair peerFuturePair : peerFuturePairs) {
FabricProposalResponse.ProposalResponse fabricResponse = null;
String message;
int status = 500;
final String peerName = peerFuturePair.peer.getName();
try {
fabricResponse = peerFuturePair.future.get(transactionContext.getProposalWaitTime(), TimeUnit.MILLISECONDS);
message = fabricResponse.getResponse().getMessage();
status = fabricResponse.getResponse().getStatus();
logger.debug(format("Channel %s got back from peer %s status: %d, message: %s", name, peerName, status, message));
if (null != diagnosticFileDumper) {
logger.trace(format("Got back from channel %s, peer: %s, proposal response: %s", name, peerName, diagnosticFileDumper.createDiagnosticProtobufFile(fabricResponse.toByteArray())));
}
} catch (InterruptedException e) {
message = "Sending proposal to " + peerName + " failed because of interruption";
logger.error(message, e);
} catch (TimeoutException e) {
message = format("Sending proposal to " + peerName + " failed because of timeout(%d milliseconds) expiration", transactionContext.getProposalWaitTime());
logger.error(message, e);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof Error) {
String emsg = "Sending proposal to " + peerName + " failed because of " + cause.getMessage();
// wrapped in exception to get full stack trace.
logger.error(emsg, new Exception(cause));
throw (Error) cause;
} else {
if (cause instanceof StatusRuntimeException) {
message = format("Sending proposal to " + peerName + " failed because of: gRPC failure=%s", ((StatusRuntimeException) cause).getStatus());
} else {
message = format("Sending proposal to " + peerName + " failed because of: %s", cause.getMessage());
}
// wrapped in exception to get full stack trace.
logger.error(message, new Exception(cause));
}
}
ProposalResponse proposalResponse = new ProposalResponse(transactionContext.getTxID(), transactionContext.getChannelID(), status, message);
proposalResponse.setProposalResponse(fabricResponse);
proposalResponse.setProposal(signedProposal);
proposalResponse.setPeer(peerFuturePair.peer);
if (fabricResponse != null && transactionContext.getVerify()) {
proposalResponse.verify(client.getCryptoSuite());
}
proposalResponses.add(proposalResponse);
}
return proposalResponses;
}
Aggregations