Java Code Examples for io.grpc.Status#PERMISSION_DENIED

The following examples show how to use io.grpc.Status#PERMISSION_DENIED . 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: RemoteSerializerTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertsTargetChangeWithRemoved() {
  WatchTargetChange expected =
      new WatchTargetChange(
          WatchTargetChangeType.Removed,
          asList(1, 4),
          ByteString.copyFrom(new byte[] {0, 1, 2}),
          Status.PERMISSION_DENIED);
  WatchTargetChange actual =
      (WatchTargetChange)
          serializer.decodeWatchChange(
              ListenResponse.newBuilder()
                  .setTargetChange(
                      TargetChange.newBuilder()
                          .setTargetChangeType(TargetChangeType.REMOVE)
                          .addTargetIds(1)
                          .addTargetIds(4)
                          .setCause(com.google.rpc.Status.newBuilder().setCode(7))
                          .setResumeToken(ByteString.copyFrom(new byte[] {0, 1, 2})))
                  .build());
  assertEquals(expected, actual);
}
 
Example 2
Source File: SpannerExceptionUtilTest.java    From cloud-spanner-r2dbc with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonRetryableException() {
  assertThat(createR2dbcException(new IllegalArgumentException()))
      .isInstanceOf(R2dbcNonTransientResourceException.class);
  assertThat(createR2dbcException((new IOException())))
      .isInstanceOf(R2dbcNonTransientResourceException.class);

  StatusRuntimeException nonRetryableException =
      new StatusRuntimeException(Status.PERMISSION_DENIED);
  assertThat(createR2dbcException(nonRetryableException))
      .isInstanceOf(R2dbcPermissionDeniedException.class);
}
 
Example 3
Source File: ControllerServiceImpl.java    From pravega with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: RouteGuideClientTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
/**
 * Example for testing bi-directional call.
 */
@Test
public void routeChat_errorResponse() throws Exception {
  final List<RouteNote> notesDelivered = new ArrayList<>();
  final StatusRuntimeException fakeError = new StatusRuntimeException(Status.PERMISSION_DENIED);

  // implement the fake service
  RouteGuideImplBase routeChatImpl =
      new RouteGuideImplBase() {
        @Override
        public StreamObserver<RouteNote> routeChat(
            final StreamObserver<RouteNote> responseObserver) {
          StreamObserver<RouteNote> requestObserver = new StreamObserver<RouteNote>() {
            @Override
            public void onNext(RouteNote value) {
              notesDelivered.add(value);
              responseObserver.onError(fakeError);
            }

            @Override
            public void onError(Throwable t) {
            }

            @Override
            public void onCompleted() {
              responseObserver.onCompleted();
            }
          };

          return requestObserver;
        }
      };
  serviceRegistry.addService(routeChatImpl);

  client.routeChat().await(1, TimeUnit.SECONDS);

  assertEquals("First message", notesDelivered.get(0).getMessage());
  verify(testHelper, never()).onMessage(any(Message.class));
  ArgumentCaptor<Throwable> errorCaptor = ArgumentCaptor.forClass(Throwable.class);
  verify(testHelper).onRpcError(errorCaptor.capture());
  assertEquals(fakeError.getStatus(), Status.fromThrowable(errorCaptor.getValue()));
}
 
Example 5
Source File: RouteGuideClientTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/**
 * Example for testing bi-directional call.
 */
@Test
public void routeChat_errorResponse() throws Exception {
  final List<RouteNote> notesDelivered = new ArrayList<>();
  final StatusRuntimeException fakeError = new StatusRuntimeException(Status.PERMISSION_DENIED);

  // implement the fake service
  RouteGuideImplBase routeChatImpl =
      new RouteGuideImplBase() {
        @Override
        public StreamObserver<RouteNote> routeChat(
            final StreamObserver<RouteNote> responseObserver) {
          StreamObserver<RouteNote> requestObserver = new StreamObserver<RouteNote>() {
            @Override
            public void onNext(RouteNote value) {
              notesDelivered.add(value);
              responseObserver.onError(fakeError);
            }

            @Override
            public void onError(Throwable t) {
            }

            @Override
            public void onCompleted() {
              responseObserver.onCompleted();
            }
          };

          return requestObserver;
        }
      };
  serviceRegistry.addService(routeChatImpl);

  client.routeChat().await(1, TimeUnit.SECONDS);

  assertEquals("First message", notesDelivered.get(0).getMessage());
  verify(testHelper, never()).onMessage(any(Message.class));
  ArgumentCaptor<Throwable> errorCaptor = ArgumentCaptor.forClass(Throwable.class);
  verify(testHelper).onRpcError(errorCaptor.capture());
  assertEquals(fakeError.getStatus(), Status.fromThrowable(errorCaptor.getValue()));
}