Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d8c62d

Browse files
authored
fix: Support PubSub's _deleted-topic_ pattern (#739)
1 parent 842d7a3 commit 7d8c62d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+17187
-39
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
run: bazel --batch test $(bazel query "//src/test/..." | grep "Test$") --noshow_progress
5050

5151
- name: Integration Tests
52-
run: bazel --batch test //test/integration:asset //test/integration:credentials //test/integration:iam //test/integration:kms //test/integration:logging //test/integration:redis //test/integration:library --noshow_progress
52+
run: bazel --batch test //test/integration:asset //test/integration:credentials //test/integration:iam //test/integration:kms //test/integration:logging //test/integration:pubsub //test/integration:redis //test/integration:library --noshow_progress
5353

5454
- uses: actions/upload-artifact@v2
5555
if: ${{ failure() }}

src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameHelperClassComposer.java

Lines changed: 200 additions & 38 deletions
Large diffs are not rendered by default.

src/main/java/com/google/api/generator/gapic/composer/resourcename/ResourceNameTokenizer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.api.generator.gapic.composer.resourcename;
1616

17+
import com.google.api.generator.gapic.utils.ResourceNameConstants;
1718
import com.google.api.pathtemplate.PathTemplate;
1819
import com.google.common.base.Preconditions;
1920
import java.util.ArrayList;
@@ -42,6 +43,12 @@ public static List<List<String>> parseTokenHierarchy(List<String> patterns) {
4243

4344
// Process variables.
4445
for (String rawPatternToken : rawPatternTokens) {
46+
// PubSub exception case.
47+
if (rawPatternToken.equals(ResourceNameConstants.DELETED_TOPIC_LITERAL)) {
48+
hierarchy.add(rawPatternToken);
49+
continue;
50+
}
51+
4552
if (!rawPatternToken.startsWith(LEFT_BRACE) || !rawPatternToken.endsWith(RIGHT_BRACE)) {
4653
continue;
4754
}

src/main/java/com/google/api/generator/gapic/utils/JavaStyle.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public static String toLowerCamelCase(String s) {
2626
return s;
2727
}
2828

29+
s = s.replace('-', '_');
30+
2931
if (s.indexOf(UNDERSCORE) >= 0) {
3032
s = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, s);
3133
}
@@ -39,6 +41,8 @@ public static String toUpperCamelCase(String s) {
3941
return s;
4042
}
4143

44+
s = s.replace('-', '_');
45+
4246
if (s.indexOf(UNDERSCORE) >= 0) {
4347
s = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, s);
4448
}

test/integration/BUILD.bazel

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ INTEGRATION_TEST_LIBRARIES = [
2525
"credentials", # Check that the capital name edge case is handled.
2626
"iam", # Mixin-only special-case API can build on its own.
2727
"kms", # Mixins, with an override in the proto file.
28+
"pubsub", # Special=case handling for "_deleted-topic_" resource name patterns.
2829
"logging", # Java package remapping in gapic.yaml.
2930
"redis", # Has a gapic.yaml.
3031
"library", # No gRPC service config.
@@ -36,6 +37,7 @@ API_GAPIC_TARGETS = {
3637
"credentials": "@com_google_googleapis//google/iam/credentials/v1:credentials_java_gapic",
3738
"iam": ":iam_java_gapic", # Googleapis' LRO does not have a Java Gapic.
3839
"kms": ":kms_java_gapic", # Local target because mixins are not rolled out yet.
40+
"pubsub": ":pubsub_java_gapic",
3941
"logging": "@com_google_googleapis//google/logging/v2:logging_java_gapic",
4042
"redis": "@com_google_googleapis//google/cloud/redis/v1beta1:redis_java_gapic",
4143
"library": "@com_google_googleapis//google/example/library/v1:library_java_gapic",
@@ -274,3 +276,41 @@ java_gapic_assembly_gradle_pkg(
274276
"@com_google_googleapis//google/cloud/location:location_java_proto",
275277
],
276278
)
279+
280+
# PubSub
281+
# TODO: Remove some of these targets when PubSub has been migrated in googleapis.
282+
java_gapic_library(
283+
name = "pubsub_java_gapic",
284+
srcs = ["@com_google_googleapis//google/pubsub/v1:pubsub_proto_with_info"],
285+
gapic_yaml = "@com_google_googleapis//google/pubsub/v1:pubsub_gapic.yaml",
286+
grpc_service_config = "@com_google_googleapis//google/pubsub/v1:pubsub_grpc_service_config.json",
287+
# For the IAM mixin.
288+
service_yaml = "pubsub_v1.yaml",
289+
test_deps = [
290+
"@com_google_googleapis//google/pubsub/v1:pubsub_java_grpc",
291+
"@com_google_googleapis//google/iam/v1:iam_java_grpc",
292+
],
293+
deps = [
294+
"@com_google_googleapis//google/iam/v1:iam_java_proto",
295+
"@com_google_googleapis//google/pubsub/v1:pubsub_java_proto",
296+
],
297+
)
298+
299+
java_gapic_test(
300+
name = "pubsub_java_gapic_test_suite",
301+
test_classes = [
302+
"com.google.cloud.pubsub.v1.SubscriptionAdminClientTest",
303+
"com.google.cloud.pubsub.v1.TopicAdminClientTest",
304+
],
305+
runtime_deps = [":pubsub_java_gapic_test"],
306+
)
307+
308+
java_gapic_assembly_gradle_pkg(
309+
name = "google-cloud-pubsub-v1-java",
310+
deps = [
311+
":pubsub_java_gapic",
312+
"@com_google_googleapis//google/pubsub/v1:pubsub_java_grpc",
313+
"@com_google_googleapis//google/pubsub/v1:pubsub_java_proto",
314+
"@com_google_googleapis//google/pubsub/v1:pubsub_proto",
315+
],
316+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
filegroup(
4+
name = "goldens_files",
5+
srcs = glob([
6+
"*.java",
7+
"gapic_metadata.json",
8+
]),
9+
)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.pubsub.v1;
18+
19+
import com.google.api.core.BetaApi;
20+
import com.google.api.gax.grpc.testing.MockGrpcService;
21+
import com.google.protobuf.AbstractMessage;
22+
import io.grpc.ServerServiceDefinition;
23+
import java.util.List;
24+
import javax.annotation.Generated;
25+
26+
@BetaApi
27+
@Generated("by gapic-generator-java")
28+
public class MockIAMPolicy implements MockGrpcService {
29+
private final MockIAMPolicyImpl serviceImpl;
30+
31+
public MockIAMPolicy() {
32+
serviceImpl = new MockIAMPolicyImpl();
33+
}
34+
35+
@Override
36+
public List<AbstractMessage> getRequests() {
37+
return serviceImpl.getRequests();
38+
}
39+
40+
@Override
41+
public void addResponse(AbstractMessage response) {
42+
serviceImpl.addResponse(response);
43+
}
44+
45+
@Override
46+
public void addException(Exception exception) {
47+
serviceImpl.addException(exception);
48+
}
49+
50+
@Override
51+
public ServerServiceDefinition getServiceDefinition() {
52+
return serviceImpl.bindService();
53+
}
54+
55+
@Override
56+
public void reset() {
57+
serviceImpl.reset();
58+
}
59+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.pubsub.v1;
18+
19+
import com.google.api.core.BetaApi;
20+
import com.google.iam.v1.GetIamPolicyRequest;
21+
import com.google.iam.v1.IAMPolicyGrpc.IAMPolicyImplBase;
22+
import com.google.iam.v1.Policy;
23+
import com.google.iam.v1.SetIamPolicyRequest;
24+
import com.google.iam.v1.TestIamPermissionsRequest;
25+
import com.google.iam.v1.TestIamPermissionsResponse;
26+
import com.google.protobuf.AbstractMessage;
27+
import io.grpc.stub.StreamObserver;
28+
import java.util.ArrayList;
29+
import java.util.LinkedList;
30+
import java.util.List;
31+
import java.util.Queue;
32+
import javax.annotation.Generated;
33+
34+
@BetaApi
35+
@Generated("by gapic-generator-java")
36+
public class MockIAMPolicyImpl extends IAMPolicyImplBase {
37+
private List<AbstractMessage> requests;
38+
private Queue<Object> responses;
39+
40+
public MockIAMPolicyImpl() {
41+
requests = new ArrayList<>();
42+
responses = new LinkedList<>();
43+
}
44+
45+
public List<AbstractMessage> getRequests() {
46+
return requests;
47+
}
48+
49+
public void addResponse(AbstractMessage response) {
50+
responses.add(response);
51+
}
52+
53+
public void setResponses(List<AbstractMessage> responses) {
54+
this.responses = new LinkedList<Object>(responses);
55+
}
56+
57+
public void addException(Exception exception) {
58+
responses.add(exception);
59+
}
60+
61+
public void reset() {
62+
requests = new ArrayList<>();
63+
responses = new LinkedList<>();
64+
}
65+
66+
@Override
67+
public void setIamPolicy(SetIamPolicyRequest request, StreamObserver<Policy> responseObserver) {
68+
Object response = responses.poll();
69+
if (response instanceof Policy) {
70+
requests.add(request);
71+
responseObserver.onNext(((Policy) response));
72+
responseObserver.onCompleted();
73+
} else if (response instanceof Exception) {
74+
responseObserver.onError(((Exception) response));
75+
} else {
76+
responseObserver.onError(
77+
new IllegalArgumentException(
78+
String.format(
79+
"Unrecognized response type %s for method SetIamPolicy, expected %s or %s",
80+
response == null ? "null" : response.getClass().getName(),
81+
Policy.class.getName(),
82+
Exception.class.getName())));
83+
}
84+
}
85+
86+
@Override
87+
public void getIamPolicy(GetIamPolicyRequest request, StreamObserver<Policy> responseObserver) {
88+
Object response = responses.poll();
89+
if (response instanceof Policy) {
90+
requests.add(request);
91+
responseObserver.onNext(((Policy) response));
92+
responseObserver.onCompleted();
93+
} else if (response instanceof Exception) {
94+
responseObserver.onError(((Exception) response));
95+
} else {
96+
responseObserver.onError(
97+
new IllegalArgumentException(
98+
String.format(
99+
"Unrecognized response type %s for method GetIamPolicy, expected %s or %s",
100+
response == null ? "null" : response.getClass().getName(),
101+
Policy.class.getName(),
102+
Exception.class.getName())));
103+
}
104+
}
105+
106+
@Override
107+
public void testIamPermissions(
108+
TestIamPermissionsRequest request,
109+
StreamObserver<TestIamPermissionsResponse> responseObserver) {
110+
Object response = responses.poll();
111+
if (response instanceof TestIamPermissionsResponse) {
112+
requests.add(request);
113+
responseObserver.onNext(((TestIamPermissionsResponse) response));
114+
responseObserver.onCompleted();
115+
} else if (response instanceof Exception) {
116+
responseObserver.onError(((Exception) response));
117+
} else {
118+
responseObserver.onError(
119+
new IllegalArgumentException(
120+
String.format(
121+
"Unrecognized response type %s for method TestIamPermissions, expected %s or %s",
122+
response == null ? "null" : response.getClass().getName(),
123+
TestIamPermissionsResponse.class.getName(),
124+
Exception.class.getName())));
125+
}
126+
}
127+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.pubsub.v1;
18+
19+
import com.google.api.core.BetaApi;
20+
import com.google.api.gax.grpc.testing.MockGrpcService;
21+
import com.google.protobuf.AbstractMessage;
22+
import io.grpc.ServerServiceDefinition;
23+
import java.util.List;
24+
import javax.annotation.Generated;
25+
26+
@BetaApi
27+
@Generated("by gapic-generator-java")
28+
public class MockPublisher implements MockGrpcService {
29+
private final MockPublisherImpl serviceImpl;
30+
31+
public MockPublisher() {
32+
serviceImpl = new MockPublisherImpl();
33+
}
34+
35+
@Override
36+
public List<AbstractMessage> getRequests() {
37+
return serviceImpl.getRequests();
38+
}
39+
40+
@Override
41+
public void addResponse(AbstractMessage response) {
42+
serviceImpl.addResponse(response);
43+
}
44+
45+
@Override
46+
public void addException(Exception exception) {
47+
serviceImpl.addException(exception);
48+
}
49+
50+
@Override
51+
public ServerServiceDefinition getServiceDefinition() {
52+
return serviceImpl.bindService();
53+
}
54+
55+
@Override
56+
public void reset() {
57+
serviceImpl.reset();
58+
}
59+
}

0 commit comments

Comments
 (0)