From 8a89b910812c4580d7c0f0f2c930363b9a6459a5 Mon Sep 17 00:00:00 2001 From: Phil Doctor Date: Mon, 8 Jul 2019 21:41:11 -0400 Subject: [PATCH 1/5] Update the storage mock so that copied objects can be read --- .../contrib/nio/testing/FakeStorageRpc.java | 12 +- .../nio/testing/LocalStorageHelperTest.java | 104 ++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java diff --git a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java index ba3358fc62d5..88a4ad99bb13 100644 --- a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java +++ b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java @@ -374,11 +374,21 @@ public RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws Storage String destKey = fullname(rewriteRequest.target); + // if this is a new file, set generation to 0, else increment the existing generation + long generation = 0; + if (metadata.containsKey(destKey)) { + generation = metadata.get(destKey).getGeneration() + 1; + } + checkGeneration(destKey, generationMatch); + byte[] data = contents.get(sourceKey); + + rewriteRequest.target.setGeneration(generation); + rewriteRequest.target.setSize(BigInteger.valueOf(data.length)); + metadata.put(destKey, rewriteRequest.target); - byte[] data = contents.get(sourceKey); contents.put(destKey, Arrays.copyOf(data, data.length)); return new RewriteResponse( rewriteRequest, diff --git a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java new file mode 100644 index 000000000000..ac49c0a8477b --- /dev/null +++ b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java @@ -0,0 +1,104 @@ +/* + * Copyright 2016 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.storage.contrib.nio.testing; + +import com.google.cloud.WriteChannel; +import com.google.cloud.storage.Blob; +import com.google.cloud.storage.BlobId; +import com.google.cloud.storage.BlobInfo; +import com.google.cloud.storage.Storage; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import static com.google.common.truth.Truth.assertThat; +import static java.nio.charset.StandardCharsets.UTF_8; + +/** Unit tests for {@link LocalStorageHelper}. */ +@RunWith(JUnit4.class) +public class LocalStorageHelperTest { + + Storage localStorageService = null; + private final String testBucket = "bucket"; + private final String sourceFile = "testSource"; + private final String destinationFile = "testDestination"; + private final String payload = "copy me"; + + @Before + public void before() throws IOException { + localStorageService = LocalStorageHelper.getOptions().getService(); + + byte[] payloadBytes = payload.getBytes(); + BlobId id = BlobId.of(testBucket, sourceFile); + BlobInfo info = BlobInfo.newBuilder(id).build(); + + WriteChannel writer = localStorageService.writer(info); + try { + writer.write(ByteBuffer.wrap(payloadBytes)); + } finally { + writer.close(); + } + } + + @After + public void after() { + localStorageService.delete(testBucket, sourceFile); + localStorageService.delete(testBucket, destinationFile); + } + + private Storage.CopyRequest copyRequest() { + Storage.CopyRequest request = Storage.CopyRequest + .newBuilder() + .setSource(BlobId.of(testBucket, sourceFile)) + .setTarget(BlobId.of(testBucket, destinationFile)) + .build(); + + return request; + } + + @Test + public void testCopyCanBeRead() { + Storage.CopyRequest request = copyRequest(); + localStorageService.copy(request).getResult(); + Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); + String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); + + assertThat(copiedContents).isEqualTo(payload); + assertThat(obj.getGeneration()).isEqualTo(0); + assertThat(obj.getSize()).isEqualTo(7); + } + + @Test + public void testCopyIncrementsGenerations() { + Storage.CopyRequest request = copyRequest(); + + localStorageService.copy(request).getResult(); + localStorageService.copy(request).getResult(); + Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); + String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); + + assertThat(copiedContents).isEqualTo(payload); + assertThat(obj.getGeneration()).isEqualTo(1); + assertThat(obj.getSize()).isEqualTo(7); + } + +} From 627ef40bce01c207ad298014574ccdbf408cfd67 Mon Sep 17 00:00:00 2001 From: Phil Doctor Date: Tue, 9 Jul 2019 12:35:53 -0400 Subject: [PATCH 2/5] Fixed java file formatting --- .../nio/testing/LocalStorageHelperTest.java | 123 +++++++++--------- 1 file changed, 60 insertions(+), 63 deletions(-) diff --git a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java index ac49c0a8477b..08679c0b3408 100644 --- a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java +++ b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java @@ -16,89 +16,86 @@ package com.google.cloud.storage.contrib.nio.testing; +import static com.google.common.truth.Truth.assertThat; + import com.google.cloud.WriteChannel; import com.google.cloud.storage.Blob; import com.google.cloud.storage.BlobId; import com.google.cloud.storage.BlobInfo; import com.google.cloud.storage.Storage; +import java.io.IOException; +import java.nio.ByteBuffer; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.IOException; -import java.nio.ByteBuffer; - -import static com.google.common.truth.Truth.assertThat; -import static java.nio.charset.StandardCharsets.UTF_8; - /** Unit tests for {@link LocalStorageHelper}. */ @RunWith(JUnit4.class) public class LocalStorageHelperTest { - Storage localStorageService = null; - private final String testBucket = "bucket"; - private final String sourceFile = "testSource"; - private final String destinationFile = "testDestination"; - private final String payload = "copy me"; - - @Before - public void before() throws IOException { - localStorageService = LocalStorageHelper.getOptions().getService(); - - byte[] payloadBytes = payload.getBytes(); - BlobId id = BlobId.of(testBucket, sourceFile); - BlobInfo info = BlobInfo.newBuilder(id).build(); - - WriteChannel writer = localStorageService.writer(info); - try { - writer.write(ByteBuffer.wrap(payloadBytes)); - } finally { - writer.close(); - } + Storage localStorageService = null; + private final String testBucket = "bucket"; + private final String sourceFile = "testSource"; + private final String destinationFile = "testDestination"; + private final String payload = "copy me"; + + @Before + public void before() throws IOException { + localStorageService = LocalStorageHelper.getOptions().getService(); + + byte[] payloadBytes = payload.getBytes(); + BlobId id = BlobId.of(testBucket, sourceFile); + BlobInfo info = BlobInfo.newBuilder(id).build(); + + WriteChannel writer = localStorageService.writer(info); + try { + writer.write(ByteBuffer.wrap(payloadBytes)); + } finally { + writer.close(); } + } - @After - public void after() { - localStorageService.delete(testBucket, sourceFile); - localStorageService.delete(testBucket, destinationFile); - } + @After + public void after() { + localStorageService.delete(testBucket, sourceFile); + localStorageService.delete(testBucket, destinationFile); + } - private Storage.CopyRequest copyRequest() { - Storage.CopyRequest request = Storage.CopyRequest - .newBuilder() + private Storage.CopyRequest copyRequest() { + Storage.CopyRequest request = + Storage.CopyRequest.newBuilder() .setSource(BlobId.of(testBucket, sourceFile)) .setTarget(BlobId.of(testBucket, destinationFile)) .build(); - return request; - } - - @Test - public void testCopyCanBeRead() { - Storage.CopyRequest request = copyRequest(); - localStorageService.copy(request).getResult(); - Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); - String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); - - assertThat(copiedContents).isEqualTo(payload); - assertThat(obj.getGeneration()).isEqualTo(0); - assertThat(obj.getSize()).isEqualTo(7); - } - - @Test - public void testCopyIncrementsGenerations() { - Storage.CopyRequest request = copyRequest(); - - localStorageService.copy(request).getResult(); - localStorageService.copy(request).getResult(); - Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); - String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); - - assertThat(copiedContents).isEqualTo(payload); - assertThat(obj.getGeneration()).isEqualTo(1); - assertThat(obj.getSize()).isEqualTo(7); - } - + return request; + } + + @Test + public void testCopyCanBeRead() { + Storage.CopyRequest request = copyRequest(); + localStorageService.copy(request).getResult(); + Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); + String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); + + assertThat(copiedContents).isEqualTo(payload); + assertThat(obj.getGeneration()).isEqualTo(0); + assertThat(obj.getSize()).isEqualTo(7); + } + + @Test + public void testCopyIncrementsGenerations() { + Storage.CopyRequest request = copyRequest(); + + localStorageService.copy(request).getResult(); + localStorageService.copy(request).getResult(); + Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); + String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); + + assertThat(copiedContents).isEqualTo(payload); + assertThat(obj.getGeneration()).isEqualTo(1); + assertThat(obj.getSize()).isEqualTo(7); + } } From 6bda52be18e69c338728a2e92b38db8e5b1ed797 Mon Sep 17 00:00:00 2001 From: Phil Doctor Date: Tue, 9 Jul 2019 18:19:45 -0400 Subject: [PATCH 3/5] Start generation counting at 1, which matches the docs and other tests --- .../contrib/nio/testing/FakeStorageRpc.java | 4 +- .../nio/testing/LocalStorageHelperTest.java | 101 ------------------ 2 files changed, 2 insertions(+), 103 deletions(-) delete mode 100644 google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java diff --git a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java index 88a4ad99bb13..4445d9a8c178 100644 --- a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java +++ b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java @@ -374,8 +374,8 @@ public RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws Storage String destKey = fullname(rewriteRequest.target); - // if this is a new file, set generation to 0, else increment the existing generation - long generation = 0; + // if this is a new file, set generation to 1, else increment the existing generation + long generation = 1; if (metadata.containsKey(destKey)) { generation = metadata.get(destKey).getGeneration() + 1; } diff --git a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java deleted file mode 100644 index 08679c0b3408..000000000000 --- a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2016 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.cloud.storage.contrib.nio.testing; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.cloud.WriteChannel; -import com.google.cloud.storage.Blob; -import com.google.cloud.storage.BlobId; -import com.google.cloud.storage.BlobInfo; -import com.google.cloud.storage.Storage; -import java.io.IOException; -import java.nio.ByteBuffer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Unit tests for {@link LocalStorageHelper}. */ -@RunWith(JUnit4.class) -public class LocalStorageHelperTest { - - Storage localStorageService = null; - private final String testBucket = "bucket"; - private final String sourceFile = "testSource"; - private final String destinationFile = "testDestination"; - private final String payload = "copy me"; - - @Before - public void before() throws IOException { - localStorageService = LocalStorageHelper.getOptions().getService(); - - byte[] payloadBytes = payload.getBytes(); - BlobId id = BlobId.of(testBucket, sourceFile); - BlobInfo info = BlobInfo.newBuilder(id).build(); - - WriteChannel writer = localStorageService.writer(info); - try { - writer.write(ByteBuffer.wrap(payloadBytes)); - } finally { - writer.close(); - } - } - - @After - public void after() { - localStorageService.delete(testBucket, sourceFile); - localStorageService.delete(testBucket, destinationFile); - } - - private Storage.CopyRequest copyRequest() { - Storage.CopyRequest request = - Storage.CopyRequest.newBuilder() - .setSource(BlobId.of(testBucket, sourceFile)) - .setTarget(BlobId.of(testBucket, destinationFile)) - .build(); - - return request; - } - - @Test - public void testCopyCanBeRead() { - Storage.CopyRequest request = copyRequest(); - localStorageService.copy(request).getResult(); - Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); - String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); - - assertThat(copiedContents).isEqualTo(payload); - assertThat(obj.getGeneration()).isEqualTo(0); - assertThat(obj.getSize()).isEqualTo(7); - } - - @Test - public void testCopyIncrementsGenerations() { - Storage.CopyRequest request = copyRequest(); - - localStorageService.copy(request).getResult(); - localStorageService.copy(request).getResult(); - Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); - String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); - - assertThat(copiedContents).isEqualTo(payload); - assertThat(obj.getGeneration()).isEqualTo(1); - assertThat(obj.getSize()).isEqualTo(7); - } -} From 89d33fee16eadd96905611e240f46810be19f27b Mon Sep 17 00:00:00 2001 From: Phil Doctor Date: Wed, 10 Jul 2019 13:23:27 -0400 Subject: [PATCH 4/5] Add back in test file that was accidentally removed --- .../nio/testing/LocalStorageHelperTest.java | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java diff --git a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java new file mode 100644 index 000000000000..4b78450d0a7d --- /dev/null +++ b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java @@ -0,0 +1,101 @@ +/* + * Copyright 2016 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.storage.contrib.nio.testing; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.cloud.WriteChannel; +import com.google.cloud.storage.Blob; +import com.google.cloud.storage.BlobId; +import com.google.cloud.storage.BlobInfo; +import com.google.cloud.storage.Storage; +import java.io.IOException; +import java.nio.ByteBuffer; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Unit tests for {@link LocalStorageHelper}. */ +@RunWith(JUnit4.class) +public class LocalStorageHelperTest { + + Storage localStorageService = null; + private final String testBucket = "bucket"; + private final String sourceFile = "testSource"; + private final String destinationFile = "testDestination"; + private final String payload = "copy me"; + + @Before + public void before() throws IOException { + localStorageService = LocalStorageHelper.getOptions().getService(); + + byte[] payloadBytes = payload.getBytes(); + BlobId id = BlobId.of(testBucket, sourceFile); + BlobInfo info = BlobInfo.newBuilder(id).build(); + + WriteChannel writer = localStorageService.writer(info); + try { + writer.write(ByteBuffer.wrap(payloadBytes)); + } finally { + writer.close(); + } + } + + @After + public void after() { + localStorageService.delete(testBucket, sourceFile); + localStorageService.delete(testBucket, destinationFile); + } + + private Storage.CopyRequest copyRequest() { + Storage.CopyRequest request = + Storage.CopyRequest.newBuilder() + .setSource(BlobId.of(testBucket, sourceFile)) + .setTarget(BlobId.of(testBucket, destinationFile)) + .build(); + + return request; + } + + @Test + public void testCopyCanBeRead() { + Storage.CopyRequest request = copyRequest(); + localStorageService.copy(request).getResult(); + Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); + String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); + + assertThat(copiedContents).isEqualTo(payload); + assertThat(obj.getGeneration()).isEqualTo(1); + assertThat(obj.getSize()).isEqualTo(7); + } + + @Test + public void testCopyIncrementsGenerations() { + Storage.CopyRequest request = copyRequest(); + + localStorageService.copy(request).getResult(); + localStorageService.copy(request).getResult(); + Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); + String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); + + assertThat(copiedContents).isEqualTo(payload); + assertThat(obj.getGeneration()).isEqualTo(2); + assertThat(obj.getSize()).isEqualTo(7); + } +} \ No newline at end of file From b0aa24840d852bff55e9cd081dc5b76d4e65a4b1 Mon Sep 17 00:00:00 2001 From: Phil Doctor Date: Wed, 10 Jul 2019 13:25:32 -0400 Subject: [PATCH 5/5] Reformat code per standards --- .../nio/testing/LocalStorageHelperTest.java | 126 +++++++++--------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java index 4b78450d0a7d..6f2e5cf19438 100644 --- a/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java +++ b/google-cloud-clients/google-cloud-contrib/google-cloud-nio/src/test/java/com/google/cloud/storage/contrib/nio/testing/LocalStorageHelperTest.java @@ -35,67 +35,67 @@ @RunWith(JUnit4.class) public class LocalStorageHelperTest { - Storage localStorageService = null; - private final String testBucket = "bucket"; - private final String sourceFile = "testSource"; - private final String destinationFile = "testDestination"; - private final String payload = "copy me"; - - @Before - public void before() throws IOException { - localStorageService = LocalStorageHelper.getOptions().getService(); - - byte[] payloadBytes = payload.getBytes(); - BlobId id = BlobId.of(testBucket, sourceFile); - BlobInfo info = BlobInfo.newBuilder(id).build(); - - WriteChannel writer = localStorageService.writer(info); - try { - writer.write(ByteBuffer.wrap(payloadBytes)); - } finally { - writer.close(); - } + Storage localStorageService = null; + private final String testBucket = "bucket"; + private final String sourceFile = "testSource"; + private final String destinationFile = "testDestination"; + private final String payload = "copy me"; + + @Before + public void before() throws IOException { + localStorageService = LocalStorageHelper.getOptions().getService(); + + byte[] payloadBytes = payload.getBytes(); + BlobId id = BlobId.of(testBucket, sourceFile); + BlobInfo info = BlobInfo.newBuilder(id).build(); + + WriteChannel writer = localStorageService.writer(info); + try { + writer.write(ByteBuffer.wrap(payloadBytes)); + } finally { + writer.close(); } - - @After - public void after() { - localStorageService.delete(testBucket, sourceFile); - localStorageService.delete(testBucket, destinationFile); - } - - private Storage.CopyRequest copyRequest() { - Storage.CopyRequest request = - Storage.CopyRequest.newBuilder() - .setSource(BlobId.of(testBucket, sourceFile)) - .setTarget(BlobId.of(testBucket, destinationFile)) - .build(); - - return request; - } - - @Test - public void testCopyCanBeRead() { - Storage.CopyRequest request = copyRequest(); - localStorageService.copy(request).getResult(); - Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); - String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); - - assertThat(copiedContents).isEqualTo(payload); - assertThat(obj.getGeneration()).isEqualTo(1); - assertThat(obj.getSize()).isEqualTo(7); - } - - @Test - public void testCopyIncrementsGenerations() { - Storage.CopyRequest request = copyRequest(); - - localStorageService.copy(request).getResult(); - localStorageService.copy(request).getResult(); - Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); - String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); - - assertThat(copiedContents).isEqualTo(payload); - assertThat(obj.getGeneration()).isEqualTo(2); - assertThat(obj.getSize()).isEqualTo(7); - } -} \ No newline at end of file + } + + @After + public void after() { + localStorageService.delete(testBucket, sourceFile); + localStorageService.delete(testBucket, destinationFile); + } + + private Storage.CopyRequest copyRequest() { + Storage.CopyRequest request = + Storage.CopyRequest.newBuilder() + .setSource(BlobId.of(testBucket, sourceFile)) + .setTarget(BlobId.of(testBucket, destinationFile)) + .build(); + + return request; + } + + @Test + public void testCopyCanBeRead() { + Storage.CopyRequest request = copyRequest(); + localStorageService.copy(request).getResult(); + Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); + String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); + + assertThat(copiedContents).isEqualTo(payload); + assertThat(obj.getGeneration()).isEqualTo(1); + assertThat(obj.getSize()).isEqualTo(7); + } + + @Test + public void testCopyIncrementsGenerations() { + Storage.CopyRequest request = copyRequest(); + + localStorageService.copy(request).getResult(); + localStorageService.copy(request).getResult(); + Blob obj = localStorageService.get(BlobId.of(testBucket, destinationFile)); + String copiedContents = new String(obj.getContent(Blob.BlobSourceOption.generationMatch())); + + assertThat(copiedContents).isEqualTo(payload); + assertThat(obj.getGeneration()).isEqualTo(2); + assertThat(obj.getSize()).isEqualTo(7); + } +}