Skip to content

Commit 552af72

Browse files
committed
fix: isolate stub.close change to another PR
1 parent 1c57844 commit 552af72

File tree

21 files changed

+22
-139
lines changed

21 files changed

+22
-139
lines changed

src/main/java/com/google/api/generator/gapic/composer/common/AbstractServiceStubClassComposer.java

+2-39
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
import com.google.api.generator.engine.ast.ScopeNode;
4141
import com.google.api.generator.engine.ast.Statement;
4242
import com.google.api.generator.engine.ast.ThisObjectValue;
43-
import com.google.api.generator.engine.ast.ThrowExpr;
44-
import com.google.api.generator.engine.ast.TryCatchStatement;
4543
import com.google.api.generator.engine.ast.TypeNode;
4644
import com.google.api.generator.engine.ast.ValueExpr;
4745
import com.google.api.generator.engine.ast.Variable;
@@ -793,23 +791,6 @@ private List<MethodDefinition> createStubOverrideMethods(
793791
.build())
794792
.build();
795793

796-
// Generate the close() method:
797-
// @Override
798-
// public final void close() {
799-
// try {
800-
// backgroundResources.close();
801-
// } catch (Exception e) {
802-
// throw new IllegalStateException("Failed to close resource", e);
803-
// }
804-
// }
805-
VariableExpr catchExceptionVarExpr =
806-
VariableExpr.builder()
807-
.setVariable(
808-
Variable.builder()
809-
.setType(TypeNode.withExceptionClazz(Exception.class))
810-
.setName("e")
811-
.build())
812-
.build();
813794
List<MethodDefinition> javaMethods = new ArrayList<>();
814795
javaMethods.add(
815796
methodMakerStarterFn
@@ -818,26 +799,8 @@ private List<MethodDefinition> createStubOverrideMethods(
818799
.setReturnType(TypeNode.VOID)
819800
.setBody(
820801
Arrays.asList(
821-
TryCatchStatement.builder()
822-
.setTryBody(
823-
Arrays.asList(
824-
ExprStatement.withExpr(
825-
MethodInvocationExpr.builder()
826-
.setExprReferenceExpr(backgroundResourcesVarExpr)
827-
.setMethodName("close")
828-
.build())))
829-
.addCatch(
830-
catchExceptionVarExpr.toBuilder().setIsDecl(true).build(),
831-
Arrays.asList(
832-
ExprStatement.withExpr(
833-
ThrowExpr.builder()
834-
.setType(
835-
TypeNode.withExceptionClazz(
836-
IllegalStateException.class))
837-
.setMessageExpr(String.format("Failed to close resource"))
838-
.setCauseExpr(catchExceptionVarExpr)
839-
.build())))
840-
.build()))
802+
ExprStatement.withExpr(
803+
MethodInvocationExpr.builder().setMethodName("shutdown").build())))
841804
.build());
842805
javaMethods.add(voidMethodMakerFn.apply("shutdown"));
843806
javaMethods.add(booleanMethodMakerFn.apply("isShutdown"));

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,7 @@ public class GrpcDeprecatedServiceStub extends DeprecatedServiceStub {
125125

126126
@Override
127127
public final void close() {
128-
try {
129-
backgroundResources.close();
130-
} catch (Exception e) {
131-
throw new IllegalStateException("Failed to close resource", e);
132-
}
128+
shutdown();
133129
}
134130

135131
@Override

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,7 @@ public class GrpcEchoStub extends EchoStub {
341341

342342
@Override
343343
public final void close() {
344-
try {
345-
backgroundResources.close();
346-
} catch (Exception e) {
347-
throw new IllegalStateException("Failed to close resource", e);
348-
}
344+
shutdown();
349345
}
350346

351347
@Override

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,7 @@ public class GrpcPublisherStub extends PublisherStub {
430430

431431
@Override
432432
public final void close() {
433-
try {
434-
backgroundResources.close();
435-
} catch (Exception e) {
436-
throw new IllegalStateException("Failed to close resource", e);
437-
}
433+
shutdown();
438434
}
439435

440436
@Override

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,7 @@ public class GrpcTestingStub extends TestingStub {
382382

383383
@Override
384384
public final void close() {
385-
try {
386-
backgroundResources.close();
387-
} catch (Exception e) {
388-
throw new IllegalStateException("Failed to close resource", e);
389-
}
385+
shutdown();
390386
}
391387

392388
@Override

src/test/java/com/google/api/generator/gapic/composer/rest/goldens/HttpJsonComplianceStub.golden

+1-5
Original file line numberDiff line numberDiff line change
@@ -484,11 +484,7 @@ public class HttpJsonComplianceStub extends ComplianceStub {
484484

485485
@Override
486486
public final void close() {
487-
try {
488-
backgroundResources.close();
489-
} catch (Exception e) {
490-
throw new IllegalStateException("Failed to close resource", e);
491-
}
487+
shutdown();
492488
}
493489

494490
@Override

test/integration/goldens/asset/com/google/cloud/asset/v1/stub/GrpcAssetServiceStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,7 @@ public UnaryCallable<DeleteFeedRequest, Empty> deleteFeedCallable() {
598598

599599
@Override
600600
public final void close() {
601-
try {
602-
backgroundResources.close();
603-
} catch (Exception e) {
604-
throw new IllegalStateException("Failed to close resource", e);
605-
}
601+
shutdown();
606602
}
607603

608604
@Override

test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonAddressesStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,7 @@ public UnaryCallable<ListAddressesRequest, ListPagedResponse> listPagedCallable(
403403

404404
@Override
405405
public final void close() {
406-
try {
407-
backgroundResources.close();
408-
} catch (Exception e) {
409-
throw new IllegalStateException("Failed to close resource", e);
410-
}
406+
shutdown();
411407
}
412408

413409
@Override

test/integration/goldens/compute/com/google/cloud/compute/v1/stub/HttpJsonRegionOperationsStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,7 @@ public UnaryCallable<GetRegionOperationRequest, Operation> getCallable() {
167167

168168
@Override
169169
public final void close() {
170-
try {
171-
backgroundResources.close();
172-
} catch (Exception e) {
173-
throw new IllegalStateException("Failed to close resource", e);
174-
}
170+
shutdown();
175171
}
176172

177173
@Override

test/integration/goldens/credentials/com/google/cloud/iam/credentials/v1/stub/GrpcIamCredentialsStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,7 @@ public UnaryCallable<SignJwtRequest, SignJwtResponse> signJwtCallable() {
239239

240240
@Override
241241
public final void close() {
242-
try {
243-
backgroundResources.close();
244-
} catch (Exception e) {
245-
throw new IllegalStateException("Failed to close resource", e);
246-
}
242+
shutdown();
247243
}
248244

249245
@Override

test/integration/goldens/iam/com/google/iam/v1/stub/GrpcIAMPolicyStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,7 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
197197

198198
@Override
199199
public final void close() {
200-
try {
201-
backgroundResources.close();
202-
} catch (Exception e) {
203-
throw new IllegalStateException("Failed to close resource", e);
204-
}
200+
shutdown();
205201
}
206202

207203
@Override

test/integration/goldens/kms/com/google/cloud/kms/v1/stub/GrpcKeyManagementServiceStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -1119,11 +1119,7 @@ public UnaryCallable<GetLocationRequest, Location> getLocationCallable() {
11191119

11201120
@Override
11211121
public final void close() {
1122-
try {
1123-
backgroundResources.close();
1124-
} catch (Exception e) {
1125-
throw new IllegalStateException("Failed to close resource", e);
1126-
}
1122+
shutdown();
11271123
}
11281124

11291125
@Override

test/integration/goldens/library/com/google/cloud/example/library/v1/stub/GrpcLibraryServiceStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,7 @@ public UnaryCallable<MoveBookRequest, Book> moveBookCallable() {
450450

451451
@Override
452452
public final void close() {
453-
try {
454-
backgroundResources.close();
455-
} catch (Exception e) {
456-
throw new IllegalStateException("Failed to close resource", e);
457-
}
453+
shutdown();
458454
}
459455

460456
@Override

test/integration/goldens/logging/com/google/cloud/logging/v2/stub/GrpcConfigServiceV2Stub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -889,11 +889,7 @@ public UnaryCallable<UpdateCmekSettingsRequest, CmekSettings> updateCmekSettings
889889

890890
@Override
891891
public final void close() {
892-
try {
893-
backgroundResources.close();
894-
} catch (Exception e) {
895-
throw new IllegalStateException("Failed to close resource", e);
896-
}
892+
shutdown();
897893
}
898894

899895
@Override

test/integration/goldens/logging/com/google/cloud/logging/v2/stub/GrpcLoggingServiceV2Stub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,7 @@ public UnaryCallable<ListLogsRequest, ListLogsPagedResponse> listLogsPagedCallab
328328

329329
@Override
330330
public final void close() {
331-
try {
332-
backgroundResources.close();
333-
} catch (Exception e) {
334-
throw new IllegalStateException("Failed to close resource", e);
335-
}
331+
shutdown();
336332
}
337333

338334
@Override

test/integration/goldens/logging/com/google/cloud/logging/v2/stub/GrpcMetricsServiceV2Stub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,7 @@ public UnaryCallable<DeleteLogMetricRequest, Empty> deleteLogMetricCallable() {
279279

280280
@Override
281281
public final void close() {
282-
try {
283-
backgroundResources.close();
284-
} catch (Exception e) {
285-
throw new IllegalStateException("Failed to close resource", e);
286-
}
282+
shutdown();
287283
}
288284

289285
@Override

test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/stub/GrpcPublisherStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,7 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
549549

550550
@Override
551551
public final void close() {
552-
try {
553-
backgroundResources.close();
554-
} catch (Exception e) {
555-
throw new IllegalStateException("Failed to close resource", e);
556-
}
552+
shutdown();
557553
}
558554

559555
@Override

test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/stub/GrpcSchemaServiceStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,7 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
412412

413413
@Override
414414
public final void close() {
415-
try {
416-
backgroundResources.close();
417-
} catch (Exception e) {
418-
throw new IllegalStateException("Failed to close resource", e);
419-
}
415+
shutdown();
420416
}
421417

422418
@Override

test/integration/goldens/pubsub/com/google/cloud/pubsub/v1/stub/GrpcSubscriberStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,7 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
762762

763763
@Override
764764
public final void close() {
765-
try {
766-
backgroundResources.close();
767-
} catch (Exception e) {
768-
throw new IllegalStateException("Failed to close resource", e);
769-
}
765+
shutdown();
770766
}
771767

772768
@Override

test/integration/goldens/redis/com/google/cloud/redis/v1beta1/stub/GrpcCloudRedisStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,7 @@ public OperationCallable<DeleteInstanceRequest, Empty, Any> deleteInstanceOperat
505505

506506
@Override
507507
public final void close() {
508-
try {
509-
backgroundResources.close();
510-
} catch (Exception e) {
511-
throw new IllegalStateException("Failed to close resource", e);
512-
}
508+
shutdown();
513509
}
514510

515511
@Override

test/integration/goldens/storage/com/google/storage/v2/stub/GrpcStorageStub.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,7 @@ public ClientStreamingCallable<WriteObjectRequest, WriteObjectResponse> writeObj
201201

202202
@Override
203203
public final void close() {
204-
try {
205-
backgroundResources.close();
206-
} catch (Exception e) {
207-
throw new IllegalStateException("Failed to close resource", e);
208-
}
204+
shutdown();
209205
}
210206

211207
@Override

0 commit comments

Comments
 (0)