-
Notifications
You must be signed in to change notification settings - Fork 70
chore: add showcase test for server-side with gRPC transport #1502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
eb55bfb
chore: add simple unary callable showcase test for gRPC support
mpeddada1 5c07488
install maven modules before calling bazelisk
mpeddada1 61c0ed5
undo previous commit
mpeddada1 33f10a8
use truth
mpeddada1 911d546
chore: add server side streaming showcase integration test for gRPC t…
mpeddada1 989eb78
chore: add test for server-side streaming with gRPC transport
mpeddada1 039dedc
and test for server error
mpeddada1 f945c07
fix spacing
mpeddada1 9b1c146
rebase with main
mpeddada1 43ef73b
add header
mpeddada1 6932e88
remove http json setup code
mpeddada1 2e534b7
apply formatting
mpeddada1 ec9255f
fix compilation error
mpeddada1 fc7da86
use non-static and make assertion stricter
mpeddada1 01d81d7
formatter
mpeddada1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
...se/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITServerSideStreaming.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Copyright 2023 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.showcase.v1beta1.it; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
| import static org.junit.Assert.assertThrows; | ||
|
|
||
| import com.google.api.gax.core.NoCredentialsProvider; | ||
| import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; | ||
| import com.google.api.gax.rpc.CancelledException; | ||
| import com.google.api.gax.rpc.ServerStream; | ||
| import com.google.api.gax.rpc.StatusCode; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.rpc.Status; | ||
| import com.google.showcase.v1beta1.EchoClient; | ||
| import com.google.showcase.v1beta1.EchoResponse; | ||
| import com.google.showcase.v1beta1.EchoSettings; | ||
| import com.google.showcase.v1beta1.ExpandRequest; | ||
| import io.grpc.ManagedChannelBuilder; | ||
| import java.io.IOException; | ||
| import java.security.GeneralSecurityException; | ||
| import java.util.ArrayList; | ||
| import java.util.Iterator; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| public class ITServerSideStreaming { | ||
|
|
||
| private EchoClient grpcClient; | ||
|
|
||
| @Before | ||
| public void createClients() throws IOException, GeneralSecurityException { | ||
| // Create gRPC Echo Client | ||
| EchoSettings grpcEchoSettings = | ||
| EchoSettings.newBuilder() | ||
| .setCredentialsProvider(NoCredentialsProvider.create()) | ||
| .setTransportChannelProvider( | ||
| InstantiatingGrpcChannelProvider.newBuilder() | ||
| .setChannelConfigurator(ManagedChannelBuilder::usePlaintext) | ||
| .build()) | ||
| .build(); | ||
| grpcClient = EchoClient.create(grpcEchoSettings); | ||
| } | ||
|
|
||
| @After | ||
| public void destroyClient() { | ||
| grpcClient.close(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGrpc_receiveStreamedContent() { | ||
| String content = "The rain in Spain stays mainly on the plain!"; | ||
| ServerStream<EchoResponse> responseStream = | ||
| grpcClient.expandCallable().call(ExpandRequest.newBuilder().setContent(content).build()); | ||
| ArrayList<String> responses = new ArrayList<>(); | ||
| for (EchoResponse response : responseStream) { | ||
| responses.add(response.getContent()); | ||
| } | ||
|
|
||
| assertThat(responses) | ||
| .containsExactlyElementsIn( | ||
| ImmutableList.of( | ||
| "The", "rain", "in", "Spain", "stays", "mainly", "on", "the", "plain!")) | ||
| .inOrder(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGrpc_serverError_receiveErrorAfterLastWordInStream() { | ||
| String content = "The rain in Spain"; | ||
| Status cancelledStatus = | ||
| Status.newBuilder().setCode(StatusCode.Code.CANCELLED.ordinal()).build(); | ||
| ServerStream<EchoResponse> responseStream = | ||
| grpcClient | ||
| .expandCallable() | ||
| .call(ExpandRequest.newBuilder().setContent(content).setError(cancelledStatus).build()); | ||
| Iterator<EchoResponse> echoResponseIterator = responseStream.iterator(); | ||
|
|
||
| assertThat(echoResponseIterator.next().getContent()).isEqualTo("The"); | ||
| assertThat(echoResponseIterator.next().getContent()).isEqualTo("rain"); | ||
| assertThat(echoResponseIterator.next().getContent()).isEqualTo("in"); | ||
| assertThat(echoResponseIterator.next().getContent()).isEqualTo("Spain"); | ||
| CancelledException cancelledException = | ||
| assertThrows(CancelledException.class, echoResponseIterator::next); | ||
| assertThat(cancelledException.getStatusCode().getCode()).isEqualTo(StatusCode.Code.CANCELLED); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.