Skip to content

Commit

Permalink
Merge branch 'main' into fix/handling-invalid-protocol-buffer-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeseung-bae committed Apr 4, 2024
2 parents 0f2f8e9 + 89c7cf4 commit f513257
Show file tree
Hide file tree
Showing 28 changed files with 1,327 additions and 1,424 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void getBlogPost() throws JsonProcessingException {
}

@Test
@Order(2)
@Order(3)
void getInvalidBlogPost() throws JsonProcessingException {
final Throwable exception = catchThrowable(() -> {
client.getBlogPost(GetBlogPostRequest.newBuilder().setId(Integer.MAX_VALUE).build());
Expand All @@ -95,7 +95,7 @@ void getInvalidBlogPost() throws JsonProcessingException {
}

@Test
@Order(3)
@Order(4)
void listBlogPosts() throws JsonProcessingException {
final CreateBlogPostRequest newBlogPost = CreateBlogPostRequest.newBuilder()
.setTitle("My second blog")
Expand All @@ -119,7 +119,7 @@ void listBlogPosts() throws JsonProcessingException {
}

@Test
@Order(4)
@Order(5)
void updateBlogPosts() throws JsonProcessingException {
final UpdateBlogPostRequest request = UpdateBlogPostRequest.newBuilder()
.setId(0)
Expand All @@ -133,7 +133,40 @@ void updateBlogPosts() throws JsonProcessingException {
}

@Test
@Order(5)
@Order(6)
void updateInvalidBlogPost() {
final Throwable exception = catchThrowable(() -> {
client.updateBlogPost(UpdateBlogPostRequest.newBuilder()
.setId(Integer.MAX_VALUE)
.setTitle("My first blog")
.setContent("Hello awesome Armeria!")
.build());
});
final StatusRuntimeException statusException = (StatusRuntimeException) exception;
assertThat(statusException.getStatus().getCode()).isEqualTo(Code.NOT_FOUND);
assertThat(statusException)
.hasMessageContaining("The blog post does not exist. ID: " + Integer.MAX_VALUE);
}

@Test
@Order(7)
void deleteBlogPost() {
final DeleteBlogPostRequest request = DeleteBlogPostRequest.newBuilder()
.setId(1)
.build();
client.deleteBlogPost(request);
final Throwable exception = catchThrowable(() -> {
client.getBlogPost(GetBlogPostRequest.newBuilder().setId(1).build());
});

final StatusRuntimeException statusException = (StatusRuntimeException) exception;
assertThat(statusException.getStatus().getCode()).isEqualTo(Code.NOT_FOUND);
assertThat(statusException)
.hasMessageContaining("The blog post does not exist. ID: 1");
}

@Test
@Order(8)
void badRequestExceptionHandlerWhenTryingDeleteMissingBlogPost() throws JsonProcessingException {
final Throwable exception = catchThrowable(() -> {
client.deleteBlogPost(DeleteBlogPostRequest.newBuilder().setId(100).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class BlogServiceTest {
@Override
protected void configure(ServerBuilder sb) throws Exception {
sb.service("/thrift", THttpService.builder()
.exceptionHandler(new BlogServiceExceptionHandler())
.addService(new BlogServiceImpl())
.exceptionHandler(new BlogServiceExceptionHandler())
.build());
}
};
Expand All @@ -41,7 +41,6 @@ void createBlogPost() throws TException {
assertThat(response.getId()).isGreaterThanOrEqualTo(0);
assertThat(response.getTitle()).isEqualTo("My first blog");
assertThat(response.getContent()).isEqualTo("Hello Armeria!");
System.out.println(response);
}

@Test
Expand All @@ -52,7 +51,6 @@ void getBlogPost() throws TException {

assertThat(blogPost.getTitle()).isEqualTo("My first blog");
assertThat(blogPost.getContent()).isEqualTo("Hello Armeria!");
System.out.println(blogPost);
}

@Test
Expand Down Expand Up @@ -83,7 +81,6 @@ void listBlogPosts() throws TException {
final BlogPost secondBlog = blogs.get(1);
assertThat(secondBlog.getTitle()).isEqualTo("My second blog");
assertThat(secondBlog.getContent()).isEqualTo("Armeria is awesome!");
System.out.println(blogs);
}

@Test
Expand All @@ -94,7 +91,6 @@ void updateBlogPosts() throws TException {
assertThat(updated.getId()).isZero();
assertThat(updated.getTitle()).isEqualTo("My first blog");
assertThat(updated.getContent()).isEqualTo("Hello awesome Armeria!");
System.out.println(updated);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/docs/client-timeouts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You can override the properties defined in <type://RequestOptions> at request le
using <type://WebClient#prepare()>.

```java
import com.linecopr.armeria.client.WebClient;
import com.linecorp.armeria.client.WebClient;

WebClient client = WebClient.of("http://example.com");
client.prepare()
Expand Down
121 changes: 0 additions & 121 deletions site/src/pages/tutorials/grpc/blog/add-docservice.mdx

This file was deleted.

27 changes: 16 additions & 11 deletions site/src/pages/tutorials/grpc/blog/define-service.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
menuTitle: "Define service"
menuTitle: "Define a service"
order: 1
type: step
targetLang: java
Expand All @@ -11,6 +11,10 @@ Let's begin by defining our gRPC blog service in a proto file.

<TutorialSteps current={1} />

## What you need

No preparation is required for this step. Do check that you've prepared the [prerequisites](/tutorials/grpc/blog/#prerequisites).

## 1. Create a proto file

Create a file, `blog.proto` inside the directory, `{project_root}/src/main/proto`. This tutorial uses [Protocol Buffers version 3](https://developers.google.com/protocol-buffers/docs/proto3).
Expand All @@ -23,6 +27,12 @@ option java_package = "example.armeria.blog.grpc";
option java_multiple_files = true;
```

<Tip>

See [Sample service structure](/tutorials/grpc/blog#sample-service) for the overall folder structure.

</Tip>

## 2. Define a blog post

In the proto file, define the `BlogPost` message type with minimal data.
Expand Down Expand Up @@ -88,7 +98,7 @@ message DeleteBlogPostRequest {
}
```

## 5. Add response type
## 5. Add a response type

Add a response type to return multiple blog posts.

Expand All @@ -98,24 +108,19 @@ message ListBlogPostsResponse {
}
```

## 6. Compile proto file
## 6. Compile the proto file

Compile the `blog.proto` file to generate Java code.
You can refer to the full [build.gradle](https://github.com/line/armeria-examples/tree/main/tutorials/grpc/build.gradle) file for generating code with [protobuf-gradle-plugin](https://github.com/google/protobuf-gradle-plugin).

```bash
./gradlew generateProto
```

<Tip>

Please refer to [build.gradle](https://github.com/line/armeria-examples/blob/main/tutorials/grpc/build.gradle) for generating code with [Protobuf Plugin for Gradle](https://github.com/google/protobuf-gradle-plugin).

</Tip>

Find the Java code output in the directory, `{project_root}/build/generated/source/proto/main`.
You'll see the generated Java code in the `{project_root}/build/generated/source/proto/main` folder.

## Next step

In this step, we've defined a proto file for our service and generated Java code. Next, we'll implement a minimal blog service and a client to [test run](/tutorials/grpc/blog/run-service).
In this step, we've defined a proto file for our service and generated Java code. Next, we'll [run a service](/tutorials/grpc/blog/run-service) and test the connection.

<TutorialSteps current={1} />

0 comments on commit f513257

Please sign in to comment.