Skip to content

Commit

Permalink
fix: change to generation script in manipulating googleapis/WORKSPACE. (
Browse files Browse the repository at this point in the history
#3120)

* fix: change to generation script in manipulating googleapis/WORKSPACE.

* fix: mocked method in test needs to change after java.time introduced in gax.

* fix: address review comment, create a custom InstantiatingGrpcChannelProvider instead of using mocks.

* chore: use mvn wrapper in shocase test ci.

* address review comments.
  • Loading branch information
zhumin8 authored Aug 14, 2024
1 parent a9ec698 commit 48e0681
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/showcaseTests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ jobs:
bash scripts/generate-showcase.sh
- name: Unit tests for showcase-spring-starter
# Runs showcase-spring-starter unit tests
working-directory: spring-cloud-generator
working-directory: spring-cloud-generator/showcase/showcase-spring-starter
run: |
cd showcase/showcase-spring-starter && mvn verify
../../../mvnw verify
2 changes: 1 addition & 1 deletion spring-cloud-generator/scripts/generate-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function modify_workspace_file(){
# delete existing maven_install rules
buildozer 'delete' ${path_to_workspace}:%maven_install
# add custom maven_install rules
perl -pi -e "s{(^_gapic_generator_java_version[^\n]*)}{\$1\n$(cat ${path_to_modification_string})}" ${path_to_workspace}
perl -pi -e "s{(^api_dependencies()[^\n]*)}{\$1\n$(cat ${path_to_modification_string})}" ${path_to_workspace}
}

# For individual library, set up bazel rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ _spring_cloud_generator_version = "5.5.1-SNAPSHOT" # {x-version-update:spring-cl

maven_install(
artifacts = [
"com.google.cloud:spring-cloud-generator:" + _spring_cloud_generator_version,
],
"com.google.cloud:spring-cloud-generator:" + _spring_cloud_generator_version,
] +
IO_GRPC_GRPC_JAVA_ARTIFACTS,
generate_compat_repositories = True,
override_targets = IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS,
#Update this False for local development
fail_on_missing_checksum = False,
repositories = [
"m2Local",
"https://repo.maven.apache.org/maven2/",
]
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
package com.google.showcase.v1beta1.spring;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.rpc.ApiCallContext;
import com.google.api.gax.rpc.TransportChannel;
Expand Down Expand Up @@ -189,27 +188,19 @@ void testExecutorThreadCountFromProperties() {

@Test
void testCustomTransportChannelProviderUsedWhenProvided() throws IOException {
when(mockTransportChannelProvider.getTransportName()).thenReturn("grpc");
when(mockTransportChannelProvider.getTransportChannel()).thenReturn(mockTransportChannel);
when(mockTransportChannel.getEmptyCallContext()).thenReturn(mockApiCallContext);
// Mock no-ops for ApiCallContext since this test only intends to verify override of
// TransportChannelProvider bean
when(mockApiCallContext.withCredentials(any())).thenReturn(mockApiCallContext);
when(mockApiCallContext.withTransportChannel(any())).thenReturn(mockApiCallContext);
when(mockApiCallContext.withStreamWaitTimeout(any())).thenReturn(mockApiCallContext);
when(mockApiCallContext.withStreamIdleTimeout(any())).thenReturn(mockApiCallContext);
when(mockApiCallContext.withEndpointContext(any())).thenReturn(mockApiCallContext);

InstantiatingGrpcChannelProvider channelProvider =
InstantiatingGrpcChannelProvider.newBuilder()
.build();
contextRunner
.withBean(
TRANSPORT_CHANNEL_PROVIDER_QUALIFIER_NAME,
TransportChannelProvider.class,
() -> mockTransportChannelProvider)
() -> channelProvider)
.run(
ctx -> {
EchoClient client = ctx.getBean(EchoClient.class);
assertThat(client.getSettings().getTransportChannelProvider())
.isSameAs(mockTransportChannelProvider);
.isSameAs(channelProvider);
});
}

Expand Down

0 comments on commit 48e0681

Please sign in to comment.