Skip to content

Commit 596584a

Browse files
authored
chore(test): update ITStorageTest to explicitly shutdown the grpc channel for KMS (#1379)
Refactor afterClass() to attempt cleanup of each resource independently Explicitly shutting down the grpc channel for KMS prevents the following exception from error being reported ``` *~*~*~ Channel ManagedChannelImpl{logId=1, target=cloudkms.googleapis.com:443} was not shutdown properly!!! ~*~*~* Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true. java.lang.RuntimeException: ManagedChannel allocation site at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.<init>(ManagedChannelOrphanWrapper.java:93) at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:53) at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:44) at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:630) at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:297) at com.google.cloud.storage.it.ITStorageTest.prepareKmsKeys(ITStorageTest.java:322) at com.google.cloud.storage.it.ITStorageTest.beforeClass(ITStorageTest.java:255) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.RunBefores.invokeMethod(RunBefores.java:33) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) ```
1 parent bf82936 commit 596584a

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ public class ITStorageTest {
234234
Notification.PayloadFormat.JSON_API_V1.JSON_API_V1;
235235
private static final Map<String, String> CUSTOM_ATTRIBUTES = ImmutableMap.of("label1", "value1");
236236

237+
private static ManagedChannel kmsChannel;
238+
237239
@BeforeClass
238240
public static void beforeClass() throws IOException {
239241
remoteStorageHelper = RemoteStorageHelper.create();
@@ -276,13 +278,27 @@ private static void unsetRequesterPays() {
276278

277279
@AfterClass
278280
public static void afterClass() throws ExecutionException, InterruptedException {
279-
if (storage != null) {
281+
if (kmsChannel != null) {
282+
try {
283+
kmsChannel.shutdownNow();
284+
} catch (Exception e) {
285+
log.log(Level.WARNING, "Error while trying to shutdown kms channel", e);
286+
}
287+
kmsChannel = null;
288+
}
280289

281-
/* Delete the Pub/Sub topic */
282-
if (topicAdminClient != null) {
290+
/* Delete the Pub/Sub topic */
291+
if (topicAdminClient != null) {
292+
try {
283293
topicAdminClient.deleteTopic(TOPIC);
284294
topicAdminClient.close();
295+
} catch (Exception e) {
296+
log.log(Level.WARNING, "Error while trying to delete topic and shutdown topic client", e);
285297
}
298+
topicAdminClient = null;
299+
}
300+
301+
if (storage != null) {
286302
// In beforeClass, we make buckets auto-delete blobs older than a day old.
287303
// Here, delete all buckets older than 2 days. They should already be empty and easy.
288304
long cleanTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(2);
@@ -312,8 +328,7 @@ private static void prepareKmsKeys() throws IOException {
312328
// https://cloud.google.com/storage/docs/encryption/using-customer-managed-keys
313329
String projectId = remoteStorageHelper.getOptions().getProjectId();
314330
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
315-
ManagedChannel kmsChannel =
316-
ManagedChannelBuilder.forTarget("cloudkms.googleapis.com:443").build();
331+
kmsChannel = ManagedChannelBuilder.forTarget("cloudkms.googleapis.com:443").build();
317332
KeyManagementServiceBlockingStub kmsStub =
318333
KeyManagementServiceGrpc.newBlockingStub(kmsChannel)
319334
.withCallCredentials(MoreCallCredentials.from(credentials));

0 commit comments

Comments
 (0)