Java Code Examples for io.grpc.Status#fromThrowable()
The following examples show how to use
io.grpc.Status#fromThrowable() .
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: ExperimentTest.java From modeldb with Apache License 2.0 | 6 votes |
@Test public void ee_getExperimentTagsNegativeTest() { LOGGER.info("Get Experiment tags Negative test start................................"); ExperimentServiceBlockingStub experimentServiceStub = ExperimentServiceGrpc.newBlockingStub(channel); GetTags getExperimentTags = GetTags.newBuilder().build(); try { experimentServiceStub.getExperimentTags(getExperimentTags); fail(); } catch (StatusRuntimeException e) { Status status = Status.fromThrowable(e); LOGGER.warn("Error Code : " + status.getCode() + " Description : " + status.getDescription()); assertEquals(Status.INVALID_ARGUMENT.getCode(), status.getCode()); } LOGGER.info("Get Experiment tags Negative test stop................................"); }
Example 2
Source File: ExperimentTest.java From modeldb with Apache License 2.0 | 6 votes |
@Test public void ec_addExperimentTagNegativeTest() { LOGGER.info("Add Experiment tag negative test start................................"); ExperimentServiceBlockingStub experimentServiceStub = ExperimentServiceGrpc.newBlockingStub(channel); AddExperimentTag updateExperimentTag = AddExperimentTag.newBuilder().setTag("Tag_xyz").build(); try { experimentServiceStub.addExperimentTag(updateExperimentTag); fail(); } catch (StatusRuntimeException e) { Status status = Status.fromThrowable(e); LOGGER.warn("Error Code : " + status.getCode() + " Description : " + status.getDescription()); assertEquals(Status.INVALID_ARGUMENT.getCode(), status.getCode()); } LOGGER.info("Add Experiment tags negative test stop................................"); }
Example 3
Source File: GrpcActionCache.java From bazel-buildfarm with Apache License 2.0 | 6 votes |
@Override public ActionResult get(ActionKey actionKey) { try { return actionCacheBlockingStub .get() .getActionResult( GetActionResultRequest.newBuilder() .setInstanceName(instanceName) .setActionDigest(actionKey.getDigest()) .build()); } catch (StatusRuntimeException e) { Status status = Status.fromThrowable(e); if (status.getCode() == Code.NOT_FOUND) { return null; } throw e; } }
Example 4
Source File: ClientCallsTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@Test public void blockingResponseStreamFailed() throws Exception { final AtomicReference<ClientCall.Listener<String>> listener = new AtomicReference<ClientCall.Listener<String>>(); NoopClientCall<Integer, String> call = new NoopClientCall<Integer, String>() { @Override public void start(io.grpc.ClientCall.Listener<String> responseListener, Metadata headers) { listener.set(responseListener); } }; Integer req = 2; Iterator<String> iter = ClientCalls.blockingServerStreamingCall(call, req); Metadata trailers = new Metadata(); listener.get().onClose(Status.INTERNAL, trailers); try { iter.next(); fail("Should fail"); } catch (Exception e) { Status status = Status.fromThrowable(e); assertEquals(Status.INTERNAL, status); Metadata metadata = Status.trailersFromThrowable(e); assertSame(trailers, metadata); } }
Example 5
Source File: ProjectTest.java From modeldb with Apache License 2.0 | 6 votes |
@Test public void k_getProjectByNameNotFoundTest() { LOGGER.info("Get Project by name NOT_FOUND test start................................"); ProjectServiceBlockingStub projectServiceStub = ProjectServiceGrpc.newBlockingStub(channel); try { GetProjectByName getProject = GetProjectByName.newBuilder().setName("test").build(); projectServiceStub.getProjectByName(getProject); fail(); } catch (StatusRuntimeException e) { Status status = Status.fromThrowable(e); LOGGER.warn("Error Code : " + status.getCode() + " Description : " + status.getDescription()); assertEquals(Status.NOT_FOUND.getCode(), status.getCode()); } LOGGER.info("Get project by name NOT_FOUND test stop................................"); }
Example 6
Source File: TaskRelocationIntegrationTest.java From titus-control-plane with Apache License 2.0 | 5 votes |
private Optional<TaskRelocationStatus> findRelocationStatus(String taskId) { try { TestStreamObserver<TaskRelocationExecution> events = new TestStreamObserver<>(); client.getTaskRelocationResult(RelocationTaskId.newBuilder().setId(taskId).build(), events); return Optional.of(last(events.getLast().getRelocationAttemptsList())); } catch (Exception e) { Status status = Status.fromThrowable(e); if (status.getCode() == Status.Code.NOT_FOUND) { return Optional.empty(); } throw new RuntimeException(e); } }
Example 7
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 8
Source File: Utils.java From grpc-java with Apache License 2.0 | 5 votes |
public static Status statusFromThrowable(Throwable t) { Status s = Status.fromThrowable(t); if (s.getCode() != Status.Code.UNKNOWN) { return s; } if (t instanceof ClosedChannelException) { // ClosedChannelException is used any time the Netty channel is closed. Proper error // processing requires remembering the error that occurred before this one and using it // instead. // // Netty uses an exception that has no stack trace, while we would never hope to show this to // users, if it happens having the extra information may provide a small hint of where to // look. ClosedChannelException extraT = new ClosedChannelException(); extraT.initCause(t); return Status.UNKNOWN.withDescription("channel closed").withCause(extraT); } if (t instanceof IOException) { return Status.UNAVAILABLE.withDescription("io exception").withCause(t); } if (t instanceof UnresolvedAddressException) { return Status.UNAVAILABLE.withDescription("unresolved address").withCause(t); } if (t instanceof Http2Exception) { return Status.INTERNAL.withDescription("http2 exception").withCause(t); } return s; }
Example 9
Source File: RetryPolicy.java From tikv-client-lib-java with Apache License 2.0 | 5 votes |
private void rethrowNotRecoverableException(Exception e) { if (e instanceof GrpcRegionStaleException) { throw (GrpcRegionStaleException)e; } Status status = Status.fromThrowable(e); if (unrecoverableStatus.contains(status.getCode())) { throw new GrpcException(e); } }
Example 10
Source File: WriteBufferingAndExceptionHandlerTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void uncaughtExceptionFailuresPropagated() throws Exception { WriteBufferingAndExceptionHandler handler = new WriteBufferingAndExceptionHandler(new ChannelHandlerAdapter() {}); LocalAddress addr = new LocalAddress("local"); ChannelFuture cf = new Bootstrap() .channel(LocalChannel.class) .handler(handler) .group(group) .register(); chan = cf.channel(); cf.sync(); ChannelFuture sf = new ServerBootstrap() .channel(LocalServerChannel.class) .childHandler(new ChannelHandlerAdapter() {}) .group(group) .bind(addr); server = sf.channel(); sf.sync(); ChannelFuture wf = chan.writeAndFlush(new Object()); chan.connect(addr); chan.pipeline().fireExceptionCaught(Status.ABORTED.withDescription("zap").asRuntimeException()); try { wf.sync(); fail(); } catch (Exception e) { Status status = Status.fromThrowable(e); assertThat(status.getCode()).isEqualTo(Code.ABORTED); assertThat(status.getDescription()).contains("zap"); } }
Example 11
Source File: DetailErrorSample.java From grpc-java with Apache License 2.0 | 5 votes |
static void verifyErrorReply(Throwable t) { Status status = Status.fromThrowable(t); Metadata trailers = Status.trailersFromThrowable(t); Verify.verify(status.getCode() == Status.Code.INTERNAL); Verify.verify(trailers.containsKey(DEBUG_INFO_TRAILER_KEY)); Verify.verify(status.getDescription().equals(DEBUG_DESC)); try { Verify.verify(trailers.get(DEBUG_INFO_TRAILER_KEY).equals(DEBUG_INFO)); } catch (IllegalArgumentException e) { throw new VerifyException(e); } }
Example 12
Source File: RepositoryTest.java From modeldb with Apache License 2.0 | 5 votes |
private void checkEqualsAssert(StatusRuntimeException e) { Status status = Status.fromThrowable(e); LOGGER.warn("Error Code : " + status.getCode() + " Description : " + status.getDescription()); if (app.getAuthServerHost() != null && app.getAuthServerPort() != null) { assertTrue( Status.PERMISSION_DENIED.getCode() == status.getCode() || Status.NOT_FOUND.getCode() == status.getCode()); // because of shadow delete the response could be 403 or 404 } else { assertEquals(Status.NOT_FOUND.getCode(), status.getCode()); } }
Example 13
Source File: ErrorHandlingClient.java From grpc-java with Apache License 2.0 | 5 votes |
void blockingCall() { GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channel); try { stub.sayHello(HelloRequest.newBuilder().setName("Bart").build()); } catch (Exception e) { Status status = Status.fromThrowable(e); Verify.verify(status.getCode() == Status.Code.INTERNAL); Verify.verify(status.getDescription().contains("Eggplant")); // Cause is not transmitted over the wire. } }
Example 14
Source File: AbstractServerStreamTest.java From grpc-java with Apache License 2.0 | 4 votes |
@Override public void deframeFailed(Throwable cause) { Status status = Status.fromThrowable(cause); transportReportStatus(status); }
Example 15
Source File: NFSArtifactStoreTest.java From modeldb with Apache License 2.0 | 4 votes |
@Test public void getArtifactTest() { LOGGER.info("get artifact test start................................"); try { storeArtifactTest(); GetUrlForArtifact getUrlForArtifactRequest = GetUrlForArtifact.newBuilder() .setId(experimentRun.getId()) .setKey(artifactKey) .setMethod("GET") .setArtifactType(ArtifactType.IMAGE) .build(); GetUrlForArtifact.Response getUrlForArtifactResponse = experimentRunServiceStub.getUrlForArtifact(getUrlForArtifactRequest); URL url = new URL(getUrlForArtifactResponse.getUrl()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); InputStream inputStream = connection.getInputStream(); String rootPath = System.getProperty("user.dir"); FileOutputStream fileOutputStream = new FileOutputStream(new File(rootPath + File.separator + artifactKey)); IOUtils.copy(inputStream, fileOutputStream); fileOutputStream.close(); inputStream.close(); File downloadedFile = new File(rootPath + File.separator + artifactKey); if (!downloadedFile.exists()) { fail("File not fount at download destination"); } downloadedFile.delete(); } catch (Exception e) { e.printStackTrace(); Status status = Status.fromThrowable(e); LOGGER.error( "Error Code : " + status.getCode() + " Description : " + status.getDescription()); fail(); } LOGGER.info("get artifact test stop................................"); }
Example 16
Source File: ProjectTest.java From modeldb with Apache License 2.0 | 4 votes |
@Test public void iii_deleteProjectAttributesNegativeTest() { LOGGER.info("Delete Project Attributes Negative test start................................"); ProjectServiceBlockingStub projectServiceStub = ProjectServiceGrpc.newBlockingStub(channel); DeleteProjectAttributes deleteProjectAttributesRequest = DeleteProjectAttributes.newBuilder().build(); try { projectServiceStub.deleteProjectAttributes(deleteProjectAttributesRequest); fail(); } catch (StatusRuntimeException ex) { Status status = Status.fromThrowable(ex); LOGGER.warn("Error Code : " + status.getCode() + " Description : " + status.getDescription()); assertEquals(Status.INVALID_ARGUMENT.getCode(), status.getCode()); } // Create project CreateProject createProjectRequest = getCreateProjectRequest("project_f_apt"); CreateProject.Response createProjectResponse = projectServiceStub.createProject(createProjectRequest); Project project = createProjectResponse.getProject(); LOGGER.info("Project created successfully"); assertEquals( "Project name not match with expected project name", createProjectRequest.getName(), project.getName()); deleteProjectAttributesRequest = DeleteProjectAttributes.newBuilder().setId(project.getId()).setDeleteAll(true).build(); DeleteProjectAttributes.Response response = projectServiceStub.deleteProjectAttributes(deleteProjectAttributesRequest); LOGGER.info( "All the Attributes deleted from server. Attributes count : " + response.getProject().getAttributesCount()); assertEquals(0, response.getProject().getAttributesList().size()); DeleteProject deleteProject = DeleteProject.newBuilder().setId(project.getId()).build(); DeleteProject.Response deleteProjectResponse = projectServiceStub.deleteProject(deleteProject); LOGGER.info("Project deleted successfully"); LOGGER.info(deleteProjectResponse.toString()); assertTrue(deleteProjectResponse.getStatus()); LOGGER.info("Delete Project Attributes Negative test stop................................"); }
Example 17
Source File: ExperimentTest.java From modeldb with Apache License 2.0 | 4 votes |
@Test public void d_updateExperimentNameOrDescription() { LOGGER.info("Update Experiment Name & Description test start................................"); ProjectServiceBlockingStub projectServiceStub = ProjectServiceGrpc.newBlockingStub(channel); ExperimentServiceBlockingStub experimentServiceStub = ExperimentServiceGrpc.newBlockingStub(channel); // Create project ProjectTest projectTest = new ProjectTest(); CreateProject createProjectRequest = projectTest.getCreateProjectRequest("experiment_project_n_sprt_abc"); CreateProject.Response createProjectResponse = projectServiceStub.createProject(createProjectRequest); Project project = createProjectResponse.getProject(); LOGGER.info("Project created successfully"); assertEquals( "Project name not match with expected project name", createProjectRequest.getName(), project.getName()); // Create experiment of above project CreateExperiment createExperimentRequest = getCreateExperimentRequest(project.getId(), "Experiment_n_sprt_abc"); CreateExperiment.Response createExperimentResponse = experimentServiceStub.createExperiment(createExperimentRequest); Experiment experiment = createExperimentResponse.getExperiment(); LOGGER.info("Experiment created successfully"); assertEquals( "Experiment name not match with expected Experiment name", createExperimentRequest.getName(), createExperimentResponse.getExperiment().getName()); UpdateExperimentDescription upDescriptionRequest = UpdateExperimentDescription.newBuilder() .setId(experiment.getId()) .setDescription( "This is update from UpdateExperimentDescription " + Calendar.getInstance().getTimeInMillis()) .build(); UpdateExperimentDescription.Response response = experimentServiceStub.updateExperimentDescription(upDescriptionRequest); LOGGER.info("UpdateExperimentDescription Response : " + response.getExperiment()); assertEquals( "Experiment name not match with expected experiment name", experiment.getName(), response.getExperiment().getName()); assertEquals( "Experiment description not match with expected experiment name", upDescriptionRequest.getDescription(), response.getExperiment().getDescription()); assertNotEquals( "Experiment date_updated field not update on database", experiment.getDateUpdated(), response.getExperiment().getDateUpdated()); experiment = response.getExperiment(); UpdateExperimentName updateNameRequest = UpdateExperimentName.newBuilder() .setId(experiment.getId()) .setName("Test Update Experiment Name" + Calendar.getInstance().getTimeInMillis()) .build(); UpdateExperimentName.Response updateNameResponse = experimentServiceStub.updateExperimentName(updateNameRequest); LOGGER.info("UpdateExperimentName Response : " + response.getExperiment()); assertEquals( "Experiment name not match with expected experiment name", updateNameRequest.getName(), updateNameResponse.getExperiment().getName()); assertEquals( "Experiment description not match with expected experiment name", experiment.getDescription(), response.getExperiment().getDescription()); assertNotEquals( "Experiment date_updated field not update on database", experiment.getDateUpdated(), updateNameResponse.getExperiment().getDateUpdated()); try { String name = "Experiment of Human Activity Recognition using Smartphone Dataset Human Activity Recognition using Smartphone Dataset Human Activity Recognition using Smartphone Dataset Human Activity Recognition using Smartphone Dataset Human Activity Recognition using Smartphone Dataset"; updateNameRequest = updateNameRequest.toBuilder().setName(name).build(); experimentServiceStub.updateExperimentName(updateNameRequest); fail(); } catch (StatusRuntimeException ex) { Status status = Status.fromThrowable(ex); LOGGER.warn("Error Code : " + status.getCode() + " Description : " + status.getDescription()); assertEquals(Status.INVALID_ARGUMENT.getCode(), status.getCode()); } // Delete Project DeleteProject deleteProject = DeleteProject.newBuilder().setId(project.getId()).build(); DeleteProject.Response deleteProjectResponse = projectServiceStub.deleteProject(deleteProject); LOGGER.info("Project deleted successfully"); LOGGER.info(deleteProjectResponse.toString()); assertTrue(deleteProjectResponse.getStatus()); LOGGER.info("Update Experiment Name & Description test stop................................"); }
Example 18
Source File: CommitTest.java From modeldb with Apache License 2.0 | 4 votes |
@Test public void deleteCommitWithTagsTest() throws NoSuchAlgorithmException, ModelDBException { LOGGER.info("Delete commit with tags test start................................"); VersioningServiceBlockingStub versioningServiceBlockingStub = VersioningServiceGrpc.newBlockingStub(channel); long id = createRepository(versioningServiceBlockingStub, RepositoryTest.NAME); GetBranchRequest getBranchRequest = GetBranchRequest.newBuilder() .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build()) .setBranch(ModelDBConstants.MASTER_BRANCH) .build(); GetBranchRequest.Response getBranchResponse = versioningServiceBlockingStub.getBranch(getBranchRequest); CreateCommitRequest createCommitRequest = CommitTest.getCreateCommitRequest( id, 111, getBranchResponse.getCommit(), Blob.ContentCase.DATASET); CreateCommitRequest.Response commitResponse = versioningServiceBlockingStub.createCommit(createCommitRequest); assertTrue("Commit not found in response", commitResponse.hasCommit()); String tag = "v1.0"; SetTagRequest setTagRequest = SetTagRequest.newBuilder() .setTag(tag) .setCommitSha(commitResponse.getCommit().getCommitSha()) .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build()) .build(); versioningServiceBlockingStub.setTag(setTagRequest); DeleteCommitRequest deleteCommitRequest = DeleteCommitRequest.newBuilder() .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build()) .setCommitSha(commitResponse.getCommit().getCommitSha()) .build(); try { versioningServiceBlockingStub.deleteCommit(deleteCommitRequest); } catch (StatusRuntimeException ex) { Status status = Status.fromThrowable(ex); LOGGER.warn("Error Code : " + status.getCode() + " Description : " + status.getDescription()); assertEquals(Status.FAILED_PRECONDITION.getCode(), status.getCode()); } DeleteTagRequest deleteTagRequest = DeleteTagRequest.newBuilder() .setTag(tag) .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id).build()) .build(); versioningServiceBlockingStub.deleteTag(deleteTagRequest); versioningServiceBlockingStub.deleteCommit(deleteCommitRequest); DeleteRepositoryRequest deleteRepository = DeleteRepositoryRequest.newBuilder() .setRepositoryId(RepositoryIdentification.newBuilder().setRepoId(id)) .build(); DeleteRepositoryRequest.Response deleteResult = versioningServiceBlockingStub.deleteRepository(deleteRepository); Assert.assertTrue(deleteResult.getStatus()); LOGGER.info("Delete commit with tags test end................................"); }
Example 19
Source File: ProjectTest.java From modeldb with Apache License 2.0 | 4 votes |
@Test public void nnnn_setEmptyProjectReadMeTest() throws IOException { LOGGER.info("Get Project ReadMe test start................................"); try { ProjectServiceBlockingStub projectServiceStub = ProjectServiceGrpc.newBlockingStub(channel); // Create project CreateProject createProjectRequest = getCreateProjectRequest("project_nnnn_seprt"); CreateProject.Response createProjectResponse = projectServiceStub.createProject(createProjectRequest); Project project = createProjectResponse.getProject(); LOGGER.info("\n Project created successfully \n"); assertEquals( "Project name not match with expected project name", createProjectRequest.getName(), project.getName()); String readMeText = ""; SetProjectReadme setProjectReadMe = SetProjectReadme.newBuilder().setId(project.getId()).setReadmeText(readMeText).build(); SetProjectReadme.Response response = projectServiceStub.setProjectReadme(setProjectReadMe); assertEquals( "Project ID not match with expected project ID", project.getId(), response.getProject().getId()); assertEquals( "Project ReadMe text not match with expected setProjectReadMe.md file text", readMeText, response.getProject().getReadmeText()); assertNotEquals( "Project date_updated field not update on database", project.getDateUpdated(), response.getProject().getDateUpdated()); GetProjectReadme getProjectReadMe = GetProjectReadme.newBuilder().setId(project.getId()).build(); GetProjectReadme.Response getProjectReadMeResponse = projectServiceStub.getProjectReadme(getProjectReadMe); assertEquals( "Project ReadMe text not match with expected setProjectReadMe.md file text", readMeText, getProjectReadMeResponse.getReadmeText()); // Get the file reference Path path = Paths.get("target/outputProjectReadMe.md"); try (BufferedWriter writer = Files.newBufferedWriter(path)) { writer.write(getProjectReadMeResponse.getReadmeText()); } DeleteProject deleteProject = DeleteProject.newBuilder().setId(project.getId()).build(); DeleteProject.Response deleteProjectResponse = projectServiceStub.deleteProject(deleteProject); LOGGER.info("Project deleted successfully"); LOGGER.info(deleteProjectResponse.toString()); assertTrue(deleteProjectResponse.getStatus()); } catch (StatusRuntimeException e) { Status status2 = Status.fromThrowable(e); fail(); LOGGER.info("Error Code : " + status2.getCode() + " Error : " + status2.getDescription()); } LOGGER.info("Get Project ReadMe test stop................................"); }
Example 20
Source File: DatasetTest.java From modeldb with Apache License 2.0 | 4 votes |
@Test public void deleteDatasetAttributesNegativeTest() { LOGGER.info("Delete Dataset Attributes Negative test start................................"); DatasetServiceBlockingStub datasetServiceStub = DatasetServiceGrpc.newBlockingStub(channel); DeleteDatasetAttributes deleteDatasetAttributesRequest = DeleteDatasetAttributes.newBuilder().build(); try { datasetServiceStub.deleteDatasetAttributes(deleteDatasetAttributesRequest); fail(); } catch (StatusRuntimeException ex) { Status status = Status.fromThrowable(ex); LOGGER.warn("Error Code : " + status.getCode() + " Description : " + status.getDescription()); assertEquals(Status.INVALID_ARGUMENT.getCode(), status.getCode()); } // Create dataset CreateDataset createDatasetRequest = getDatasetRequest("dataset_f_apt"); CreateDataset.Response createDatasetResponse = datasetServiceStub.createDataset(createDatasetRequest); Dataset dataset = createDatasetResponse.getDataset(); LOGGER.info("Dataset created successfully"); assertEquals( "Dataset name not match with expected dataset name", createDatasetRequest.getName(), dataset.getName()); deleteDatasetAttributesRequest = DeleteDatasetAttributes.newBuilder().setId(dataset.getId()).setDeleteAll(true).build(); DeleteDatasetAttributes.Response response = datasetServiceStub.deleteDatasetAttributes(deleteDatasetAttributesRequest); LOGGER.info( "All the Attributes deleted from server. Attributes count : " + response.getDataset().getAttributesCount()); assertEquals(0, response.getDataset().getAttributesList().size()); DeleteDataset deleteDataset = DeleteDataset.newBuilder().setId(dataset.getId()).build(); DeleteDataset.Response deleteDatasetResponse = datasetServiceStub.deleteDataset(deleteDataset); LOGGER.info("Dataset deleted successfully"); LOGGER.info(deleteDatasetResponse.toString()); assertTrue(deleteDatasetResponse.getStatus()); LOGGER.info("Delete Dataset Attributes Negative test stop................................"); }