Skip to content

Commit 27fd252

Browse files
authored
test(generator): rename test service and proto to MediaService and add GetMediaMetadata method (#14440)
Previously we'd checked in a copy of `resumable_upload.proto` from showcase to be used in generator unit tests for resumable uploads. This was confusing because - there's only one method listed in the proto, which revealed some generator edge cases e.g. for test class generation - the name triggered awkward class names like "HttpJsonResumableUploadServiceResumableUploadStub" This PR changes the test proto to `media.proto`, the service to `MediaService`, and adds a `GetMediaMetadata` method, with the intention to make diffs/testing for future changes more understandable.
1 parent 8a123d9 commit 27fd252

27 files changed

Lines changed: 1017 additions & 561 deletions

‎sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ enum SelectiveGapicType {
139139
static final ImmutableList<Pattern> RESUMABLE_UPLOAD_ALLOWLIST_PATTERNS =
140140
ImmutableList.of(
141141
Pattern.compile("^google\\.showcase\\.v1beta1\\.ResumableUploadService\\.UploadMedia$"),
142+
// For generator unit tests only; not an implemented service.
143+
Pattern.compile("^google\\.showcase\\.v1beta1\\.MediaService\\.UploadMedia$"),
142144
Pattern.compile(
143145
"^google\\.ads\\.googleads\\.v\\d+\\.services\\.YouTubeVideoUploadService\\.CreateYouTubeVideoUpload$"));
144146

‎sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/GrpcServiceStubClassComposerTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void generateGrpcServiceStubClass_resumableUpload() {
129129
Service service = context.services().get(0);
130130
GapicClass clazz = GrpcServiceStubClassComposer.instance().generate(context, service);
131131

132-
Assert.assertGoldenClass(this.getClass(), clazz, "GrpcResumableUploadServiceStub.golden");
132+
Assert.assertGoldenClass(this.getClass(), clazz, "GrpcMediaServiceStub.golden");
133133
Assert.assertEmptySamples(clazz.samples());
134134
}
135135
}

‎sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceClientClassComposerTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private static Stream<Arguments> data() {
6666
"v1beta1",
6767
1),
6868
Arguments.of(
69-
"ResumableUploadServiceClient",
69+
"MediaServiceClient",
7070
GrpcTestProtoLoader.instance().parseShowcaseResumableUpload(),
7171
"localhost:7469",
7272
"v1beta1",

‎sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceSettingsClassComposerTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static Stream<Arguments> data() {
4747
"v1beta1",
4848
1),
4949
Arguments.of(
50-
"ResumableUploadServiceSettings",
50+
"MediaServiceSettings",
5151
TestProtoLoader.instance().parseShowcaseResumableUpload(),
5252
"localhost:7469",
5353
"v1beta1",

‎sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubClassComposerTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static Stream<Arguments> data() {
4141
"",
4242
1),
4343
Arguments.of(
44-
"ResumableUploadServiceStub",
44+
"MediaServiceStub",
4545
TestProtoLoader.instance().parseShowcaseResumableUpload(),
4646
"",
4747
"",

‎sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/ServiceStubSettingsClassComposerTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static Stream<Arguments> data() {
7070
"v2",
7171
0),
7272
Arguments.of(
73-
"ResumableUploadServiceStubSettings",
73+
"MediaServiceStubSettings",
7474
GrpcTestProtoLoader.instance().parseShowcaseResumableUpload(),
7575
"localhost:7469",
7676
"v1beta1",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package com.google.showcase.v1beta1.stub;
2+
3+
import com.google.api.core.BetaApi;
4+
import com.google.api.gax.core.BackgroundResource;
5+
import com.google.api.gax.core.BackgroundResourceAggregation;
6+
import com.google.api.gax.grpc.GrpcCallSettings;
7+
import com.google.api.gax.grpc.GrpcStubCallableFactory;
8+
import com.google.api.gax.rpc.ClientContext;
9+
import com.google.api.gax.rpc.ResumableUploadCallable;
10+
import com.google.api.gax.rpc.UnaryCallable;
11+
import com.google.common.collect.ImmutableList;
12+
import com.google.longrunning.stub.GrpcOperationsStub;
13+
import com.google.showcase.v1beta1.GetMediaMetadataRequest;
14+
import com.google.showcase.v1beta1.GetMediaMetadataResponse;
15+
import com.google.showcase.v1beta1.UploadMediaRequest;
16+
import com.google.showcase.v1beta1.UploadMediaResponse;
17+
import io.grpc.MethodDescriptor;
18+
import io.grpc.protobuf.ProtoUtils;
19+
import java.io.IOException;
20+
import java.util.concurrent.TimeUnit;
21+
import javax.annotation.Generated;
22+
import org.jspecify.annotations.NullMarked;
23+
24+
// AUTO-GENERATED DOCUMENTATION AND CLASS.
25+
/**
26+
* gRPC stub implementation for the MediaService service API.
27+
*
28+
* <p>This class is for advanced usage and reflects the underlying API directly.
29+
*/
30+
@NullMarked
31+
@BetaApi
32+
@Generated("by gapic-generator-java")
33+
public class GrpcMediaServiceStub extends MediaServiceStub {
34+
private static final MethodDescriptor<GetMediaMetadataRequest, GetMediaMetadataResponse>
35+
getMediaMetadataMethodDescriptor =
36+
MethodDescriptor.<GetMediaMetadataRequest, GetMediaMetadataResponse>newBuilder()
37+
.setType(MethodDescriptor.MethodType.UNARY)
38+
.setFullMethodName("google.showcase.v1beta1.MediaService/GetMediaMetadata")
39+
.setRequestMarshaller(
40+
ProtoUtils.marshaller(GetMediaMetadataRequest.getDefaultInstance()))
41+
.setResponseMarshaller(
42+
ProtoUtils.marshaller(GetMediaMetadataResponse.getDefaultInstance()))
43+
.setSampledToLocalTracing(true)
44+
.build();
45+
46+
private final UnaryCallable<GetMediaMetadataRequest, GetMediaMetadataResponse>
47+
getMediaMetadataCallable;
48+
49+
private final BackgroundResource backgroundResources;
50+
private final GrpcOperationsStub operationsStub;
51+
private final HttpJsonMediaServiceResumableUploadStub resumableUploadStub;
52+
private final GrpcStubCallableFactory callableFactory;
53+
54+
public static final GrpcMediaServiceStub create(MediaServiceStubSettings settings)
55+
throws IOException {
56+
return new GrpcMediaServiceStub(settings, ClientContext.create(settings));
57+
}
58+
59+
public static final GrpcMediaServiceStub create(ClientContext clientContext) throws IOException {
60+
return new GrpcMediaServiceStub(MediaServiceStubSettings.newBuilder().build(), clientContext);
61+
}
62+
63+
public static final GrpcMediaServiceStub create(
64+
ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
65+
return new GrpcMediaServiceStub(
66+
MediaServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
67+
}
68+
69+
/**
70+
* Constructs an instance of GrpcMediaServiceStub, using the given settings. This is protected so
71+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
72+
* preferred.
73+
*/
74+
protected GrpcMediaServiceStub(MediaServiceStubSettings settings, ClientContext clientContext)
75+
throws IOException {
76+
this(settings, clientContext, new GrpcMediaServiceCallableFactory());
77+
}
78+
79+
/**
80+
* Constructs an instance of GrpcMediaServiceStub, using the given settings. This is protected so
81+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
82+
* preferred.
83+
*/
84+
protected GrpcMediaServiceStub(
85+
MediaServiceStubSettings settings,
86+
ClientContext clientContext,
87+
GrpcStubCallableFactory callableFactory)
88+
throws IOException {
89+
this.callableFactory = callableFactory;
90+
this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
91+
92+
GrpcCallSettings<GetMediaMetadataRequest, GetMediaMetadataResponse>
93+
getMediaMetadataTransportSettings =
94+
GrpcCallSettings.<GetMediaMetadataRequest, GetMediaMetadataResponse>newBuilder()
95+
.setMethodDescriptor(getMediaMetadataMethodDescriptor)
96+
.build();
97+
98+
this.getMediaMetadataCallable =
99+
callableFactory.createUnaryCallable(
100+
getMediaMetadataTransportSettings, settings.getMediaMetadataSettings(), clientContext);
101+
102+
this.resumableUploadStub = HttpJsonMediaServiceResumableUploadStub.create(settings);
103+
104+
this.backgroundResources =
105+
new BackgroundResourceAggregation(
106+
ImmutableList.<BackgroundResource>builder()
107+
.addAll(clientContext.getBackgroundResources())
108+
.add(resumableUploadStub)
109+
.build());
110+
}
111+
112+
public GrpcOperationsStub getOperationsStub() {
113+
return operationsStub;
114+
}
115+
116+
@Override
117+
public UnaryCallable<GetMediaMetadataRequest, GetMediaMetadataResponse>
118+
getMediaMetadataCallable() {
119+
return getMediaMetadataCallable;
120+
}
121+
122+
@Override
123+
public ResumableUploadCallable<UploadMediaRequest, UploadMediaResponse> uploadMediaCallable() {
124+
return resumableUploadStub.uploadMediaCallable();
125+
}
126+
127+
@Override
128+
public final void close() {
129+
try {
130+
backgroundResources.close();
131+
} catch (RuntimeException e) {
132+
throw e;
133+
} catch (Exception e) {
134+
throw new IllegalStateException("Failed to close resource", e);
135+
}
136+
}
137+
138+
@Override
139+
public void shutdown() {
140+
backgroundResources.shutdown();
141+
}
142+
143+
@Override
144+
public boolean isShutdown() {
145+
return backgroundResources.isShutdown();
146+
}
147+
148+
@Override
149+
public boolean isTerminated() {
150+
return backgroundResources.isTerminated();
151+
}
152+
153+
@Override
154+
public void shutdownNow() {
155+
backgroundResources.shutdownNow();
156+
}
157+
158+
@Override
159+
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
160+
return backgroundResources.awaitTermination(duration, unit);
161+
}
162+
}

‎sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/GrpcResumableUploadServiceStub.golden‎

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)