Skip to content

Commit

Permalink
🦉 Updates from OwlBot post-processor
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-owl-bot[bot] committed Apr 15, 2022
1 parent 35aa301 commit d6ada35
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 43 deletions.
Expand Up @@ -19,9 +19,7 @@
import static com.google.cloud.storage.Blob.BlobSourceOption.toGetOptions;
import static com.google.cloud.storage.Blob.BlobSourceOption.toSourceOptions;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.concurrent.Executors.callable;

import com.google.api.gax.retrying.ResultRetryAlgorithm;
import com.google.api.services.storage.model.StorageObject;
import com.google.auth.ServiceAccountSigner;
import com.google.auth.ServiceAccountSigner.SigningException;
Expand All @@ -34,7 +32,6 @@
import com.google.cloud.storage.Storage.SignUrlOption;
import com.google.cloud.storage.spi.v1.StorageRpc;
import com.google.common.io.BaseEncoding;
import com.google.common.io.CountingOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.OutputStream;
Expand All @@ -47,7 +44,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

/**
* An object in Google Cloud Storage. A {@code Blob} object includes the {@code BlobId} instance,
Expand Down
Expand Up @@ -2676,14 +2676,16 @@ Blob createFrom(

/**
* Downloads the given blob to the given path using specified blob read options.
*
* @param blob
* @param path
* @param options
*/
void downloadTo(BlobId blob, Path path, Blob.BlobSourceOption... options);

/**
* Downloads the given blob to the given output stream using specified blob read options.
* Downloads the given blob to the given output stream using specified blob read options.
*
* @param blob
* @param outputStream
* @param options
Expand Down
Expand Up @@ -550,7 +550,7 @@ public ReadChannel reader(BlobId blob, BlobSourceOption... options) {
@Override
public void downloadTo(BlobId blob, Path path, Blob.BlobSourceOption... options) {
try (OutputStream outputStream = Files.newOutputStream(path)) {
downloadTo(blob,outputStream, options);
downloadTo(blob, outputStream, options);
} catch (IOException e) {
throw new StorageException(e);
}
Expand Down
Expand Up @@ -16,14 +16,11 @@

package com.google.cloud.storage;

import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.createStrictMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.getCurrentArguments;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertArrayEquals;
Expand All @@ -32,11 +29,9 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.google.api.core.ApiClock;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.services.storage.model.StorageObject;
import com.google.cloud.ReadChannel;
import com.google.cloud.storage.Acl.Project;
import com.google.cloud.storage.Acl.Project.ProjectRole;
Expand All @@ -45,21 +40,16 @@
import com.google.cloud.storage.Blob.BlobSourceOption;
import com.google.cloud.storage.Storage.BlobWriteOption;
import com.google.cloud.storage.Storage.CopyRequest;
import com.google.cloud.storage.spi.v1.StorageRpc;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.BaseEncoding;
import java.io.File;
import java.io.OutputStream;
import java.net.URL;
import java.nio.file.Files;
import java.security.Key;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.crypto.spec.SecretKeySpec;
import org.easymock.Capture;
import org.easymock.IAnswer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down
Expand Up @@ -20,7 +20,6 @@
import static com.google.cloud.storage.testing.ApiPolicyMatcher.eqApiPolicy;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.getCurrentArguments;
Expand Down Expand Up @@ -2280,11 +2279,11 @@ public void testDownloadTo() throws Exception {
storage = options.toBuilder().build().getService();
final byte[] expected = {1, 2};
EasyMock.expect(
storageRpcMock.read(
anyObject(StorageObject.class),
anyObject(Map.class),
eq(0l),
anyObject(OutputStream.class)))
storageRpcMock.read(
anyObject(StorageObject.class),
anyObject(Map.class),
eq(0l),
anyObject(OutputStream.class)))
.andAnswer(
new IAnswer<Long>() {
@Override
Expand All @@ -2303,17 +2302,19 @@ public Long answer() throws Throwable {
@Test
public void testDownloadToWithRetries() throws Exception {
BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1);
storage = options.toBuilder()
.setRetrySettings(RetrySettings.newBuilder().setMaxAttempts(2).build())
.build()
.getService();
storage =
options
.toBuilder()
.setRetrySettings(RetrySettings.newBuilder().setMaxAttempts(2).build())
.build()
.getService();
final byte[] expected = {1, 2};
expect(
storageRpcMock.read(
anyObject(StorageObject.class),
anyObject(Map.class),
eq(0l),
anyObject(OutputStream.class)))
storageRpcMock.read(
anyObject(StorageObject.class),
anyObject(Map.class),
eq(0l),
anyObject(OutputStream.class)))
.andAnswer(
new IAnswer<Long>() {
@Override
Expand All @@ -2323,11 +2324,11 @@ public Long answer() throws Throwable {
}
});
expect(
storageRpcMock.read(
anyObject(StorageObject.class),
anyObject(Map.class),
eq(1l),
anyObject(OutputStream.class)))
storageRpcMock.read(
anyObject(StorageObject.class),
anyObject(Map.class),
eq(1l),
anyObject(OutputStream.class)))
.andAnswer(
new IAnswer<Long>() {
@Override
Expand All @@ -2349,11 +2350,11 @@ public void testDownloadToWithException() throws Exception {
storage = options.toBuilder().build().getService();
Exception exception = new IllegalStateException("test");
expect(
storageRpcMock.read(
anyObject(StorageObject.class),
anyObject(Map.class),
eq(0l),
anyObject(OutputStream.class)))
storageRpcMock.read(
anyObject(StorageObject.class),
anyObject(Map.class),
eq(0l),
anyObject(OutputStream.class)))
.andThrow(exception);
replay(storageRpcMock);
File file = File.createTempFile("blob", ".tmp");
Expand Down
Expand Up @@ -884,13 +884,15 @@ public void testGetBlobRawInput() throws IOException {

Path rawInputGzippedFile = File.createTempFile("rawinputgzippedfile", ".txt").toPath();

storage.downloadTo(blobId, rawInputGzippedFile, Blob.BlobSourceOption.shouldReturnRawInputStream(true));
storage.downloadTo(
blobId, rawInputGzippedFile, Blob.BlobSourceOption.shouldReturnRawInputStream(true));

assertArrayEquals(
Files.readAllBytes(gzippedFile.toPath()), Files.readAllBytes(rawInputGzippedFile));

Path unzippedFile = File.createTempFile("unzippedfile", ".txt").toPath();
storage.downloadTo(blobId, unzippedFile, Blob.BlobSourceOption.shouldReturnRawInputStream(false));
storage.downloadTo(
blobId, unzippedFile, Blob.BlobSourceOption.shouldReturnRawInputStream(false));

assertArrayEquals("hello world".getBytes(), Files.readAllBytes(unzippedFile));
}
Expand Down

0 comments on commit d6ada35

Please sign in to comment.