Java Code Examples for io.grpc.Status#UNKNOWN
The following examples show how to use
io.grpc.Status#UNKNOWN .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OcAgentTraceServiceConfigRpcHandler.java From opencensus-java with Apache License 2.0 | 6 votes |
synchronized void onComplete(@javax.annotation.Nullable Throwable error) { if (isCompleted()) { return; } currentConfigObserver = null; // TODO(songya): add Runnable Status status; if (error == null) { status = Status.OK; } else if (error instanceof StatusRuntimeException) { status = ((StatusRuntimeException) error).getStatus(); } else { status = Status.UNKNOWN; } terminateStatus = status; }
Example 2
Source File: RedisClientTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
@Test public void runExceptionConnectionResetIsUnavailable() throws IOException, InterruptedException { RedisClient client = new RedisClient(mock(JedisCluster.class)); Status status = Status.UNKNOWN; try { client.run( jedis -> { throw new JedisConnectionException(new SocketException("Connection reset")); }); } catch (IOException e) { status = Status.fromThrowable(e); } assertThat(status.getCode()).isEqualTo(Code.UNAVAILABLE); }
Example 3
Source File: RoundRobinLoadBalancerTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void pickerEmptyList() throws Exception { SubchannelPicker picker = new EmptyPicker(Status.UNKNOWN); assertEquals(null, picker.pickSubchannel(mockArgs).getSubchannel()); assertEquals(Status.UNKNOWN, picker.pickSubchannel(mockArgs).getStatus()); }
Example 4
Source File: ForwardingClientStreamListenerTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void closedTest() { Status status = Status.UNKNOWN; Metadata trailers = new Metadata(); forward.closed(status, trailers); verify(mock).closed(same(status), same(trailers)); }
Example 5
Source File: ControllerServiceImpl.java From pravega with Apache License 2.0 | 5 votes |
@SuppressWarnings("checkstyle:ReturnCount") private Status getStatusFromException(Throwable cause) { if (cause instanceof StoreException.DataExistsException) { return Status.ALREADY_EXISTS; } if (cause instanceof StoreException.DataNotFoundException) { return Status.NOT_FOUND; } if (cause instanceof StoreException.DataNotEmptyException) { return Status.FAILED_PRECONDITION; } if (cause instanceof StoreException.WriteConflictException) { return Status.FAILED_PRECONDITION; } if (cause instanceof StoreException.IllegalStateException) { return Status.INTERNAL; } if (cause instanceof StoreException.OperationNotAllowedException) { return Status.PERMISSION_DENIED; } if (cause instanceof StoreException.StoreConnectionException) { return Status.INTERNAL; } if (cause instanceof TimeoutException) { return Status.DEADLINE_EXCEEDED; } return Status.UNKNOWN; }
Example 6
Source File: OcAgentTraceServiceExportRpcHandler.java From opencensus-java with Apache License 2.0 | 5 votes |
synchronized void onComplete(@javax.annotation.Nullable Throwable error) { if (isCompleted()) { return; } // TODO(songya): add Runnable Status status; if (error == null) { status = Status.OK; } else if (error instanceof StatusRuntimeException) { status = ((StatusRuntimeException) error).getStatus(); } else { status = Status.UNKNOWN; } terminateStatus = status; }
Example 7
Source File: OcAgentMetricsServiceExportRpcHandler.java From opencensus-java with Apache License 2.0 | 5 votes |
synchronized void onComplete(@javax.annotation.Nullable Throwable error) { if (isCompleted()) { return; } // TODO(songya): add Runnable Status status; if (error == null) { status = Status.OK; } else if (error instanceof StatusRuntimeException) { status = ((StatusRuntimeException) error).getStatus(); } else { status = Status.UNKNOWN; } terminateStatus = status; }
Example 8
Source File: RedisClientTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
@Test public void runExceptionSocketTimeoutExceptionIsDeadlineExceeded() throws IOException, InterruptedException { RedisClient client = new RedisClient(mock(JedisCluster.class)); Status status = Status.UNKNOWN; try { client.run( jedis -> { throw new JedisConnectionException(new SocketTimeoutException()); }); } catch (IOException e) { status = Status.fromThrowable(e); } assertThat(status.getCode()).isEqualTo(Code.DEADLINE_EXCEEDED); }
Example 9
Source File: ForwardingClientStreamListenerTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void closedTest() { Status status = Status.UNKNOWN; Metadata trailers = new Metadata(); forward.closed(status, trailers); verify(mock).closed(same(status), same(trailers)); }
Example 10
Source File: RedisClientTest.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
@Test public void runExceptionEndOfStreamIsUnavailable() throws IOException, InterruptedException { RedisClient client = new RedisClient(mock(JedisCluster.class)); Status status = Status.UNKNOWN; try { client.run( jedis -> { throw new JedisConnectionException("Unexpected end of stream."); }); } catch (IOException e) { status = Status.fromThrowable(e); } assertThat(status.getCode()).isEqualTo(Code.UNAVAILABLE); }
Example 11
Source File: GoogleAdsClientTest.java From google-ads-java with Apache License 2.0 | 5 votes |
/** * Verifies that the exception transformation behaviour is working for a test example. */ @Test public void exceptionTransformedToGoogleAdsException() { GoogleAdsClient client = GoogleAdsClient.newBuilder() .setCredentials(fakeCredentials) .setDeveloperToken(DEVELOPER_TOKEN) .setTransportChannelProvider(localChannelProvider) .setEnableGeneratedCatalog(enabledGeneratedCatalog) .build(); Metadata.Key trailerKey = ApiCatalog .getDefault(enabledGeneratedCatalog) .getLatestVersion() .getExceptionFactory() .getTrailerKey(); Metadata trailers = new Metadata(); GoogleAdsFailure.Builder failure = GoogleAdsFailure.newBuilder(); failure.addErrors(GoogleAdsError.newBuilder().setMessage("Test error message")); trailers.put(trailerKey, failure.build().toByteArray()); StatusException rootCause = new StatusException(Status.UNKNOWN, trailers); mockService.addException(new ApiException(rootCause, GrpcStatusCode.of(Code.UNKNOWN), false)); try (GoogleAdsServiceClient googleAdsServiceClient = client.getLatestVersion().createGoogleAdsServiceClient()) { googleAdsServiceClient.search("123", "select blah"); } catch (GoogleAdsException ex) { // Expected } }
Example 12
Source File: GoogleAdsExceptionTransformationTest.java From google-ads-java with Apache License 2.0 | 5 votes |
private static ApiException getApiExceptionForVersion( Metadata.Key<byte[]> failureKey, byte[] data) { Metadata trailers = new Metadata(); if (data != null) { trailers.put(failureKey, data); } return new ApiException( new StatusException(Status.UNKNOWN, trailers), GrpcStatusCode.of(Code.UNKNOWN), false); }
Example 13
Source File: GoogleAdsExceptionTransformationTest.java From google-ads-java with Apache License 2.0 | 5 votes |
@Test public void handlesNullTrailers() { ApiException exception = new ApiException( new StatusException(Status.UNKNOWN), GrpcStatusCode.of(Code.UNKNOWN), false); Throwable result = transformation.transform(exception); assertEquals(exception, result); }
Example 14
Source File: ApiCatalogTest.java From google-ads-java with Apache License 2.0 | 5 votes |
/** Constructs an ApiException embedding the proto in the trailing metadata for a given key. */ private static ApiException getApiExceptionForVersion( Metadata.Key<byte[]> failureKey, byte[] data) { Metadata trailers = new Metadata(); if (data != null) { trailers.put(failureKey, data); } return new ApiException( new StatusException(Status.UNKNOWN, trailers), GrpcStatusCode.of(Code.UNKNOWN), false); }
Example 15
Source File: ApiCatalogTest.java From google-ads-java with Apache License 2.0 | 5 votes |
/** Ensure that all versions return Optional.empty() when the trailing metadata is not present. */ @Test public void createGoogleAdsException_fromNullMetadata() { for (Version version : catalog.getSupportedVersions()) { ApiException exception = new ApiException( new StatusException(Status.UNKNOWN, null), GrpcStatusCode.of(Code.UNKNOWN), false); Optional<? extends BaseGoogleAdsException> result = version.getExceptionFactory().createGoogleAdsException(exception); assertFalse("Null metadata produced result", result.isPresent()); } }
Example 16
Source File: RoundRobinLoadBalancerTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void pickerEmptyList() throws Exception { SubchannelPicker picker = new EmptyPicker(Status.UNKNOWN); assertEquals(null, picker.pickSubchannel(mockArgs).getSubchannel()); assertEquals(Status.UNKNOWN, picker.pickSubchannel(mockArgs).getStatus()); }
Example 17
Source File: ForwardingClientStreamTest.java From grpc-java with Apache License 2.0 | 4 votes |
@Test public void cancelTest() { Status reason = Status.UNKNOWN; forward.cancel(reason); verify(mock).cancel(same(reason)); }
Example 18
Source File: ForwardingClientStreamTest.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Test public void cancelTest() { Status reason = Status.UNKNOWN; forward.cancel(reason); verify(mock).cancel(same(reason)); }