Skip to content

Commit 2ce9f42

Browse files
authored
fix: Routing annotation was not recognized on parsing protos (#928)
Routing annotation was not recognized on parsing protos, this is due to RoutingProto's extensions are not registered. This also indicate that we are missing integration tests for the new routing annotation, hence added bigtable to integration tests as well.
1 parent 0940f46 commit 2ce9f42

28 files changed

+4563
-19
lines changed

repositories.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def gapic_generator_java_repositories():
5959
_maybe(
6060
http_archive,
6161
name = "com_google_googleapis",
62-
strip_prefix = "googleapis-0899ba0f4c053a4487ccf0b699df5f850e39a45f",
62+
strip_prefix = "googleapis-44d6bef0ca6db8bba3fb324c8186e694bcc4829c",
6363
urls = [
64-
"https://github.com/googleapis/googleapis/archive/0899ba0f4c053a4487ccf0b699df5f850e39a45f.zip",
64+
"https://github.com/googleapis/googleapis/archive/44d6bef0ca6db8bba3fb324c8186e694bcc4829c.zip",
6565
],
6666
)
6767

src/main/java/com/google/api/generator/ProtoRegistry.java

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.google.api.ClientProto;
1919
import com.google.api.FieldBehaviorProto;
2020
import com.google.api.ResourceProto;
21+
import com.google.api.RoutingProto;
2122
import com.google.cloud.ExtendedOperationsProto;
2223
import com.google.longrunning.OperationsProto;
2324
import com.google.protobuf.ExtensionRegistry;
@@ -31,5 +32,6 @@ public static void registerAllExtensions(ExtensionRegistry extensionRegistry) {
3132
ResourceProto.registerAllExtensions(extensionRegistry);
3233
FieldBehaviorProto.registerAllExtensions(extensionRegistry);
3334
ExtendedOperationsProto.registerAllExtensions(extensionRegistry);
35+
RoutingProto.registerAllExtensions(extensionRegistry);
3436
}
3537
}

src/test/java/com/google/api/generator/gapic/composer/grpc/goldens/SubscriberClientTest.golden

+11
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class SubscriberClientTest {
8888
.setDeadLetterPolicy(DeadLetterPolicy.newBuilder().build())
8989
.setRetryPolicy(RetryPolicy.newBuilder().build())
9090
.setDetached(true)
91+
.setEnableExactlyOnceDelivery(true)
9192
.build();
9293
mockSubscriber.addResponse(expectedResponse);
9394

@@ -147,6 +148,7 @@ public class SubscriberClientTest {
147148
.setDeadLetterPolicy(DeadLetterPolicy.newBuilder().build())
148149
.setRetryPolicy(RetryPolicy.newBuilder().build())
149150
.setDetached(true)
151+
.setEnableExactlyOnceDelivery(true)
150152
.build();
151153
mockSubscriber.addResponse(expectedResponse);
152154

@@ -206,6 +208,7 @@ public class SubscriberClientTest {
206208
.setDeadLetterPolicy(DeadLetterPolicy.newBuilder().build())
207209
.setRetryPolicy(RetryPolicy.newBuilder().build())
208210
.setDetached(true)
211+
.setEnableExactlyOnceDelivery(true)
209212
.build();
210213
mockSubscriber.addResponse(expectedResponse);
211214

@@ -265,6 +268,7 @@ public class SubscriberClientTest {
265268
.setDeadLetterPolicy(DeadLetterPolicy.newBuilder().build())
266269
.setRetryPolicy(RetryPolicy.newBuilder().build())
267270
.setDetached(true)
271+
.setEnableExactlyOnceDelivery(true)
268272
.build();
269273
mockSubscriber.addResponse(expectedResponse);
270274

@@ -324,6 +328,7 @@ public class SubscriberClientTest {
324328
.setDeadLetterPolicy(DeadLetterPolicy.newBuilder().build())
325329
.setRetryPolicy(RetryPolicy.newBuilder().build())
326330
.setDetached(true)
331+
.setEnableExactlyOnceDelivery(true)
327332
.build();
328333
mockSubscriber.addResponse(expectedResponse);
329334

@@ -373,6 +378,7 @@ public class SubscriberClientTest {
373378
.setDeadLetterPolicy(DeadLetterPolicy.newBuilder().build())
374379
.setRetryPolicy(RetryPolicy.newBuilder().build())
375380
.setDetached(true)
381+
.setEnableExactlyOnceDelivery(true)
376382
.build();
377383
mockSubscriber.addResponse(expectedResponse);
378384

@@ -422,6 +428,7 @@ public class SubscriberClientTest {
422428
.setDeadLetterPolicy(DeadLetterPolicy.newBuilder().build())
423429
.setRetryPolicy(RetryPolicy.newBuilder().build())
424430
.setDetached(true)
431+
.setEnableExactlyOnceDelivery(true)
425432
.build();
426433
mockSubscriber.addResponse(expectedResponse);
427434

@@ -939,6 +946,10 @@ public class SubscriberClientTest {
939946
StreamingPullResponse expectedResponse =
940947
StreamingPullResponse.newBuilder()
941948
.addAllReceivedMessages(new ArrayList<ReceivedMessage>())
949+
.setAcknowlegeConfirmation(
950+
StreamingPullResponse.AcknowledgeConfirmation.newBuilder().build())
951+
.setModifyAckDeadlineConfirmation(
952+
StreamingPullResponse.ModifyAckDeadlineConfirmation.newBuilder().build())
942953
.setSubscriptionProperties(
943954
StreamingPullResponse.SubscriptionProperties.newBuilder().build())
944955
.build();

test/integration/BUILD.bazel

+11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ API_GAPIC_TARGETS = {
3232
"library": "@com_google_googleapis//google/example/library/v1:library_java_gapic",
3333
# REGAPIC test.
3434
"compute": "@com_google_googleapis//google/cloud/compute/v1small:compute_small_java_gapic",
35+
# Routing headers.
36+
"bigtable": "@com_google_googleapis//google/bigtable/v2:bigtable_java_gapic",
3537
}
3638

3739
[filegroup(
@@ -124,6 +126,15 @@ java_gapic_test(
124126
runtime_deps = ["@com_google_googleapis//google/iam/credentials/v1:credentials_java_gapic_test"],
125127
)
126128

129+
# Bigtable API
130+
java_gapic_test(
131+
name = "bigtable_java_gapic_test_suite",
132+
test_classes = [
133+
"com.google.cloud.bigtable.data.v2.BaseBigtableDataClientTest",
134+
],
135+
runtime_deps = ["@com_google_googleapis//google/bigtable/v2:bigtable_java_gapic_test"],
136+
)
137+
127138
# IAM (for a standalone mixed-in API).
128139
java_gapic_library(
129140
name = "iam_java_gapic",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
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.bigtable.v2;
18+
19+
import com.google.api.pathtemplate.PathTemplate;
20+
import com.google.api.resourcenames.ResourceName;
21+
import com.google.common.base.Preconditions;
22+
import com.google.common.collect.ImmutableMap;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
import java.util.Map;
26+
import java.util.Objects;
27+
import javax.annotation.Generated;
28+
29+
// AUTO-GENERATED DOCUMENTATION AND CLASS.
30+
@Generated("by gapic-generator-java")
31+
public class TableName implements ResourceName {
32+
private static final PathTemplate PROJECT_INSTANCE_TABLE =
33+
PathTemplate.createWithoutUrlEncoding(
34+
"projects/{project}/instances/{instance}/tables/{table}");
35+
private volatile Map<String, String> fieldValuesMap;
36+
private final String project;
37+
private final String instance;
38+
private final String table;
39+
40+
@Deprecated
41+
protected TableName() {
42+
project = null;
43+
instance = null;
44+
table = null;
45+
}
46+
47+
private TableName(Builder builder) {
48+
project = Preconditions.checkNotNull(builder.getProject());
49+
instance = Preconditions.checkNotNull(builder.getInstance());
50+
table = Preconditions.checkNotNull(builder.getTable());
51+
}
52+
53+
public String getProject() {
54+
return project;
55+
}
56+
57+
public String getInstance() {
58+
return instance;
59+
}
60+
61+
public String getTable() {
62+
return table;
63+
}
64+
65+
public static Builder newBuilder() {
66+
return new Builder();
67+
}
68+
69+
public Builder toBuilder() {
70+
return new Builder(this);
71+
}
72+
73+
public static TableName of(String project, String instance, String table) {
74+
return newBuilder().setProject(project).setInstance(instance).setTable(table).build();
75+
}
76+
77+
public static String format(String project, String instance, String table) {
78+
return newBuilder()
79+
.setProject(project)
80+
.setInstance(instance)
81+
.setTable(table)
82+
.build()
83+
.toString();
84+
}
85+
86+
public static TableName parse(String formattedString) {
87+
if (formattedString.isEmpty()) {
88+
return null;
89+
}
90+
Map<String, String> matchMap =
91+
PROJECT_INSTANCE_TABLE.validatedMatch(
92+
formattedString, "TableName.parse: formattedString not in valid format");
93+
return of(matchMap.get("project"), matchMap.get("instance"), matchMap.get("table"));
94+
}
95+
96+
public static List<TableName> parseList(List<String> formattedStrings) {
97+
List<TableName> list = new ArrayList<>(formattedStrings.size());
98+
for (String formattedString : formattedStrings) {
99+
list.add(parse(formattedString));
100+
}
101+
return list;
102+
}
103+
104+
public static List<String> toStringList(List<TableName> values) {
105+
List<String> list = new ArrayList<>(values.size());
106+
for (TableName value : values) {
107+
if (value == null) {
108+
list.add("");
109+
} else {
110+
list.add(value.toString());
111+
}
112+
}
113+
return list;
114+
}
115+
116+
public static boolean isParsableFrom(String formattedString) {
117+
return PROJECT_INSTANCE_TABLE.matches(formattedString);
118+
}
119+
120+
@Override
121+
public Map<String, String> getFieldValuesMap() {
122+
if (fieldValuesMap == null) {
123+
synchronized (this) {
124+
if (fieldValuesMap == null) {
125+
ImmutableMap.Builder<String, String> fieldMapBuilder = ImmutableMap.builder();
126+
if (project != null) {
127+
fieldMapBuilder.put("project", project);
128+
}
129+
if (instance != null) {
130+
fieldMapBuilder.put("instance", instance);
131+
}
132+
if (table != null) {
133+
fieldMapBuilder.put("table", table);
134+
}
135+
fieldValuesMap = fieldMapBuilder.build();
136+
}
137+
}
138+
}
139+
return fieldValuesMap;
140+
}
141+
142+
public String getFieldValue(String fieldName) {
143+
return getFieldValuesMap().get(fieldName);
144+
}
145+
146+
@Override
147+
public String toString() {
148+
return PROJECT_INSTANCE_TABLE.instantiate(
149+
"project", project, "instance", instance, "table", table);
150+
}
151+
152+
@Override
153+
public boolean equals(Object o) {
154+
if (o == this) {
155+
return true;
156+
}
157+
if (o != null || getClass() == o.getClass()) {
158+
TableName that = ((TableName) o);
159+
return Objects.equals(this.project, that.project)
160+
&& Objects.equals(this.instance, that.instance)
161+
&& Objects.equals(this.table, that.table);
162+
}
163+
return false;
164+
}
165+
166+
@Override
167+
public int hashCode() {
168+
int h = 1;
169+
h *= 1000003;
170+
h ^= Objects.hashCode(project);
171+
h *= 1000003;
172+
h ^= Objects.hashCode(instance);
173+
h *= 1000003;
174+
h ^= Objects.hashCode(table);
175+
return h;
176+
}
177+
178+
/** Builder for projects/{project}/instances/{instance}/tables/{table}. */
179+
public static class Builder {
180+
private String project;
181+
private String instance;
182+
private String table;
183+
184+
protected Builder() {}
185+
186+
public String getProject() {
187+
return project;
188+
}
189+
190+
public String getInstance() {
191+
return instance;
192+
}
193+
194+
public String getTable() {
195+
return table;
196+
}
197+
198+
public Builder setProject(String project) {
199+
this.project = project;
200+
return this;
201+
}
202+
203+
public Builder setInstance(String instance) {
204+
this.instance = instance;
205+
return this;
206+
}
207+
208+
public Builder setTable(String table) {
209+
this.table = table;
210+
return this;
211+
}
212+
213+
private Builder(TableName tableName) {
214+
this.project = tableName.project;
215+
this.instance = tableName.instance;
216+
this.table = tableName.table;
217+
}
218+
219+
public TableName build() {
220+
return new TableName(this);
221+
}
222+
}
223+
}

0 commit comments

Comments
 (0)