Search in sources :

Example 61 with StatusRuntimeException

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);
        }
    }
}
Also used : Rectangle(com.hry.spring.grpc.stream.Rectangle) StatusRuntimeException(io.grpc.StatusRuntimeException) Feature(com.hry.spring.grpc.stream.Feature) Point(com.hry.spring.grpc.stream.Point)

Example 62 with StatusRuntimeException

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);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) SimpleFeature(com.hry.spring.grpc.mystream.SimpleFeature) Simple(com.hry.spring.grpc.mystream.Simple)

Example 63 with StatusRuntimeException

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));
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 64 with StatusRuntimeException

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());
}
Also used : Status(io.grpc.Status) UpstreamSegment(org.apache.skywalking.apm.network.proto.UpstreamSegment) TraceSegmentServiceGrpc(org.apache.skywalking.apm.network.proto.TraceSegmentServiceGrpc) DnsNameResolverProvider(io.grpc.internal.DnsNameResolverProvider) StatusRuntimeException(io.grpc.StatusRuntimeException) ManagedChannel(io.grpc.ManagedChannel) Downstream(org.apache.skywalking.apm.network.proto.Downstream)

Example 65 with StatusRuntimeException

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;
}
Also used : ArrayList(java.util.ArrayList) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException) ProtoUtils.getSignatureHeaderAsByteString(org.hyperledger.fabric.sdk.transaction.ProtoUtils.getSignatureHeaderAsByteString) ByteString(com.google.protobuf.ByteString) EventHubException(org.hyperledger.fabric.sdk.exception.EventHubException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) InvalidArgumentException(org.hyperledger.fabric.sdk.exception.InvalidArgumentException) TransactionException(org.hyperledger.fabric.sdk.exception.TransactionException) TransactionEventException(org.hyperledger.fabric.sdk.exception.TransactionEventException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) StatusRuntimeException(io.grpc.StatusRuntimeException) CryptoException(org.hyperledger.fabric.sdk.exception.CryptoException) TimeoutException(java.util.concurrent.TimeoutException) ProposalException(org.hyperledger.fabric.sdk.exception.ProposalException) CompletableFuture(java.util.concurrent.CompletableFuture) FabricProposalResponse(org.hyperledger.fabric.protos.peer.FabricProposalResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) Future(java.util.concurrent.Future) ScheduledFuture(java.util.concurrent.ScheduledFuture) CompletableFuture(java.util.concurrent.CompletableFuture) FabricProposalResponse(org.hyperledger.fabric.protos.peer.FabricProposalResponse) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)240 Test (org.junit.Test)164 ApiException (com.google.api.gax.grpc.ApiException)74 Status (io.grpc.Status)25 StreamObserver (io.grpc.stub.StreamObserver)20 ByteString (com.google.protobuf.ByteString)18 ArrayList (java.util.ArrayList)18 Metadata (io.grpc.Metadata)14 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)13 ExecutionException (java.util.concurrent.ExecutionException)12 JanusGraphGrpcServerBaseTest (org.janusgraph.graphdb.grpc.JanusGraphGrpcServerBaseTest)12 Test (org.junit.jupiter.api.Test)12 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ManagedChannel (io.grpc.ManagedChannel)9 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)8 BStruct (org.ballerinalang.model.values.BStruct)8 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)7 ChannelCredentials (io.grpc.ChannelCredentials)6 ServerCredentials (io.grpc.ServerCredentials)6 TlsChannelCredentials (io.grpc.TlsChannelCredentials)6