import com.google.gcloud.datastore.Datastore;
-import com.google.gcloud.datastore.DatastoreFactory;
import com.google.gcloud.datastore.DatastoreOptions;
import com.google.gcloud.datastore.Entity;
import com.google.gcloud.datastore.Key;
@@ -145,7 +144,7 @@ Example: Retrieve Datastore Entries
// Authentication is automatic inside Google Compute Engine
// and Google App Engine.
DatastoreOptions options = DatastoreOptions.builder().build();
-Datastore datastore = DatastoreFactory.instance().get(options);
+Datastore datastore = options.service();
KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND );
Key key = keyFactory.newKey(keyName);
Entity entity = datastore.get(key);
@@ -156,7 +155,6 @@ Example: Retrieve Datastore Entries
import com.google.gcloud.AuthCredentials;
import com.google.gcloud.datastore.Datastore;
-import com.google.gcloud.datastore.DatastoreFactory;
import com.google.gcloud.datastore.DatastoreOptions;
import com.google.gcloud.datastore.Entity;
import com.google.gcloud.datastore.Key;
@@ -166,7 +164,7 @@ Example: Retrieve Datastore Entries
.projectId(PROJECT_ID )
.authCredentials(AuthCredentials.createForJson(
new FileInputStream(PATH_TO_JSON_KEY ))).build();
-Datastore datastore = DatastoreFactory.instance().get(options);
+Datastore datastore = options.service();
KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND );
Key key = keyFactory.newKey(keyName);
Entity entity = datastore.get(key);
From 855a9d1290ab2fe726ad6847cedde5dd02eefd47 Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Mon, 26 Oct 2015 21:57:41 +0100
Subject: [PATCH 018/322] Force dependency information page to show
instructions for gcloud-java
---
pom.xml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/pom.xml b/pom.xml
index 9672c02a8ca7..91f88db02c0a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -332,6 +332,8 @@
true
true
true
+ gcloud-java
+ jar
From 7afcc34c56b19556ef2b2cc8bcbc7459604910ad Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Tue, 27 Oct 2015 11:18:15 +0100
Subject: [PATCH 019/322] Override artifact id for Dependency Information
report
---
gcloud-java-core/pom.xml | 21 +++++++++++++++++++++
gcloud-java-datastore/pom.xml | 21 +++++++++++++++++++++
gcloud-java-examples/pom.xml | 17 +++++++++++++++++
gcloud-java-storage/pom.xml | 21 +++++++++++++++++++++
gcloud-java/pom.xml | 21 +++++++++++++++++++++
5 files changed, 101 insertions(+)
diff --git a/gcloud-java-core/pom.xml b/gcloud-java-core/pom.xml
index 2275c7f0765b..1062f4d3110c 100644
--- a/gcloud-java-core/pom.xml
+++ b/gcloud-java-core/pom.xml
@@ -90,4 +90,25 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-site-plugin
+ 3.4
+
+
+
+ org.apache.maven.plugins
+ maven-project-info-reports-plugin
+ 2.8
+
+ gcloud-java-core
+
+
+
+
+
+
+
diff --git a/gcloud-java-datastore/pom.xml b/gcloud-java-datastore/pom.xml
index ba70d805a86c..700f14c03a51 100644
--- a/gcloud-java-datastore/pom.xml
+++ b/gcloud-java-datastore/pom.xml
@@ -38,4 +38,25 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-site-plugin
+ 3.4
+
+
+
+ org.apache.maven.plugins
+ maven-project-info-reports-plugin
+ 2.8
+
+ gcloud-java-datastore
+
+
+
+
+
+
+
diff --git a/gcloud-java-examples/pom.xml b/gcloud-java-examples/pom.xml
index d6a990ed8b7c..4f5649797f78 100644
--- a/gcloud-java-examples/pom.xml
+++ b/gcloud-java-examples/pom.xml
@@ -29,6 +29,23 @@
false
+
+ org.apache.maven.plugins
+ maven-site-plugin
+ 3.4
+
+
+
+ org.apache.maven.plugins
+ maven-project-info-reports-plugin
+ 2.8
+
+ gcloud-java-examples
+
+
+
+
+
diff --git a/gcloud-java-storage/pom.xml b/gcloud-java-storage/pom.xml
index 2d4d9f8df55b..439fa540e479 100644
--- a/gcloud-java-storage/pom.xml
+++ b/gcloud-java-storage/pom.xml
@@ -44,4 +44,25 @@
test
+
+
+
+ org.apache.maven.plugins
+ maven-site-plugin
+ 3.4
+
+
+
+ org.apache.maven.plugins
+ maven-project-info-reports-plugin
+ 2.8
+
+ gcloud-java-storage
+
+
+
+
+
+
+
diff --git a/gcloud-java/pom.xml b/gcloud-java/pom.xml
index 6ad0fce8f1b1..9b8614c20431 100644
--- a/gcloud-java/pom.xml
+++ b/gcloud-java/pom.xml
@@ -30,4 +30,25 @@
${project.version}
+
+
+
+ org.apache.maven.plugins
+ maven-site-plugin
+ 3.4
+
+
+
+ org.apache.maven.plugins
+ maven-project-info-reports-plugin
+ 2.8
+
+ gcloud-java
+
+
+
+
+
+
+
From e0363357c295c561b755619126a10a8ac9db2809 Mon Sep 17 00:00:00 2001
From: aozarov
Date: Tue, 27 Oct 2015 12:15:39 -0700
Subject: [PATCH 020/322] use static constant for default factories, add
example to Restorable and use mock instead of niceMock
---
.../java/com/google/gcloud/Restorable.java | 17 ++-
.../com/google/gcloud/ServiceOptions.java | 44 ++++----
.../gcloud/datastore/DatastoreOptions.java | 8 +-
.../gcloud/storage/BlobReadChannel.java | 2 +-
.../gcloud/storage/BlobWriteChannel.java | 2 +-
.../google/gcloud/storage/StorageOptions.java | 8 +-
.../storage/BlobReadChannelImplTest.java | 63 +++++------
.../storage/BlobWriteChannelImplTest.java | 103 +++++++++---------
.../google/gcloud/storage/ITStorageTest.java | 13 +--
.../gcloud/storage/StorageImplTest.java | 5 +-
10 files changed, 145 insertions(+), 120 deletions(-)
diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/Restorable.java b/gcloud-java-core/src/main/java/com/google/gcloud/Restorable.java
index aba973590965..83ef39a4dd73 100644
--- a/gcloud-java-core/src/main/java/com/google/gcloud/Restorable.java
+++ b/gcloud-java-core/src/main/java/com/google/gcloud/Restorable.java
@@ -2,11 +2,26 @@
/**
* Implementation of this interface can persist their state and restore from it.
+ *
+ *
+ * A typical capture usage:
+ *
{@code
+ * X restorableObj; // X instanceof Restorable
+ * RestorableState state = restorableObj.capture();
+ * .. persist state
+ * }
+ *
+ * A typical restore usage:
+ * {@code
+ * RestorableState state = ... // read from persistence
+ * X restorableObj = state.restore();
+ * ...
+ * }
*/
public interface Restorable> {
/**
- * Capture the state of this object.
+ * Captures the state of this object.
*
* @return a {@link RestorableState} instance that contains the state for this object and can
* restore it afterwards.
diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
index 70da7831c1db..4a68aa7894f7 100644
--- a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
+++ b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
@@ -1,17 +1,15 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
- * 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
+ * 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
+ * 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.
+ * 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.gcloud;
@@ -28,7 +26,15 @@
import com.google.common.collect.Iterables;
import com.google.gcloud.spi.ServiceRpcFactory;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamException;
+import java.io.Serializable;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
@@ -70,8 +76,8 @@ public abstract class ServiceOptions<
/**
* A base interface for all {@link HttpTransport} factories.
*
- * Implementation must provide a public no-arg constructor.
- * Loading of a factory implementation is done via {@link java.util.ServiceLoader}.
+ * Implementation must provide a public no-arg constructor. Loading of a factory implementation is
+ * done via {@link java.util.ServiceLoader}.
*/
public interface HttpTransportFactory {
HttpTransport create();
@@ -264,7 +270,7 @@ public B serviceRpcFactory(ServiceRpcFactory serviceRpcFa
* Sets the timeout in milliseconds to establish a connection.
*
* @param connectTimeout connection timeout in milliseconds. 0 for an infinite timeout, a
- * negative number for the default value (20000).
+ * negative number for the default value (20000).
* @return the builder.
*/
public B connectTimeout(int connectTimeout) {
@@ -275,8 +281,8 @@ public B connectTimeout(int connectTimeout) {
/**
* Sets the timeout in milliseconds to read data from an established connection.
*
- * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a
- * negative number for the default value (20000).
+ * @param readTimeout read timeout in milliseconds. 0 for an infinite timeout, a negative number
+ * for the default value (20000).
* @return the builder.
*/
public B readTimeout(int readTimeout) {
@@ -362,10 +368,10 @@ protected static String googleCloudProjectId() {
} catch (IOException ignore) {
// ignore
}
- File configDir;
+ File configDir;
if (System.getenv().containsKey("CLOUDSDK_CONFIG")) {
configDir = new File(System.getenv("CLOUDSDK_CONFIG"));
- } else if (isWindows() && System.getenv().containsKey("APPDATA")) {
+ } else if (isWindows() && System.getenv().containsKey("APPDATA")) {
configDir = new File(System.getenv("APPDATA"), "gcloud");
} else {
configDir = new File(System.getProperty("user.home"), ".config/gcloud");
@@ -509,8 +515,8 @@ public int readTimeout() {
}
/**
- * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to
- * get current time.
+ * Returns the service's clock. Default time source uses {@link System#currentTimeMillis()} to get
+ * current time.
*/
public Clock clock() {
return clock;
diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java
index 46ff1b5b847b..328573ac7164 100644
--- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java
+++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java
@@ -49,6 +49,8 @@ public class DatastoreOptions extends ServiceOptions readerState = reader.capture();
@@ -194,7 +189,7 @@ public void testSaveAndRestore() throws IOException, ClassNotFoundException {
@Test
public void testStateEquals() {
- EasyMock.replay(storageRpcMock);
+ replay(storageRpcMock);
reader = new BlobReadChannelImpl(options, BLOB_ID, EMPTY_RPC_OPTIONS);
BlobReadChannel secondReader = new BlobReadChannelImpl(options, BLOB_ID, EMPTY_RPC_OPTIONS);
RestorableState state = reader.capture();
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java
index fdb75fe8cad4..6faa36173ab9 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobWriteChannelImplTest.java
@@ -16,6 +16,14 @@
package com.google.gcloud.storage;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.captureLong;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -29,7 +37,6 @@
import org.easymock.Capture;
import org.easymock.CaptureType;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -53,16 +60,17 @@ public class BlobWriteChannelImplTest {
private static final Random RANDOM = new Random();
private StorageOptions options;
+ private StorageRpcFactory rpcFactoryMock;
private StorageRpc storageRpcMock;
private BlobWriteChannelImpl writer;
@Before
public void setUp() throws IOException, InterruptedException {
- StorageRpcFactory rpcFactoryMock = EasyMock.createNiceMock(StorageRpcFactory.class);
- storageRpcMock = EasyMock.createMock(StorageRpc.class);
- EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(StorageOptions.class)))
+ rpcFactoryMock = createMock(StorageRpcFactory.class);
+ storageRpcMock = createMock(StorageRpc.class);
+ expect(rpcFactoryMock.create(anyObject(StorageOptions.class)))
.andReturn(storageRpcMock);
- EasyMock.replay(rpcFactoryMock);
+ replay(rpcFactoryMock);
options = StorageOptions.builder()
.projectId("projectid")
.serviceRpcFactory(rpcFactoryMock)
@@ -71,34 +79,32 @@ public void setUp() throws IOException, InterruptedException {
@After
public void tearDown() throws Exception {
- verify(storageRpcMock);
+ verify(rpcFactoryMock, storageRpcMock);
}
@Test
public void testCreate() {
- EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
- EasyMock.replay(storageRpcMock);
+ expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
+ replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
assertTrue(writer.isOpen());
}
@Test
public void testWriteWithoutFlush() throws IOException {
- EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
- EasyMock.replay(storageRpcMock);
+ expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
+ replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
assertEquals(MIN_CHUNK_SIZE, writer.write(ByteBuffer.allocate(MIN_CHUNK_SIZE)));
}
@Test
public void testWriteWithFlush() throws IOException {
- EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
+ expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture capturedBuffer = Capture.newInstance();
- storageRpcMock.write(EasyMock.eq(UPLOAD_ID), EasyMock.capture(capturedBuffer), EasyMock.eq(0),
- EasyMock.eq(BLOB_INFO.toPb()), EasyMock.eq(0L), EasyMock.eq(CUSTOM_CHUNK_SIZE),
- EasyMock.eq(false));
- EasyMock.expectLastCall();
- EasyMock.replay(storageRpcMock);
+ storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
+ eq(BLOB_INFO.toPb()), eq(0L), eq(CUSTOM_CHUNK_SIZE), eq(false));
+ replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
writer.chunkSize(CUSTOM_CHUNK_SIZE);
ByteBuffer buffer = randomBuffer(CUSTOM_CHUNK_SIZE);
@@ -108,13 +114,12 @@ public void testWriteWithFlush() throws IOException {
@Test
public void testWritesAndFlush() throws IOException {
- EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
+ expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture capturedBuffer = Capture.newInstance();
- storageRpcMock.write(EasyMock.eq(UPLOAD_ID), EasyMock.capture(capturedBuffer), EasyMock.eq(0),
- EasyMock.eq(BLOB_INFO.toPb()), EasyMock.eq(0L), EasyMock.eq(DEFAULT_CHUNK_SIZE),
- EasyMock.eq(false));
- EasyMock.expectLastCall();
- EasyMock.replay(storageRpcMock);
+ storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
+ eq(BLOB_INFO.toPb()), eq(0L), eq(DEFAULT_CHUNK_SIZE),
+ eq(false));
+ replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
ByteBuffer[] buffers = new ByteBuffer[DEFAULT_CHUNK_SIZE / MIN_CHUNK_SIZE];
for (int i = 0; i < buffers.length; i++) {
@@ -131,12 +136,11 @@ public void testWritesAndFlush() throws IOException {
@Test
public void testCloseWithoutFlush() throws IOException {
- EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
+ expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture capturedBuffer = Capture.newInstance();
- storageRpcMock.write(EasyMock.eq(UPLOAD_ID), EasyMock.capture(capturedBuffer), EasyMock.eq(0),
- EasyMock.eq(BLOB_INFO.toPb()), EasyMock.eq(0L), EasyMock.eq(0), EasyMock.eq(true));
- EasyMock.expectLastCall();
- EasyMock.replay(storageRpcMock);
+ storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
+ eq(BLOB_INFO.toPb()), eq(0L), eq(0), eq(true));
+ replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
assertTrue(writer.isOpen());
writer.close();
@@ -146,14 +150,13 @@ public void testCloseWithoutFlush() throws IOException {
@Test
public void testCloseWithFlush() throws IOException {
- EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
+ expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture capturedBuffer = Capture.newInstance();
ByteBuffer buffer = randomBuffer(MIN_CHUNK_SIZE);
- storageRpcMock.write(EasyMock.eq(UPLOAD_ID), EasyMock.capture(capturedBuffer), EasyMock.eq(0),
- EasyMock.eq(BLOB_INFO.toPb()), EasyMock.eq(0L), EasyMock.eq(MIN_CHUNK_SIZE),
- EasyMock.eq(true));
- EasyMock.expectLastCall();
- EasyMock.replay(storageRpcMock);
+ storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
+ eq(BLOB_INFO.toPb()), eq(0L), eq(MIN_CHUNK_SIZE),
+ eq(true));
+ replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
assertTrue(writer.isOpen());
writer.write(buffer);
@@ -165,12 +168,11 @@ public void testCloseWithFlush() throws IOException {
@Test
public void testWriteClosed() throws IOException {
- EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
+ expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture capturedBuffer = Capture.newInstance();
- storageRpcMock.write(EasyMock.eq(UPLOAD_ID), EasyMock.capture(capturedBuffer), EasyMock.eq(0),
- EasyMock.eq(BLOB_INFO.toPb()), EasyMock.eq(0L), EasyMock.eq(0), EasyMock.eq(true));
- EasyMock.expectLastCall();
- EasyMock.replay(storageRpcMock);
+ storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
+ eq(BLOB_INFO.toPb()), eq(0L), eq(0), eq(true));
+ replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
writer.close();
try {
@@ -183,14 +185,14 @@ public void testWriteClosed() throws IOException {
@Test
public void testSaveAndRestore() throws IOException {
- EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
+ expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture capturedBuffer = Capture.newInstance(CaptureType.ALL);
Capture capturedPosition = Capture.newInstance(CaptureType.ALL);
- storageRpcMock.write(EasyMock.eq(UPLOAD_ID), EasyMock.capture(capturedBuffer), EasyMock.eq(0),
- EasyMock.eq(BLOB_INFO.toPb()), EasyMock.captureLong(capturedPosition),
- EasyMock.eq(DEFAULT_CHUNK_SIZE), EasyMock.eq(false));
- EasyMock.expectLastCall().times(2);
- EasyMock.replay(storageRpcMock);
+ storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
+ eq(BLOB_INFO.toPb()), captureLong(capturedPosition),
+ eq(DEFAULT_CHUNK_SIZE), eq(false));
+ expectLastCall().times(2);
+ replay(storageRpcMock);
ByteBuffer buffer1 = randomBuffer(DEFAULT_CHUNK_SIZE);
ByteBuffer buffer2 = randomBuffer(DEFAULT_CHUNK_SIZE);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
@@ -206,12 +208,11 @@ public void testSaveAndRestore() throws IOException {
@Test
public void testSaveAndRestoreClosed() throws IOException {
- EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
+ expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID);
Capture capturedBuffer = Capture.newInstance();
- storageRpcMock.write(EasyMock.eq(UPLOAD_ID), EasyMock.capture(capturedBuffer), EasyMock.eq(0),
- EasyMock.eq(BLOB_INFO.toPb()), EasyMock.eq(0L), EasyMock.eq(0), EasyMock.eq(true));
- EasyMock.expectLastCall();
- EasyMock.replay(storageRpcMock);
+ storageRpcMock.write(eq(UPLOAD_ID), capture(capturedBuffer), eq(0),
+ eq(BLOB_INFO.toPb()), eq(0L), eq(0), eq(true));
+ replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
writer.close();
RestorableState writerState = writer.capture();
@@ -229,9 +230,9 @@ public void testSaveAndRestoreClosed() throws IOException {
@Test
public void testStateEquals() {
- EasyMock.expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID)
+ expect(storageRpcMock.open(BLOB_INFO.toPb(), EMPTY_RPC_OPTIONS)).andReturn(UPLOAD_ID)
.times(2);
- EasyMock.replay(storageRpcMock);
+ replay(storageRpcMock);
writer = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
BlobWriteChannel writer2 = new BlobWriteChannelImpl(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
RestorableState state = writer.capture();
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
index 1dd310cdc8b5..a0bae0e0e29e 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
@@ -54,7 +54,6 @@
public class ITStorageTest {
private static Storage storage;
- private static RemoteGcsHelper gcsHelper;
private static final Logger log = Logger.getLogger(ITStorageTest.class.getName());
private static final String bucket = RemoteGcsHelper.generateBucketName();
@@ -64,7 +63,7 @@ public class ITStorageTest {
@BeforeClass
public static void beforeClass() {
- gcsHelper = RemoteGcsHelper.create();
+ RemoteGcsHelper gcsHelper = RemoteGcsHelper.create();
storage = gcsHelper.options().service();
storage.create(BucketInfo.of(bucket));
}
@@ -445,7 +444,7 @@ public void testBatchRequestFail() {
}
@Test
- public void testReadAndWriteChannels() throws UnsupportedEncodingException, IOException {
+ public void testReadAndWriteChannels() throws IOException {
String blobName = "test-read-and-write-channels-blob";
BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
byte[] stringBytes;
@@ -468,7 +467,7 @@ public void testReadAndWriteChannels() throws UnsupportedEncodingException, IOEx
}
@Test
- public void testReadAndWriteSaveChannels() throws UnsupportedEncodingException, IOException {
+ public void testReadAndWriteCaptureChannels() throws IOException {
String blobName = "test-read-and-write-capture-channels-blob";
BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
byte[] stringBytes;
@@ -497,7 +496,7 @@ public void testReadAndWriteSaveChannels() throws UnsupportedEncodingException,
}
@Test
- public void testReadChannelFail() throws UnsupportedEncodingException, IOException {
+ public void testReadChannelFail() throws IOException {
String blobName = "test-read-channel-blob-fail";
BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
assertNotNull(storage.create(blob));
@@ -512,7 +511,7 @@ public void testReadChannelFail() throws UnsupportedEncodingException, IOExcepti
}
@Test
- public void testWriteChannelFail() throws UnsupportedEncodingException, IOException {
+ public void testWriteChannelFail() throws IOException {
String blobName = "test-write-channel-blob-fail";
BlobInfo blob = BlobInfo.builder(bucket, blobName).generation(-1L).build();
try {
@@ -527,7 +526,7 @@ public void testWriteChannelFail() throws UnsupportedEncodingException, IOExcept
}
@Test
- public void testWriteChannelExistingBlob() throws UnsupportedEncodingException, IOException {
+ public void testWriteChannelExistingBlob() throws IOException {
String blobName = "test-write-channel-existing-blob";
BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
BlobInfo remoteBlob = storage.create(blob);
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
index 4aa4a84a7975..9c80d43396c0 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
@@ -200,6 +200,7 @@ public long millis() {
private static PublicKey publicKey;
private StorageOptions options;
+ private StorageRpcFactory rpcFactoryMock;
private StorageRpc storageRpcMock;
private Storage storage;
@@ -219,7 +220,7 @@ public static void beforeClass() throws NoSuchAlgorithmException, InvalidKeySpec
@Before
public void setUp() throws IOException, InterruptedException {
- StorageRpcFactory rpcFactoryMock = EasyMock.createNiceMock(StorageRpcFactory.class);
+ rpcFactoryMock = EasyMock.createMock(StorageRpcFactory.class);
storageRpcMock = EasyMock.createMock(StorageRpc.class);
EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(StorageOptions.class)))
.andReturn(storageRpcMock);
@@ -234,7 +235,7 @@ public void setUp() throws IOException, InterruptedException {
@After
public void tearDown() throws Exception {
- EasyMock.verify(storageRpcMock);
+ EasyMock.verify(rpcFactoryMock, storageRpcMock);
}
@Test
From fd556b8035122a8a18bad54ef8188bc13ae2cec1 Mon Sep 17 00:00:00 2001
From: aozarov
Date: Tue, 27 Oct 2015 12:24:53 -0700
Subject: [PATCH 021/322] add and fix copyright headers
---
.../main/java/com/google/gcloud/Restorable.java | 16 ++++++++++++++++
.../java/com/google/gcloud/ServiceOptions.java | 16 +++++++++-------
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/Restorable.java b/gcloud-java-core/src/main/java/com/google/gcloud/Restorable.java
index 83ef39a4dd73..51391e33bd7d 100644
--- a/gcloud-java-core/src/main/java/com/google/gcloud/Restorable.java
+++ b/gcloud-java-core/src/main/java/com/google/gcloud/Restorable.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2015 Google Inc. All Rights Reserved.
+ *
+ * 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.gcloud;
/**
diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
index 4a68aa7894f7..f22c4d51e371 100644
--- a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
+++ b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
@@ -1,15 +1,17 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
- * 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
+ * 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
+ * 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.
+ * 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.gcloud;
From 207c00a3554efbc70041466ee9a4a6d982cb62d2 Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Tue, 27 Oct 2015 22:39:50 +0100
Subject: [PATCH 022/322] Copy report configuration to submodules poms
---
gcloud-java-core/pom.xml | 77 +++++++++++++++++++++++++++++++++++
gcloud-java-datastore/pom.xml | 77 +++++++++++++++++++++++++++++++++++
gcloud-java-examples/pom.xml | 77 +++++++++++++++++++++++++++++++++++
gcloud-java-storage/pom.xml | 77 +++++++++++++++++++++++++++++++++++
gcloud-java/pom.xml | 77 +++++++++++++++++++++++++++++++++++
5 files changed, 385 insertions(+)
diff --git a/gcloud-java-core/pom.xml b/gcloud-java-core/pom.xml
index 1062f4d3110c..6d25aa42ce95 100644
--- a/gcloud-java-core/pom.xml
+++ b/gcloud-java-core/pom.xml
@@ -97,13 +97,90 @@
maven-site-plugin
3.4
+ true
+
+ org.apache.maven.plugins
+ maven-changelog-plugin
+ 2.3
+
org.apache.maven.plugins
maven-project-info-reports-plugin
2.8
+
+
+
+ index
+ dependency-info
+ dependencies
+ dependency-convergence
+ project-team
+ mailing-list
+ cim
+ issue-tracking
+ license
+ scm
+ dependency-management
+ distribution-management
+ summary
+ modules
+
+
+
+ true
+ true
+ true
+ true
gcloud-java-core
+ jar
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 2.10
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.10.3
+
+
+ html
+
+ javadoc
+
+
+
+
+ true
+ protected
+ true
+ ${project.build.directory}/javadoc
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-report-plugin
+ 2.18.1
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 2.16
+
+ checkstyle.xml
+ false
+
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ 2.7
+
+ true
diff --git a/gcloud-java-datastore/pom.xml b/gcloud-java-datastore/pom.xml
index 700f14c03a51..6cd56e2c2211 100644
--- a/gcloud-java-datastore/pom.xml
+++ b/gcloud-java-datastore/pom.xml
@@ -45,13 +45,90 @@
maven-site-plugin
3.4
+ true
+
+ org.apache.maven.plugins
+ maven-changelog-plugin
+ 2.3
+
org.apache.maven.plugins
maven-project-info-reports-plugin
2.8
+
+
+
+ index
+ dependency-info
+ dependencies
+ dependency-convergence
+ project-team
+ mailing-list
+ cim
+ issue-tracking
+ license
+ scm
+ dependency-management
+ distribution-management
+ summary
+ modules
+
+
+
+ true
+ true
+ true
+ true
gcloud-java-datastore
+ jar
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 2.10
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.10.3
+
+
+ html
+
+ javadoc
+
+
+
+
+ true
+ protected
+ true
+ ${project.build.directory}/javadoc
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-report-plugin
+ 2.18.1
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 2.16
+
+ checkstyle.xml
+ false
+
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ 2.7
+
+ true
diff --git a/gcloud-java-examples/pom.xml b/gcloud-java-examples/pom.xml
index 4f5649797f78..c795571a0ff1 100644
--- a/gcloud-java-examples/pom.xml
+++ b/gcloud-java-examples/pom.xml
@@ -34,13 +34,90 @@
maven-site-plugin
3.4
+ true
+
+ org.apache.maven.plugins
+ maven-changelog-plugin
+ 2.3
+
org.apache.maven.plugins
maven-project-info-reports-plugin
2.8
+
+
+
+ index
+ dependency-info
+ dependencies
+ dependency-convergence
+ project-team
+ mailing-list
+ cim
+ issue-tracking
+ license
+ scm
+ dependency-management
+ distribution-management
+ summary
+ modules
+
+
+
+ true
+ true
+ true
+ true
gcloud-java-examples
+ jar
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 2.10
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.10.3
+
+
+ html
+
+ javadoc
+
+
+
+
+ true
+ protected
+ true
+ ${project.build.directory}/javadoc
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-report-plugin
+ 2.18.1
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 2.16
+
+ checkstyle.xml
+ false
+
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ 2.7
+
+ true
diff --git a/gcloud-java-storage/pom.xml b/gcloud-java-storage/pom.xml
index 439fa540e479..f682f498da6c 100644
--- a/gcloud-java-storage/pom.xml
+++ b/gcloud-java-storage/pom.xml
@@ -51,13 +51,90 @@
maven-site-plugin
3.4
+ true
+
+ org.apache.maven.plugins
+ maven-changelog-plugin
+ 2.3
+
org.apache.maven.plugins
maven-project-info-reports-plugin
2.8
+
+
+
+ index
+ dependency-info
+ dependencies
+ dependency-convergence
+ project-team
+ mailing-list
+ cim
+ issue-tracking
+ license
+ scm
+ dependency-management
+ distribution-management
+ summary
+ modules
+
+
+
+ true
+ true
+ true
+ true
gcloud-java-storage
+ jar
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 2.10
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.10.3
+
+
+ html
+
+ javadoc
+
+
+
+
+ true
+ protected
+ true
+ ${project.build.directory}/javadoc
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-report-plugin
+ 2.18.1
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 2.16
+
+ checkstyle.xml
+ false
+
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ 2.7
+
+ true
diff --git a/gcloud-java/pom.xml b/gcloud-java/pom.xml
index 9b8614c20431..df5f1352881e 100644
--- a/gcloud-java/pom.xml
+++ b/gcloud-java/pom.xml
@@ -37,13 +37,90 @@
maven-site-plugin
3.4
+ true
+
+ org.apache.maven.plugins
+ maven-changelog-plugin
+ 2.3
+
org.apache.maven.plugins
maven-project-info-reports-plugin
2.8
+
+
+
+ index
+ dependency-info
+ dependencies
+ dependency-convergence
+ project-team
+ mailing-list
+ cim
+ issue-tracking
+ license
+ scm
+ dependency-management
+ distribution-management
+ summary
+ modules
+
+
+
+ true
+ true
+ true
+ true
gcloud-java
+ jar
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 2.10
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ 2.10.3
+
+
+ html
+
+ javadoc
+
+
+
+
+ true
+ protected
+ true
+ ${project.build.directory}/javadoc
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-report-plugin
+ 2.18.1
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 2.16
+
+ checkstyle.xml
+ false
+
+
+
+ org.codehaus.mojo
+ cobertura-maven-plugin
+ 2.7
+
+ true
From 736a0f573ebbd6b2b656d93f0c8ac254fc3c24c8 Mon Sep 17 00:00:00 2001
From: aozarov
Date: Tue, 27 Oct 2015 17:28:50 -0700
Subject: [PATCH 023/322] fix checkstyle issues
---
.../java/com/google/gcloud/RetryParams.java | 3 +-
.../com/google/gcloud/ServiceOptions.java | 10 +-
.../google/gcloud/ExceptionHandlerTest.java | 2 +-
.../com/google/gcloud/datastore/Blob.java | 3 +-
.../google/gcloud/datastore/Transaction.java | 3 +-
.../google/gcloud/datastore/BaseKeyTest.java | 4 +-
.../gcloud/datastore/DatastoreTest.java | 3 +-
.../gcloud/datastore/ListValueTest.java | 3 +-
.../gcloud/datastore/SerializationTest.java | 4 +-
.../google/gcloud/datastore/ValueTest.java | 7 +-
.../gcloud/examples/DatastoreExample.java | 2 +-
.../gcloud/examples/StorageExample.java | 8 +-
.../java/com/google/gcloud/storage/Acl.java | 5 +-
.../com/google/gcloud/storage/BlobId.java | 2 +-
.../com/google/gcloud/storage/BlobInfo.java | 4 +-
.../com/google/gcloud/storage/BucketInfo.java | 4 +-
.../java/com/google/gcloud/storage/Cors.java | 2 +-
.../google/gcloud/storage/StorageImpl.java | 7 +-
.../storage/testing/RemoteGcsHelper.java | 4 +-
.../gcloud/storage/BlobListResultTest.java | 3 +-
.../com/google/gcloud/storage/BucketTest.java | 10 +-
.../google/gcloud/storage/ITStorageTest.java | 202 +++++++++---------
.../com/google/gcloud/storage/OptionTest.java | 2 +-
.../gcloud/storage/RemoteGcsHelperTest.java | 20 +-
.../gcloud/storage/SerializationTest.java | 4 +-
25 files changed, 165 insertions(+), 156 deletions(-)
diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/RetryParams.java b/gcloud-java-core/src/main/java/com/google/gcloud/RetryParams.java
index 24983326ccae..461dbac77ff2 100644
--- a/gcloud-java-core/src/main/java/com/google/gcloud/RetryParams.java
+++ b/gcloud-java-core/src/main/java/com/google/gcloud/RetryParams.java
@@ -251,7 +251,8 @@ public double getRetryDelayBackoffFactor() {
}
/**
- * Returns the totalRetryPeriodMillis. Default value is {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}.
+ * Returns the totalRetryPeriodMillis. Default value is
+ * {@value #DEFAULT_TOTAL_RETRY_PERIOD_MILLIS}.
*/
public long getTotalRetryPeriodMillis() {
return totalRetryPeriodMillis;
diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
index f22c4d51e371..8555b8d61ed4 100644
--- a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
+++ b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
@@ -48,9 +48,9 @@
import java.util.regex.Pattern;
public abstract class ServiceOptions<
- ServiceT extends Service,
- ServiceRpcT,
- OptionsT extends ServiceOptions>
+ ServiceT extends Service,
+ ServiceRpcT,
+ OptionsT extends ServiceOptions>
implements Serializable {
private static final String DEFAULT_HOST = "https://www.googleapis.com";
@@ -116,9 +116,9 @@ public HttpTransport create() {
* Implementations should implement {@code Serializable} wherever possible and must document
* whether or not they do support serialization.
*/
- public static abstract class Clock {
+ public abstract static class Clock {
- private static ServiceOptions.Clock DEFAULT_TIME_SOURCE = new DefaultClock();
+ private static final ServiceOptions.Clock DEFAULT_TIME_SOURCE = new DefaultClock();
/**
* Returns current time in milliseconds according to this clock.
diff --git a/gcloud-java-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java b/gcloud-java-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java
index 5ce05ad900a8..c182515dbb16 100644
--- a/gcloud-java-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java
+++ b/gcloud-java-core/src/test/java/com/google/gcloud/ExceptionHandlerTest.java
@@ -23,9 +23,9 @@
import com.google.gcloud.ExceptionHandler.Interceptor;
import com.google.gcloud.ExceptionHandler.Interceptor.RetryResult;
-import org.junit.rules.ExpectedException;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import java.io.FileNotFoundException;
import java.io.IOException;
diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Blob.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Blob.java
index 5a759240be38..0c4d6c26d9fa 100644
--- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Blob.java
+++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Blob.java
@@ -35,7 +35,8 @@
* A Google Cloud Datastore Blob.
* This class is immutable.
*
- * @see Google Cloud Datastore Entities, Properties, and Keys
+ * @see
+ * Google Cloud Datastore Entities, Properties, and Keys
*/
public final class Blob extends Serializable {
diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Transaction.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Transaction.java
index 9d676bc68a8c..8089c0130f5d 100644
--- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Transaction.java
+++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/Transaction.java
@@ -47,7 +47,8 @@
* }
* }
*
- * @see
Google Cloud Datastore transactions
+ * @see
+ * Google Cloud Datastore transactions
*
*/
public interface Transaction extends DatastoreBatchWriter, DatastoreReaderWriter {
diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseKeyTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseKeyTest.java
index e99e7a60fd0b..8615ee025bd1 100644
--- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseKeyTest.java
+++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseKeyTest.java
@@ -115,10 +115,10 @@ public void testAncestors() throws Exception {
BaseKey key = builder.build();
assertTrue(key.ancestors().isEmpty());
List
path = new ArrayList<>();
- path.add(PathElement.of("p1","v1"));
+ path.add(PathElement.of("p1", "v1"));
key = builder.ancestors(path.get(0)).build();
assertEquals(path, key.ancestors());
- path.add(PathElement.of("p2","v2"));
+ path.add(PathElement.of("p2", "v2"));
key = builder.ancestors(path.get(1)).build();
assertEquals(path, key.ancestors());
}
diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java
index c0d21456d28f..1d2bb4889658 100644
--- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java
+++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java
@@ -346,7 +346,8 @@ public void testNewBatch() {
@Test
public void testRunGqlQueryNoCasting() {
- Query query1 = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND1).build();
+ Query query1 =
+ Query.gqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND1).build();
QueryResults results1 = datastore.run(query1);
assertTrue(results1.hasNext());
assertEquals(ENTITY1, results1.next());
diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ListValueTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ListValueTest.java
index 36e3571d49ac..7af82c29901d 100644
--- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ListValueTest.java
+++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ListValueTest.java
@@ -28,7 +28,8 @@
public class ListValueTest {
- private static final List> CONTENT = ImmutableList.of(NullValue.of(), StringValue.of("foo"));
+ private static final List> CONTENT =
+ ImmutableList.of(NullValue.of(), StringValue.of("foo"));
@Test
public void testToBuilder() throws Exception {
diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java
index 5f3bfc036fa2..1ad690938ef5 100644
--- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java
+++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/SerializationTest.java
@@ -48,8 +48,8 @@ public class SerializationTest {
private static final Key KEY2 = Key.builder(KEY1, "v", 2).build();
private static final DateTime DATE_TIME1 = DateTime.now();
private static final Blob BLOB1 = Blob.copyFrom(UTF_8.encode("hello world"));
- private static final Cursor CURSOR1 = Cursor.copyFrom(new byte[] {1,2});
- private static final Cursor CURSOR2 = Cursor.copyFrom(new byte[]{10});
+ private static final Cursor CURSOR1 = Cursor.copyFrom(new byte[] {1, 2});
+ private static final Cursor CURSOR2 = Cursor.copyFrom(new byte[] {10});
private static final Query> GQL1 =
Query.gqlQueryBuilder("select * from kind1 where name = @name and age > @1")
.setBinding("name", "name1")
diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ValueTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ValueTest.java
index 973a3c3c0da4..199b3f90f442 100644
--- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ValueTest.java
+++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/ValueTest.java
@@ -42,7 +42,8 @@ public class ValueTest {
private static final NullValue NULL_VALUE = NullValue.of();
private static final StringValue STRING_VALUE = StringValue.of("hello");
private static final RawValue RAW_VALUE = RawValue.of(STRING_VALUE.toPb());
- private static final ImmutableMap TYPES = ImmutableMap.builder()
+ private static final ImmutableMap TYPES =
+ ImmutableMap.builder()
.put(ValueType.NULL, new Object[] {NullValue.class, NULL_VALUE.get()})
.put(ValueType.KEY, new Object[] {KeyValue.class, KEY})
.put(ValueType.BLOB, new Object[] {BlobValue.class, BLOB})
@@ -160,7 +161,7 @@ public void testIndexed() throws Exception {
@SuppressWarnings("deprecation")
@Test
public void testHasMeaning() throws Exception {
- for (Value> value: typeToValue.values()) {
+ for (Value> value : typeToValue.values()) {
assertFalse(value.hasMeaning());
}
@@ -171,7 +172,7 @@ public void testHasMeaning() throws Exception {
@SuppressWarnings("deprecation")
@Test
public void testMeaning() throws Exception {
- for (Value> value: typeToValue.values()) {
+ for (Value> value : typeToValue.values()) {
assertNull(value.meaning());
}
diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java
index a3b1257f943a..93bb1b5b93b4 100644
--- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java
+++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/DatastoreExample.java
@@ -202,7 +202,7 @@ public static void main(String... args) {
DatastoreExample.class.getSimpleName(), actionAndParams);
return;
}
- args = args.length > 3 ? Arrays.copyOfRange(args, 3, args.length): new String []{};
+ args = args.length > 3 ? Arrays.copyOfRange(args, 3, args.length) : new String []{};
Transaction tx = datastore.newTransaction();
try {
action.run(tx, key, args);
diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
index 46fb94297ec7..274710f10e93 100644
--- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
+++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
@@ -83,7 +83,7 @@ public class StorageExample {
private static final Map ACTIONS = new HashMap<>();
- private static abstract class StorageAction {
+ private abstract static class StorageAction {
abstract void run(Storage storage, T request) throws Exception;
@@ -94,7 +94,7 @@ protected String params() {
}
}
- private static abstract class BlobsAction extends StorageAction {
+ private abstract static class BlobsAction extends StorageAction {
@Override
BlobId[] parse(String... args) {
@@ -483,8 +483,8 @@ public void run(Storage storage, Tuple
private void run(Storage storage, ServiceAccountAuthCredentials cred, BlobInfo blobInfo)
throws IOException {
Blob blob = new Blob(storage, blobInfo);
- System.out.println("Signed URL: " +
- blob.signUrl(1, TimeUnit.DAYS, SignUrlOption.serviceAccount(cred)));
+ System.out.println("Signed URL: "
+ + blob.signUrl(1, TimeUnit.DAYS, SignUrlOption.serviceAccount(cred)));
}
@Override
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java
index e5e319b39164..3d9731352400 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Acl.java
@@ -36,7 +36,7 @@ public enum Role {
OWNER, READER, WRITER
}
- public static abstract class Entity implements Serializable {
+ public abstract static class Entity implements Serializable {
private static final long serialVersionUID = -2707407252771255840L;
@@ -69,8 +69,7 @@ public boolean equals(Object o) {
return false;
}
Entity entity = (Entity) o;
- return Objects.equals(type, entity.type) &&
- Objects.equals(value, entity.value);
+ return Objects.equals(type, entity.type) && Objects.equals(value, entity.value);
}
@Override
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobId.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobId.java
index ea98e65d244d..eafebe09a4cb 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobId.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobId.java
@@ -16,9 +16,9 @@
package com.google.gcloud.storage;
-import com.google.api.services.storage.model.StorageObject;
import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.api.services.storage.model.StorageObject;
import com.google.common.base.MoreObjects;
import java.io.Serializable;
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java
index ec3ef36708cb..01711a53613e 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobInfo.java
@@ -204,8 +204,8 @@ Builder mediaLink(String mediaLink) {
}
public Builder metadata(Map metadata) {
- this.metadata = metadata != null ?
- new HashMap(metadata) : Data.nullOf(ImmutableEmptyMap.class);
+ this.metadata = metadata != null
+ ? new HashMap(metadata) : Data.nullOf(ImmutableEmptyMap.class);
return this;
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BucketInfo.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BucketInfo.java
index ddd4665ca129..5d69c54e0d96 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BucketInfo.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BucketInfo.java
@@ -83,7 +83,7 @@ public com.google.api.services.storage.model.Bucket apply(BucketInfo bucketInfo)
private final Location location;
private final StorageClass storageClass;
- public static abstract class DeleteRule implements Serializable {
+ public abstract static class DeleteRule implements Serializable {
private static final long serialVersionUID = 3137971668395933033L;
private static final String SUPPORTED_ACTION = "Delete";
@@ -393,7 +393,7 @@ public static Location of(String value) {
}
}
- public final static class Builder {
+ public static final class Builder {
private String id;
private String name;
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Cors.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Cors.java
index ce8cfb95b6e9..a94359f17a79 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Cors.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Cors.java
@@ -98,7 +98,7 @@ public boolean equals(Object obj) {
if (!(obj instanceof Origin)) {
return false;
}
- return value.equals(((Origin)obj).value);
+ return value.equals(((Origin) obj).value);
}
@Override
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
index 6856ee27eec7..21cd8b726753 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
@@ -222,7 +222,7 @@ public BlobInfo get(BlobId blob) {
return get(blob, new BlobSourceOption[0]);
}
- private static abstract class BasePageFetcher
+ private abstract static class BasePageFetcher
implements BaseListResult.NextPageFetcher {
private static final long serialVersionUID = 8236329004030295223L;
@@ -497,7 +497,8 @@ public BatchResponse apply(BatchRequest batchRequest) {
}
List>> toUpdate =
Lists.newArrayListWithCapacity(batchRequest.toUpdate().size());
- for (Map.Entry> entry : batchRequest.toUpdate().entrySet()) {
+ for (Map.Entry> entry :
+ batchRequest.toUpdate().entrySet()) {
BlobInfo blobInfo = entry.getKey();
Map optionsMap =
optionMap(blobInfo.generation(), blobInfo.metageneration(), entry.getValue());
@@ -582,7 +583,7 @@ public URL signUrl(BlobInfo blobInfo, long duration, TimeUnit unit, SignUrlOptio
"Signing key was not provided and could not be derived");
cred = (ServiceAccountAuthCredentials) this.options().authCredentials();
}
- // construct signature data - see https://cloud.google.com/storage/docs/access-control#Signed-URLs
+ // construct signature - see https://cloud.google.com/storage/docs/access-control#Signed-URLs
StringBuilder stBuilder = new StringBuilder();
if (optionMap.containsKey(SignUrlOption.Option.HTTP_METHOD)) {
stBuilder.append(optionMap.get(SignUrlOption.Option.HTTP_METHOD));
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java
index 1e154e3f8eea..6ad655db8670 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java
@@ -17,16 +17,16 @@
package com.google.gcloud.storage.testing;
import com.google.gcloud.AuthCredentials;
-import com.google.gcloud.storage.BlobInfo;
import com.google.gcloud.RetryParams;
+import com.google.gcloud.storage.BlobInfo;
import com.google.gcloud.storage.Storage;
import com.google.gcloud.storage.StorageException;
import com.google.gcloud.storage.StorageOptions;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobListResultTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobListResultTest.java
index 117e2b692c6b..615213ab1516 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobListResultTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobListResultTest.java
@@ -24,11 +24,12 @@
import static org.junit.Assert.assertFalse;
import com.google.common.collect.ImmutableList;
-import java.util.Iterator;
import org.junit.Before;
import org.junit.Test;
+import java.util.Iterator;
+
public class BlobListResultTest {
private static final Iterable FIRST_PAGE_RESULTS = ImmutableList.of(
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java
index 6526f0d2fe8f..370850a5b6d4 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BucketTest.java
@@ -28,6 +28,12 @@
import com.google.common.collect.ImmutableList;
import com.google.gcloud.storage.BatchResponse.Result;
+
+import org.easymock.Capture;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Collections;
@@ -35,10 +41,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import org.easymock.Capture;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
public class BucketTest {
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
index a0bae0e0e29e..7b29086ecbe5 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
@@ -56,7 +56,7 @@ public class ITStorageTest {
private static Storage storage;
private static final Logger log = Logger.getLogger(ITStorageTest.class.getName());
- private static final String bucket = RemoteGcsHelper.generateBucketName();
+ private static final String BUCKET = RemoteGcsHelper.generateBucketName();
private static final String CONTENT_TYPE = "text/plain";
private static final byte[] BLOB_BYTE_CONTENT = {0xD, 0xE, 0xA, 0xD};
private static final String BLOB_STRING_CONTENT = "Hello Google Cloud Storage!";
@@ -65,15 +65,15 @@ public class ITStorageTest {
public static void beforeClass() {
RemoteGcsHelper gcsHelper = RemoteGcsHelper.create();
storage = gcsHelper.options().service();
- storage.create(BucketInfo.of(bucket));
+ storage.create(BucketInfo.of(BUCKET));
}
@AfterClass
public static void afterClass()
throws ExecutionException, TimeoutException, InterruptedException {
- if (storage != null && !RemoteGcsHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS)) {
+ if (storage != null && !RemoteGcsHelper.forceDelete(storage, BUCKET, 5, TimeUnit.SECONDS)) {
if (log.isLoggable(Level.WARNING)) {
- log.log(Level.WARNING, "Deletion of bucket {0} timed out, bucket is not empty", bucket);
+ log.log(Level.WARNING, "Deletion of bucket {0} timed out, bucket is not empty", BUCKET);
}
}
}
@@ -81,58 +81,58 @@ public static void afterClass()
@Test(timeout = 5000)
public void testListBuckets() throws InterruptedException {
Iterator bucketIterator =
- storage.list(Storage.BucketListOption.prefix(bucket)).iterator();
+ storage.list(Storage.BucketListOption.prefix(BUCKET)).iterator();
while (!bucketIterator.hasNext()) {
Thread.sleep(500);
- bucketIterator = storage.list(Storage.BucketListOption.prefix(bucket)).iterator();
+ bucketIterator = storage.list(Storage.BucketListOption.prefix(BUCKET)).iterator();
}
while (bucketIterator.hasNext()) {
- assertTrue(bucketIterator.next().name().startsWith(bucket));
+ assertTrue(bucketIterator.next().name().startsWith(BUCKET));
}
}
@Test
public void testCreateBlob() {
String blobName = "test-create-blob";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
BlobInfo remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT);
assertNotNull(remoteBlob);
assertEquals(blob.blobId(), remoteBlob.blobId());
- byte[] readBytes = storage.readAllBytes(bucket, blobName);
+ byte[] readBytes = storage.readAllBytes(BUCKET, blobName);
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes);
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testCreateEmptyBlob() {
String blobName = "test-create-empty-blob";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
BlobInfo remoteBlob = storage.create(blob);
assertNotNull(remoteBlob);
assertEquals(blob.blobId(), remoteBlob.blobId());
- byte[] readBytes = storage.readAllBytes(bucket, blobName);
+ byte[] readBytes = storage.readAllBytes(BUCKET, blobName);
assertArrayEquals(new byte[0], readBytes);
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testCreateBlobStream() throws UnsupportedEncodingException {
String blobName = "test-create-blob-stream";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).contentType(CONTENT_TYPE).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).contentType(CONTENT_TYPE).build();
ByteArrayInputStream stream = new ByteArrayInputStream(BLOB_STRING_CONTENT.getBytes(UTF_8));
BlobInfo remoteBlob = storage.create(blob, stream);
assertNotNull(remoteBlob);
assertEquals(blob.blobId(), remoteBlob.blobId());
assertEquals(blob.contentType(), remoteBlob.contentType());
- byte[] readBytes = storage.readAllBytes(bucket, blobName);
+ byte[] readBytes = storage.readAllBytes(BUCKET, blobName);
assertEquals(BLOB_STRING_CONTENT, new String(readBytes, UTF_8));
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testCreateBlobFail() {
String blobName = "test-create-blob-fail";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
assertNotNull(storage.create(blob));
try {
storage.create(blob.toBuilder().generation(-1L).build(), BLOB_BYTE_CONTENT,
@@ -141,13 +141,13 @@ public void testCreateBlobFail() {
} catch (StorageException ex) {
// expected
}
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testCreateBlobMd5Fail() throws UnsupportedEncodingException {
String blobName = "test-create-blob-md5-fail";
- BlobInfo blob = BlobInfo.builder(bucket, blobName)
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName)
.contentType(CONTENT_TYPE)
.md5("O1R4G1HJSDUISJjoIYmVhQ==")
.build();
@@ -163,13 +163,13 @@ public void testCreateBlobMd5Fail() throws UnsupportedEncodingException {
@Test
public void testUpdateBlob() {
String blobName = "test-update-blob";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
assertNotNull(storage.create(blob));
BlobInfo updatedBlob = storage.update(blob.toBuilder().contentType(CONTENT_TYPE).build());
assertNotNull(updatedBlob);
assertEquals(blob.blobId(), updatedBlob.blobId());
assertEquals(CONTENT_TYPE, updatedBlob.contentType());
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
@@ -177,7 +177,7 @@ public void testUpdateBlobReplaceMetadata() {
String blobName = "test-update-blob-replace-metadata";
ImmutableMap metadata = ImmutableMap.of("k1", "a");
ImmutableMap newMetadata = ImmutableMap.of("k2", "b");
- BlobInfo blob = BlobInfo.builder(bucket, blobName)
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName)
.contentType(CONTENT_TYPE)
.metadata(metadata)
.build();
@@ -188,7 +188,7 @@ public void testUpdateBlobReplaceMetadata() {
updatedBlob = storage.update(blob.toBuilder().metadata(newMetadata).build());
assertEquals(blob.blobId(), updatedBlob.blobId());
assertEquals(newMetadata, updatedBlob.metadata());
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
@@ -197,7 +197,7 @@ public void testUpdateBlobMergeMetadata() {
ImmutableMap metadata = ImmutableMap.of("k1", "a");
ImmutableMap newMetadata = ImmutableMap.of("k2", "b");
ImmutableMap expectedMetadata = ImmutableMap.of("k1", "a", "k2", "b");
- BlobInfo blob = BlobInfo.builder(bucket, blobName)
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName)
.contentType(CONTENT_TYPE)
.metadata(metadata)
.build();
@@ -206,7 +206,7 @@ public void testUpdateBlobMergeMetadata() {
assertNotNull(updatedBlob);
assertEquals(blob.blobId(), updatedBlob.blobId());
assertEquals(expectedMetadata, updatedBlob.metadata());
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
@@ -217,7 +217,7 @@ public void testUpdateBlobUnsetMetadata() {
newMetadata.put("k1", "a");
newMetadata.put("k2", null);
ImmutableMap expectedMetadata = ImmutableMap.of("k1", "a");
- BlobInfo blob = BlobInfo.builder(bucket, blobName)
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName)
.contentType(CONTENT_TYPE)
.metadata(metadata)
.build();
@@ -226,13 +226,13 @@ public void testUpdateBlobUnsetMetadata() {
assertNotNull(updatedBlob);
assertEquals(blob.blobId(), updatedBlob.blobId());
assertEquals(expectedMetadata, updatedBlob.metadata());
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testUpdateBlobFail() {
String blobName = "test-update-blob-fail";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
assertNotNull(storage.create(blob));
try {
storage.update(blob.toBuilder().contentType(CONTENT_TYPE).generation(-1L).build(),
@@ -241,64 +241,64 @@ public void testUpdateBlobFail() {
} catch (StorageException ex) {
// expected
}
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testDeleteNonExistingBlob() {
String blobName = "test-delete-non-existing-blob";
- assertTrue(!storage.delete(bucket, blobName));
+ assertTrue(!storage.delete(BUCKET, blobName));
}
@Test
public void testDeleteBlobFail() {
String blobName = "test-delete-blob-fail";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
assertNotNull(storage.create(blob));
try {
- storage.delete(bucket, blob.name(), Storage.BlobSourceOption.generationMatch(-1L));
+ storage.delete(BUCKET, blob.name(), Storage.BlobSourceOption.generationMatch(-1L));
fail("StorageException was expected");
} catch (StorageException ex) {
// expected
}
- assertTrue(storage.delete(bucket, blob.name()));
+ assertTrue(storage.delete(BUCKET, blob.name()));
}
@Test
public void testComposeBlob() {
String sourceBlobName1 = "test-compose-blob-source-1";
String sourceBlobName2 = "test-compose-blob-source-2";
- BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build();
- BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build();
+ BlobInfo sourceBlob1 = BlobInfo.builder(BUCKET, sourceBlobName1).build();
+ BlobInfo sourceBlob2 = BlobInfo.builder(BUCKET, sourceBlobName2).build();
assertNotNull(storage.create(sourceBlob1, BLOB_BYTE_CONTENT));
assertNotNull(storage.create(sourceBlob2, BLOB_BYTE_CONTENT));
String targetBlobName = "test-compose-blob-target";
- BlobInfo targetBlob = BlobInfo.builder(bucket, targetBlobName).build();
+ BlobInfo targetBlob = BlobInfo.builder(BUCKET, targetBlobName).build();
Storage.ComposeRequest req =
Storage.ComposeRequest.of(ImmutableList.of(sourceBlobName1, sourceBlobName2), targetBlob);
BlobInfo remoteBlob = storage.compose(req);
assertNotNull(remoteBlob);
assertEquals(targetBlob.blobId(), remoteBlob.blobId());
- byte[] readBytes = storage.readAllBytes(bucket, targetBlobName);
+ byte[] readBytes = storage.readAllBytes(BUCKET, targetBlobName);
byte[] composedBytes = Arrays.copyOf(BLOB_BYTE_CONTENT, BLOB_BYTE_CONTENT.length * 2);
System.arraycopy(BLOB_BYTE_CONTENT, 0, composedBytes, BLOB_BYTE_CONTENT.length,
BLOB_BYTE_CONTENT.length);
assertArrayEquals(composedBytes, readBytes);
- assertTrue(storage.delete(bucket, sourceBlobName1));
- assertTrue(storage.delete(bucket, sourceBlobName2));
- assertTrue(storage.delete(bucket, targetBlobName));
+ assertTrue(storage.delete(BUCKET, sourceBlobName1));
+ assertTrue(storage.delete(BUCKET, sourceBlobName2));
+ assertTrue(storage.delete(BUCKET, targetBlobName));
}
@Test
public void testComposeBlobFail() {
String sourceBlobName1 = "test-compose-blob-fail-source-1";
String sourceBlobName2 = "test-compose-blob-fail-source-2";
- BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build();
- BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build();
+ BlobInfo sourceBlob1 = BlobInfo.builder(BUCKET, sourceBlobName1).build();
+ BlobInfo sourceBlob2 = BlobInfo.builder(BUCKET, sourceBlobName2).build();
assertNotNull(storage.create(sourceBlob1));
assertNotNull(storage.create(sourceBlob2));
String targetBlobName = "test-compose-blob-fail-target";
- BlobInfo targetBlob = BlobInfo.builder(bucket, targetBlobName).build();
+ BlobInfo targetBlob = BlobInfo.builder(BUCKET, targetBlobName).build();
Storage.ComposeRequest req = Storage.ComposeRequest.builder()
.addSource(sourceBlobName1, -1L)
.addSource(sourceBlobName2, -1L)
@@ -310,53 +310,53 @@ public void testComposeBlobFail() {
} catch (StorageException ex) {
// expected
}
- assertTrue(storage.delete(bucket, sourceBlobName1));
- assertTrue(storage.delete(bucket, sourceBlobName2));
+ assertTrue(storage.delete(BUCKET, sourceBlobName1));
+ assertTrue(storage.delete(BUCKET, sourceBlobName2));
}
@Test
public void testCopyBlob() {
String sourceBlobName = "test-copy-blob-source";
- BlobInfo blob = BlobInfo.builder(bucket, sourceBlobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, sourceBlobName).build();
assertNotNull(storage.create(blob, BLOB_BYTE_CONTENT));
String targetBlobName = "test-copy-blob-target";
Storage.CopyRequest req = Storage.CopyRequest.of(blob.blobId(), targetBlobName);
BlobInfo remoteBlob = storage.copy(req);
assertNotNull(remoteBlob);
- assertEquals(bucket, remoteBlob.bucket());
+ assertEquals(BUCKET, remoteBlob.bucket());
assertEquals(targetBlobName, remoteBlob.name());
- byte[] readBytes = storage.readAllBytes(bucket, targetBlobName);
+ byte[] readBytes = storage.readAllBytes(BUCKET, targetBlobName);
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes);
- assertTrue(storage.delete(bucket, sourceBlobName));
- assertTrue(storage.delete(bucket, targetBlobName));
+ assertTrue(storage.delete(BUCKET, sourceBlobName));
+ assertTrue(storage.delete(BUCKET, targetBlobName));
}
@Test
public void testCopyBlobUpdateMetadata() {
String sourceBlobName = "test-copy-blob-update-metadata-source";
- BlobInfo sourceBlob = BlobInfo.builder(bucket, sourceBlobName).build();
+ BlobInfo sourceBlob = BlobInfo.builder(BUCKET, sourceBlobName).build();
assertNotNull(storage.create(sourceBlob));
String targetBlobName = "test-copy-blob-update-metadata-target";
BlobInfo targetBlob =
- BlobInfo.builder(bucket, targetBlobName).contentType(CONTENT_TYPE).build();
- Storage.CopyRequest req = Storage.CopyRequest.of(bucket, sourceBlobName, targetBlob);
+ BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
+ Storage.CopyRequest req = Storage.CopyRequest.of(BUCKET, sourceBlobName, targetBlob);
BlobInfo remoteBlob = storage.copy(req);
assertNotNull(remoteBlob);
assertEquals(targetBlob.blobId(), remoteBlob.blobId());
assertEquals(CONTENT_TYPE, remoteBlob.contentType());
- assertTrue(storage.delete(bucket, sourceBlobName));
- assertTrue(storage.delete(bucket, targetBlobName));
+ assertTrue(storage.delete(BUCKET, sourceBlobName));
+ assertTrue(storage.delete(BUCKET, targetBlobName));
}
@Test
public void testCopyBlobFail() {
String sourceBlobName = "test-copy-blob-fail-source";
- BlobInfo blob = BlobInfo.builder(bucket, sourceBlobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, sourceBlobName).build();
assertNotNull(storage.create(blob));
String targetBlobName = "test-copy-blob-fail-target";
Storage.CopyRequest req = new Storage.CopyRequest.Builder()
- .source(bucket, sourceBlobName)
- .target(BlobInfo.builder(bucket, targetBlobName).build())
+ .source(BUCKET, sourceBlobName)
+ .target(BlobInfo.builder(BUCKET, targetBlobName).build())
.sourceOptions(Storage.BlobSourceOption.metagenerationMatch(-1L))
.build();
try {
@@ -365,15 +365,15 @@ public void testCopyBlobFail() {
} catch (StorageException ex) {
// expected
}
- assertTrue(storage.delete(bucket, sourceBlobName));
+ assertTrue(storage.delete(BUCKET, sourceBlobName));
}
@Test
public void testBatchRequest() {
String sourceBlobName1 = "test-batch-request-blob-1";
String sourceBlobName2 = "test-batch-request-blob-2";
- BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build();
- BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build();
+ BlobInfo sourceBlob1 = BlobInfo.builder(BUCKET, sourceBlobName1).build();
+ BlobInfo sourceBlob2 = BlobInfo.builder(BUCKET, sourceBlobName2).build();
assertNotNull(storage.create(sourceBlob1));
assertNotNull(storage.create(sourceBlob2));
@@ -397,8 +397,8 @@ public void testBatchRequest() {
// Batch get request
BatchRequest getRequest = BatchRequest.builder()
- .get(bucket, sourceBlobName1)
- .get(bucket, sourceBlobName2)
+ .get(BUCKET, sourceBlobName1)
+ .get(BUCKET, sourceBlobName2)
.build();
BatchResponse getResponse = storage.apply(getRequest);
assertEquals(2, getResponse.gets().size());
@@ -411,8 +411,8 @@ public void testBatchRequest() {
// Batch delete request
BatchRequest deleteRequest = BatchRequest.builder()
- .delete(bucket, sourceBlobName1)
- .delete(bucket, sourceBlobName2)
+ .delete(BUCKET, sourceBlobName1)
+ .delete(BUCKET, sourceBlobName2)
.build();
BatchResponse deleteResponse = storage.apply(deleteRequest);
assertEquals(2, deleteResponse.deletes().size());
@@ -425,13 +425,13 @@ public void testBatchRequest() {
@Test
public void testBatchRequestFail() {
String blobName = "test-batch-request-blob-fail";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
assertNotNull(storage.create(blob));
BlobInfo updatedBlob = blob.toBuilder().generation(-1L).build();
BatchRequest batchRequest = BatchRequest.builder()
.update(updatedBlob, Storage.BlobTargetOption.generationMatch())
- .delete(bucket, blobName, Storage.BlobSourceOption.generationMatch(-1L))
- .get(bucket, blobName, Storage.BlobSourceOption.generationMatch(-1L))
+ .delete(BUCKET, blobName, Storage.BlobSourceOption.generationMatch(-1L))
+ .get(BUCKET, blobName, Storage.BlobSourceOption.generationMatch(-1L))
.build();
BatchResponse updateResponse = storage.apply(batchRequest);
assertEquals(1, updateResponse.updates().size());
@@ -440,13 +440,13 @@ public void testBatchRequestFail() {
assertTrue(updateResponse.updates().get(0).failed());
assertTrue(updateResponse.gets().get(0).failed());
assertTrue(updateResponse.deletes().get(0).failed());
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testReadAndWriteChannels() throws IOException {
String blobName = "test-read-and-write-channels-blob";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
byte[] stringBytes;
try (BlobWriteChannel writer = storage.writer(blob)) {
stringBytes = BLOB_STRING_CONTENT.getBytes(UTF_8);
@@ -463,13 +463,13 @@ public void testReadAndWriteChannels() throws IOException {
}
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes.array());
assertEquals(BLOB_STRING_CONTENT, new String(readStringBytes.array(), UTF_8));
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testReadAndWriteCaptureChannels() throws IOException {
String blobName = "test-read-and-write-capture-channels-blob";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
byte[] stringBytes;
BlobWriteChannel writer = storage.writer(blob);
stringBytes = BLOB_STRING_CONTENT.getBytes(UTF_8);
@@ -492,13 +492,13 @@ public void testReadAndWriteCaptureChannels() throws IOException {
secondReader.close();
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes.array());
assertEquals(BLOB_STRING_CONTENT, new String(readStringBytes.array(), UTF_8));
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testReadChannelFail() throws IOException {
String blobName = "test-read-channel-blob-fail";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
assertNotNull(storage.create(blob));
try (BlobReadChannel reader =
storage.reader(blob.blobId(), Storage.BlobSourceOption.metagenerationMatch(-1L))) {
@@ -507,13 +507,13 @@ public void testReadChannelFail() throws IOException {
} catch (StorageException ex) {
// expected
}
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testWriteChannelFail() throws IOException {
String blobName = "test-write-channel-blob-fail";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).generation(-1L).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).generation(-1L).build();
try {
try (BlobWriteChannel writer =
storage.writer(blob, Storage.BlobWriteOption.generationMatch())) {
@@ -528,7 +528,7 @@ public void testWriteChannelFail() throws IOException {
@Test
public void testWriteChannelExistingBlob() throws IOException {
String blobName = "test-write-channel-existing-blob";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
BlobInfo remoteBlob = storage.create(blob);
byte[] stringBytes;
try (BlobWriteChannel writer = storage.writer(remoteBlob)) {
@@ -536,13 +536,13 @@ public void testWriteChannelExistingBlob() throws IOException {
writer.write(ByteBuffer.wrap(stringBytes));
}
assertArrayEquals(stringBytes, storage.readAllBytes(blob.blobId()));
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testGetSignedUrl() throws IOException {
String blobName = "test-get-signed-url-blob";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
assertNotNull(storage.create(blob, BLOB_BYTE_CONTENT));
URL url = storage.signUrl(blob, 1, TimeUnit.HOURS);
URLConnection connection = url.openConnection();
@@ -550,60 +550,60 @@ public void testGetSignedUrl() throws IOException {
try (InputStream responseStream = connection.getInputStream()) {
assertEquals(BLOB_BYTE_CONTENT.length, responseStream.read(readBytes));
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes);
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
}
@Test
public void testPostSignedUrl() throws IOException {
String blobName = "test-post-signed-url-blob";
- BlobInfo blob = BlobInfo.builder(bucket, blobName).build();
+ BlobInfo blob = BlobInfo.builder(BUCKET, blobName).build();
assertNotNull(storage.create(blob));
URL url =
storage.signUrl(blob, 1, TimeUnit.HOURS, Storage.SignUrlOption.httpMethod(HttpMethod.POST));
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.connect();
- BlobInfo remoteBlob = storage.get(bucket, blobName);
+ BlobInfo remoteBlob = storage.get(BUCKET, blobName);
assertNotNull(remoteBlob);
assertEquals(blob.blobId(), remoteBlob.blobId());
- assertTrue(storage.delete(bucket, blobName));
+ assertTrue(storage.delete(BUCKET, blobName));
}
@Test
public void testGetBlobs() {
String sourceBlobName1 = "test-get-blobs-1";
String sourceBlobName2 = "test-get-blobs-2";
- BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build();
- BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build();
+ BlobInfo sourceBlob1 = BlobInfo.builder(BUCKET, sourceBlobName1).build();
+ BlobInfo sourceBlob2 = BlobInfo.builder(BUCKET, sourceBlobName2).build();
assertNotNull(storage.create(sourceBlob1));
assertNotNull(storage.create(sourceBlob2));
List remoteBlobs = storage.get(sourceBlob1.blobId(), sourceBlob2.blobId());
assertEquals(sourceBlob1.blobId(), remoteBlobs.get(0).blobId());
assertEquals(sourceBlob2.blobId(), remoteBlobs.get(1).blobId());
- assertTrue(storage.delete(bucket, sourceBlobName1));
- assertTrue(storage.delete(bucket, sourceBlobName2));
+ assertTrue(storage.delete(BUCKET, sourceBlobName1));
+ assertTrue(storage.delete(BUCKET, sourceBlobName2));
}
@Test
public void testGetBlobsFail() {
String sourceBlobName1 = "test-get-blobs-fail-1";
String sourceBlobName2 = "test-get-blobs-fail-2";
- BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build();
- BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build();
+ BlobInfo sourceBlob1 = BlobInfo.builder(BUCKET, sourceBlobName1).build();
+ BlobInfo sourceBlob2 = BlobInfo.builder(BUCKET, sourceBlobName2).build();
assertNotNull(storage.create(sourceBlob1));
List remoteBlobs = storage.get(sourceBlob1.blobId(), sourceBlob2.blobId());
assertEquals(sourceBlob1.blobId(), remoteBlobs.get(0).blobId());
assertNull(remoteBlobs.get(1));
- assertTrue(storage.delete(bucket, sourceBlobName1));
+ assertTrue(storage.delete(BUCKET, sourceBlobName1));
}
@Test
public void testDeleteBlobs() {
String sourceBlobName1 = "test-delete-blobs-1";
String sourceBlobName2 = "test-delete-blobs-2";
- BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build();
- BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build();
+ BlobInfo sourceBlob1 = BlobInfo.builder(BUCKET, sourceBlobName1).build();
+ BlobInfo sourceBlob2 = BlobInfo.builder(BUCKET, sourceBlobName2).build();
assertNotNull(storage.create(sourceBlob1));
assertNotNull(storage.create(sourceBlob2));
List deleteStatus = storage.delete(sourceBlob1.blobId(), sourceBlob2.blobId());
@@ -615,8 +615,8 @@ public void testDeleteBlobs() {
public void testDeleteBlobsFail() {
String sourceBlobName1 = "test-delete-blobs-fail-1";
String sourceBlobName2 = "test-delete-blobs-fail-2";
- BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build();
- BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build();
+ BlobInfo sourceBlob1 = BlobInfo.builder(BUCKET, sourceBlobName1).build();
+ BlobInfo sourceBlob2 = BlobInfo.builder(BUCKET, sourceBlobName2).build();
assertNotNull(storage.create(sourceBlob1));
List deleteStatus = storage.delete(sourceBlob1.blobId(), sourceBlob2.blobId());
assertTrue(deleteStatus.get(0));
@@ -627,8 +627,8 @@ public void testDeleteBlobsFail() {
public void testUpdateBlobs() {
String sourceBlobName1 = "test-update-blobs-1";
String sourceBlobName2 = "test-update-blobs-2";
- BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build();
- BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build();
+ BlobInfo sourceBlob1 = BlobInfo.builder(BUCKET, sourceBlobName1).build();
+ BlobInfo sourceBlob2 = BlobInfo.builder(BUCKET, sourceBlobName2).build();
BlobInfo remoteBlob1 = storage.create(sourceBlob1);
BlobInfo remoteBlob2 = storage.create(sourceBlob2);
assertNotNull(remoteBlob1);
@@ -640,16 +640,16 @@ public void testUpdateBlobs() {
assertEquals(CONTENT_TYPE, updatedBlobs.get(0).contentType());
assertEquals(sourceBlob2.blobId(), updatedBlobs.get(1).blobId());
assertEquals(CONTENT_TYPE, updatedBlobs.get(1).contentType());
- assertTrue(storage.delete(bucket, sourceBlobName1));
- assertTrue(storage.delete(bucket, sourceBlobName2));
+ assertTrue(storage.delete(BUCKET, sourceBlobName1));
+ assertTrue(storage.delete(BUCKET, sourceBlobName2));
}
@Test
public void testUpdateBlobsFail() {
String sourceBlobName1 = "test-update-blobs-fail-1";
String sourceBlobName2 = "test-update-blobs-fail-2";
- BlobInfo sourceBlob1 = BlobInfo.builder(bucket, sourceBlobName1).build();
- BlobInfo sourceBlob2 = BlobInfo.builder(bucket, sourceBlobName2).build();
+ BlobInfo sourceBlob1 = BlobInfo.builder(BUCKET, sourceBlobName1).build();
+ BlobInfo sourceBlob2 = BlobInfo.builder(BUCKET, sourceBlobName2).build();
BlobInfo remoteBlob1 = storage.create(sourceBlob1);
assertNotNull(remoteBlob1);
List updatedBlobs = storage.update(
@@ -658,6 +658,6 @@ public void testUpdateBlobsFail() {
assertEquals(sourceBlob1.blobId(), updatedBlobs.get(0).blobId());
assertEquals(CONTENT_TYPE, updatedBlobs.get(0).contentType());
assertNull(updatedBlobs.get(1));
- assertTrue(storage.delete(bucket, sourceBlobName1));
+ assertTrue(storage.delete(BUCKET, sourceBlobName1));
}
}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/OptionTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/OptionTest.java
index 4665d04b2d82..2703ddb401c5 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/OptionTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/OptionTest.java
@@ -31,7 +31,7 @@ public void testOption() {
assertEquals("/", option.value());
}
- @Test(expected=NullPointerException.class)
+ @Test(expected = NullPointerException.class)
public void testIndexOutOfBoundsException() {
new Option(null, "/");
}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java
index 3cd67701e92b..329767e85d4a 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java
@@ -22,6 +22,12 @@
import com.google.common.collect.ImmutableList;
import com.google.gcloud.storage.testing.RemoteGcsHelper;
+import org.easymock.EasyMock;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.file.Files;
@@ -32,12 +38,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-import org.easymock.EasyMock;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
public class RemoteGcsHelperTest {
private static final String BUCKET_NAME = "bucket-name";
@@ -91,7 +91,7 @@ public Iterator iterator() {
return BLOB_LIST.iterator();
}
};
- private static String KEY_PATH = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json";
+ private static String keyPath = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json";
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -99,7 +99,7 @@ public Iterator iterator() {
@BeforeClass
public static void beforeClass() {
while (Files.exists(Paths.get(JSON_KEY))) {
- KEY_PATH = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json";
+ keyPath = "/does/not/exist/key." + UUID.randomUUID().toString() + ".json";
}
}
@@ -163,7 +163,7 @@ public void testCreateFromStream() {
@Test
public void testCreateNoKey() {
thrown.expect(RemoteGcsHelper.GcsHelperException.class);
- thrown.expectMessage(KEY_PATH + " (No such file or directory)");
- RemoteGcsHelper.create(PROJECT_ID, KEY_PATH);
+ thrown.expectMessage(keyPath + " (No such file or directory)");
+ RemoteGcsHelper.create(PROJECT_ID, keyPath);
}
}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java
index 50cbdbf9abd5..4c22170bba80 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/SerializationTest.java
@@ -54,8 +54,8 @@ public class SerializationTest {
Collections.singletonList(BatchResponse.Result.of(true)),
Collections.>emptyList(),
Collections.>emptyList());
- private static final BaseListResult LIST_RESULT =
- new BaseListResult<>(null, "c", Collections.singletonList(BlobInfo.builder("b", "n").build()));
+ private static final BaseListResult LIST_RESULT = new BaseListResult<>(
+ null, "c", Collections.singletonList(BlobInfo.builder("b", "n").build()));
private static final Storage.BlobListOption BLOB_LIST_OPTIONS =
Storage.BlobListOption.maxResults(100);
private static final Storage.BlobSourceOption BLOB_SOURCE_OPTIONS =
From fdb2402b1ea90fc1cfc4631005563c08887fdfd3 Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Mon, 26 Oct 2015 17:45:29 +0100
Subject: [PATCH 024/322] Add support for blob rewrite - Add rewrite method to
StorageRpc and DefaultStorageRpc - Add rewriter method to Storage and
StorageImpl - Add unit and integration tests
---
.../google/gcloud/spi/DefaultStorageRpc.java | 28 +++
.../com/google/gcloud/spi/StorageRpc.java | 5 +
.../google/gcloud/storage/BlobRewriter.java | 203 ++++++++++++++++++
.../com/google/gcloud/storage/Storage.java | 170 +++++++++++++++
.../google/gcloud/storage/StorageImpl.java | 11 +
.../gcloud/storage/BlobRewriterTest.java | 149 +++++++++++++
.../google/gcloud/storage/ITStorageTest.java | 38 ++++
7 files changed, 604 insertions(+)
create mode 100644 gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java
create mode 100644 gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
index 90f2c98ad4b8..f28e3dba8a65 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
@@ -55,6 +55,7 @@
import com.google.api.services.storage.model.ComposeRequest;
import com.google.api.services.storage.model.ComposeRequest.SourceObjects.ObjectPreconditions;
import com.google.api.services.storage.model.Objects;
+import com.google.api.services.storage.model.RewriteResponse;
import com.google.api.services.storage.model.StorageObject;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
@@ -521,4 +522,31 @@ public String open(StorageObject object, Map options)
throw translate(ex);
}
}
+
+ @Override
+ public RewriteResponse rewrite(StorageObject source, Map sourceOptions,
+ StorageObject target, Map targetOptions, String token, Long maxByteRewrittenPerCall)
+ throws StorageException {
+ try {
+ return storage
+ .objects()
+ .rewrite(source.getBucket(), source.getName(), target.getBucket(), target.getName(),
+ target)
+ .setRewriteToken(token)
+ .setMaxBytesRewrittenPerCall(maxByteRewrittenPerCall)
+ .setProjection(DEFAULT_PROJECTION)
+ .setIfSourceMetagenerationMatch(IF_SOURCE_METAGENERATION_MATCH.getLong(sourceOptions))
+ .setIfSourceMetagenerationNotMatch(
+ IF_SOURCE_METAGENERATION_NOT_MATCH.getLong(sourceOptions))
+ .setIfSourceGenerationMatch(IF_SOURCE_GENERATION_MATCH.getLong(sourceOptions))
+ .setIfSourceGenerationNotMatch(IF_SOURCE_GENERATION_NOT_MATCH.getLong(sourceOptions))
+ .setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(targetOptions))
+ .setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(targetOptions))
+ .setIfGenerationMatch(IF_GENERATION_MATCH.getLong(targetOptions))
+ .setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(targetOptions))
+ .execute();
+ } catch (IOException ex) {
+ throw translate(ex);
+ }
+ }
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java
index b7ac99bf909e..a463583a563c 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java
@@ -19,6 +19,7 @@
import static com.google.common.base.MoreObjects.firstNonNull;
import com.google.api.services.storage.model.Bucket;
+import com.google.api.services.storage.model.RewriteResponse;
import com.google.api.services.storage.model.StorageObject;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -174,4 +175,8 @@ byte[] read(StorageObject from, Map options, long position, int bytes
void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest,
long destOffset, int length, boolean last) throws StorageException;
+
+ RewriteResponse rewrite(StorageObject source, Map sourceOptions,
+ StorageObject target, Map targetOptions, String token, Long maxByteRewrittenPerCall)
+ throws StorageException;
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java
new file mode 100644
index 000000000000..e144fe013261
--- /dev/null
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright 2015 Google Inc. All Rights Reserved.
+ *
+ * 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.gcloud.storage;
+
+import static com.google.common.base.MoreObjects.firstNonNull;
+import static com.google.gcloud.RetryHelper.runWithRetries;
+
+import com.google.api.services.storage.model.RewriteResponse;
+import com.google.gcloud.RetryHelper;
+import com.google.gcloud.spi.StorageRpc;
+
+import java.math.BigInteger;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+/**
+ * Google Storage blob rewriter.
+ */
+public final class BlobRewriter {
+
+ private final StorageOptions serviceOptions;
+ private final BlobId source;
+ private final Map sourceOptions;
+ private final Map targetOptions;
+ private final Long maxBytesRewrittenPerCall;
+ private BigInteger blobSize;
+ private BlobInfo target;
+ private Boolean isDone;
+ private String rewriteToken;
+ private BigInteger totalBytesRewritten;
+
+ private final StorageRpc storageRpc;
+
+ private BlobRewriter(Builder builder) {
+ this.serviceOptions = builder.serviceOptions;
+ this.source = builder.source;
+ this.sourceOptions = builder.sourceOptions;
+ this.target = builder.target;
+ this.targetOptions = builder.targetOptions;
+ this.blobSize = builder.blobSize;
+ this.isDone = builder.isDone;
+ this.rewriteToken = builder.rewriteToken;
+ this.totalBytesRewritten = firstNonNull(builder.totalBytesRewritten, BigInteger.ZERO);
+ this.maxBytesRewrittenPerCall = builder.maxBytesRewrittenPerCall;
+ this.storageRpc = serviceOptions.storageRpc();
+ }
+
+ static class Builder {
+
+ private final StorageOptions serviceOptions;
+ private final BlobId source;
+ private final Map sourceOptions;
+ private final BlobInfo target;
+ private final Map targetOptions;
+ private BigInteger blobSize;
+ private Boolean isDone;
+ private String rewriteToken;
+ private BigInteger totalBytesRewritten;
+ private Long maxBytesRewrittenPerCall;
+
+ Builder(StorageOptions serviceOptions, BlobId source, Map sourceOptions,
+ BlobInfo target, Map targetOptions) {
+ this.serviceOptions = serviceOptions;
+ this.source = source;
+ this.sourceOptions = sourceOptions;
+ this.target = target;
+ this.targetOptions = targetOptions;
+ }
+
+ Builder blobSize(BigInteger blobSize) {
+ this.blobSize = blobSize;
+ return this;
+ }
+
+ Builder isDone(Boolean isDone) {
+ this.isDone = isDone;
+ return this;
+ }
+
+ Builder rewriteToken(String rewriteToken) {
+ this.rewriteToken = rewriteToken;
+ return this;
+ }
+
+ Builder totalBytesRewritten(BigInteger totalBytesRewritten) {
+ this.totalBytesRewritten = totalBytesRewritten;
+ return this;
+ }
+
+ Builder maxBytesRewrittenPerCall(Long maxBytesRewrittenPerCall) {
+ this.maxBytesRewrittenPerCall = maxBytesRewrittenPerCall;
+ return this;
+ }
+
+ BlobRewriter build() {
+ return new BlobRewriter(this);
+ }
+ }
+
+ static Builder builder(StorageOptions options, BlobId source,
+ Map sourceOpt,
+ BlobInfo target, Map targetOpt) {
+ return new Builder(options, source, sourceOpt, target, targetOpt);
+ }
+
+ /**
+ * Returns the id of the source blob.
+ */
+ public BlobId source() {
+ return source;
+ }
+
+ /**
+ * Returns the info for the target blob. When {@link #isDone} is {@code true} this method returns
+ * the updated information for the just written blob.
+ */
+ public BlobInfo target() {
+ return target;
+ }
+
+ /**
+ * Size of the blob being copied. Returns {@code null} until the first copy request returns.
+ */
+ public BigInteger blobSize() {
+ return blobSize;
+ }
+
+ /**
+ * Returns {@code true} of blob rewrite finished, {@code false} otherwise.
+ */
+ public Boolean isDone() {
+ return isDone;
+ }
+
+ /**
+ * Returns the token to be used to rewrite the next chunk of the blob.
+ */
+ public String rewriteToken() {
+ return rewriteToken;
+ }
+
+ /**
+ * Returns the number of bytes written.
+ */
+ public BigInteger totalBytesRewritten() {
+ return totalBytesRewritten;
+ }
+
+ /**
+ * Returns the maximum number of bytes to be copied with each {@link #copyChunk()} call. This
+ * parameter is ignored if source and target blob share the same location and storage class as
+ * rewrite is made with one single RPC.
+ */
+ public Long maxBytesRewrittenPerCall() {
+ return maxBytesRewrittenPerCall;
+ }
+
+ /**
+ * Rewrite the next chunk of the blob. An RPC is issued only if rewrite has not finished yet
+ * ({@link #isDone} returns {@code false}).
+ *
+ * @throws StorageException upon failure
+ */
+ public void copyChunk() {
+ if (!isDone) {
+ try {
+ RewriteResponse response = runWithRetries(new Callable() {
+ @Override
+ public RewriteResponse call() {
+ return storageRpc.rewrite(
+ source.toPb(),
+ sourceOptions,
+ target.toPb(),
+ targetOptions,
+ rewriteToken,
+ maxBytesRewrittenPerCall);
+ }
+ }, serviceOptions.retryParams(), StorageImpl.EXCEPTION_HANDLER);
+ rewriteToken = response.getRewriteToken();
+ isDone = response.getDone();
+ blobSize = response.getObjectSize();
+ totalBytesRewritten = response.getTotalBytesRewritten();
+ target = response.getResource() != null ? BlobInfo.fromPb(response.getResource()) : target;
+ } catch (RetryHelper.RetryHelperException e) {
+ throw StorageException.translateAndThrow(e);
+ }
+ }
+ }
+}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
index 7f96ba90fc1f..f5dfee6f2f70 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
@@ -596,6 +596,157 @@ public static Builder builder() {
}
}
+ class RewriteRequest implements Serializable {
+
+ private static final long serialVersionUID = -4498650529476219937L;
+
+ private final BlobId source;
+ private final List sourceOptions;
+ private final BlobInfo target;
+ private final List targetOptions;
+ private final Long maxBytesRewrittenPerCall;
+
+ public static class Builder {
+
+ private final Set sourceOptions = new LinkedHashSet<>();
+ private final Set targetOptions = new LinkedHashSet<>();
+ private BlobId source;
+ private BlobInfo target;
+ private Long maxBytesRewrittenPerCall;
+
+ /**
+ * Sets the blob to rewrite given bucket and blob name.
+ *
+ * @return the builder.
+ */
+ public Builder source(String bucket, String blob) {
+ this.source = BlobId.of(bucket, blob);
+ return this;
+ }
+
+ /**
+ * Sets the blob to rewrite given a {@link BlobId}.
+ *
+ * @return the builder.
+ */
+ public Builder source(BlobId source) {
+ this.source = source;
+ return this;
+ }
+
+ /**
+ * Sets blob's source options.
+ *
+ * @return the builder.
+ */
+ public Builder sourceOptions(BlobSourceOption... options) {
+ Collections.addAll(sourceOptions, options);
+ return this;
+ }
+
+ /**
+ * Sets blob's source options.
+ *
+ * @return the builder.
+ */
+ public Builder sourceOptions(Iterable options) {
+ Iterables.addAll(sourceOptions, options);
+ return this;
+ }
+
+ /**
+ * Sets the rewrite target.
+ *
+ * @return the builder.
+ */
+ public Builder target(BlobInfo target) {
+ this.target = target;
+ return this;
+ }
+
+ /**
+ * Sets blob's target options.
+ *
+ * @return the builder.
+ */
+ public Builder targetOptions(BlobTargetOption... options) {
+ Collections.addAll(targetOptions, options);
+ return this;
+ }
+
+ /**
+ * Sets blob's target options.
+ *
+ * @return the builder.
+ */
+ public Builder targetOptions(Iterable options) {
+ Iterables.addAll(targetOptions, options);
+ return this;
+ }
+
+ /**
+ * Sets the maximum number of bytes to copy for each RPC call. This parameter is ignored if
+ * source and target blob share the same location and storage class as rewrite is made with
+ * one single RPC.
+ *
+ * @return the builder.
+ */
+ public Builder maxBytesRewrittenPerCall(Long maxBytesRewrittenPerCall) {
+ this.maxBytesRewrittenPerCall = maxBytesRewrittenPerCall;
+ return this;
+ }
+
+ /**
+ * Creates a {@code RewriteRequest}.
+ */
+ public RewriteRequest build() {
+ checkNotNull(source);
+ checkNotNull(target);
+ return new RewriteRequest(this);
+ }
+ }
+
+ private RewriteRequest(Builder builder) {
+ source = checkNotNull(builder.source);
+ sourceOptions = ImmutableList.copyOf(builder.sourceOptions);
+ target = checkNotNull(builder.target);
+ targetOptions = ImmutableList.copyOf(builder.targetOptions);
+ maxBytesRewrittenPerCall = builder.maxBytesRewrittenPerCall;
+ }
+
+ public BlobId source() {
+ return source;
+ }
+
+ public List sourceOptions() {
+ return sourceOptions;
+ }
+
+ public BlobInfo target() {
+ return target;
+ }
+
+ public List targetOptions() {
+ return targetOptions;
+ }
+
+ public Long maxBytesRewrittenPerCall() {
+ return maxBytesRewrittenPerCall;
+ }
+
+ public static RewriteRequest of(String sourceBucket, String sourceBlob, BlobInfo target) {
+ return builder().source(sourceBucket, sourceBlob).target(target).build();
+ }
+
+ public static RewriteRequest of(BlobId sourceBlobId, BlobInfo target) {
+ return builder().source(sourceBlobId).target(target).build();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+ }
+
/**
* Create a new bucket.
*
@@ -865,4 +1016,23 @@ public static Builder builder() {
* @throws StorageException upon failure
*/
List delete(BlobId... blobIds);
+
+ /**
+ * Returns a {@link BlobRewriter} object for the provided {@code rewriteRequest}. If source and
+ * destination objects share the same location and storage class the source blob is copied with a
+ * single call of {@link BlobRewriter#copyChunk()}, regardless of the {@link
+ * RewriteRequest#maxBytesRewrittenPerCall} parameter. If source and destination have different
+ * location or storage class multiple RPC calls might be needed depending on blob's size.
+ *
+ * Example usage of blob rewriter:
+ *
{@code BlobRewriter rewriter = service.rewriter(rewriteRequest);}
+ * {@code while(!rewriter.isDone()) {
+ * rewriter.copyChunk();
+ * }}
+ *
+ *
+ * @throws StorageException upon failure
+ * @see Rewrite
+ */
+ BlobRewriter rewriter(RewriteRequest rewriteRequest);
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
index 21cd8b726753..bfa760288d6f 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
@@ -663,6 +663,17 @@ public List delete(BlobId... blobIds) {
return Collections.unmodifiableList(transformResultList(response.deletes(), Boolean.FALSE));
}
+ @Override
+ public BlobRewriter rewriter(final RewriteRequest req) {
+ final Map sourceOpts = optionMap(null, null, req.sourceOptions(), true);
+ final Map targetOpts = optionMap(req.target().generation(),
+ req.target().metageneration(), req.targetOptions());
+ return BlobRewriter.builder(options(), req.source(), sourceOpts, req.target(), targetOpts)
+ .isDone(false)
+ .maxBytesRewrittenPerCall(req.maxBytesRewrittenPerCall())
+ .build();
+ }
+
private static List transformResultList(
List> results, final T errorValue) {
return Lists.transform(results, new Function, T>() {
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java
new file mode 100644
index 000000000000..0f5e009fd95e
--- /dev/null
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2015 Google Inc. All Rights Reserved.
+ *
+ * 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.gcloud.storage;
+
+import com.google.api.services.storage.model.RewriteResponse;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.gcloud.RetryParams;
+import com.google.gcloud.spi.StorageRpc;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.junit.Before;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.util.Map;
+import org.junit.After;
+
+public class BlobRewriterTest {
+
+ private static final String SOURCE_BUCKET_NAME = "b";
+ private static final String SOURCE_BLOB_NAME = "n";
+ private static final String DESTINATION_BUCKET_NAME = "b1";
+ private static final String DESTINATION_BLOB_NAME = "n1";
+ private static final BlobId BLOB_ID = BlobId.of(SOURCE_BUCKET_NAME, SOURCE_BLOB_NAME);
+ private static final BlobInfo BLOB_INFO =
+ BlobInfo.builder(DESTINATION_BUCKET_NAME, DESTINATION_BLOB_NAME).build();
+ private static final Map EMPTY_OPTIONS = ImmutableMap.of();
+
+ private StorageOptions optionsMock;
+ private StorageRpc storageRpcMock;
+ private BlobRewriter rewriter;
+
+ @Before
+ public void setUp() throws IOException, InterruptedException {
+ optionsMock = EasyMock.createMock(StorageOptions.class);
+ storageRpcMock = EasyMock.createMock(StorageRpc.class);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ verify(optionsMock, storageRpcMock);
+ }
+
+ @Test
+ public void testRewrite() {
+ RewriteResponse response = new RewriteResponse()
+ .setDone(true)
+ .setResource(BLOB_INFO.toPb())
+ .setObjectSize(BigInteger.valueOf(42L))
+ .setTotalBytesRewritten(BigInteger.valueOf(42L));
+ EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
+ EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries());
+ EasyMock.expect(storageRpcMock.rewrite(
+ BLOB_ID.toPb(), EMPTY_OPTIONS, BLOB_INFO.toPb(), EMPTY_OPTIONS, null, null))
+ .andReturn(response);
+ EasyMock.replay(optionsMock, storageRpcMock);
+ rewriter = BlobRewriter.builder(optionsMock, BLOB_ID, EMPTY_OPTIONS, BLOB_INFO, EMPTY_OPTIONS)
+ .isDone(false)
+ .build();
+ rewriter.copyChunk();
+ assertTrue(rewriter.isDone());
+ assertEquals(BLOB_INFO, rewriter.target());
+ assertEquals(BLOB_ID, rewriter.source());
+ assertEquals(BigInteger.valueOf(42L), rewriter.totalBytesRewritten());
+ assertEquals(BigInteger.valueOf(42L), rewriter.blobSize());
+ }
+
+ @Test
+ public void testRewriteCustumSize() {
+ RewriteResponse response = new RewriteResponse()
+ .setDone(true)
+ .setResource(BLOB_INFO.toPb())
+ .setObjectSize(BigInteger.valueOf(42L))
+ .setTotalBytesRewritten(BigInteger.valueOf(42L));
+ EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
+ EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries());
+ EasyMock.expect(storageRpcMock.rewrite(
+ BLOB_ID.toPb(), EMPTY_OPTIONS, BLOB_INFO.toPb(), EMPTY_OPTIONS, null, 1048576L))
+ .andReturn(response);
+ EasyMock.replay(optionsMock, storageRpcMock);
+ rewriter = BlobRewriter.builder(optionsMock, BLOB_ID, EMPTY_OPTIONS, BLOB_INFO, EMPTY_OPTIONS)
+ .isDone(false)
+ .maxBytesRewrittenPerCall(1048576L)
+ .build();
+ rewriter.copyChunk();
+ assertTrue(rewriter.isDone());
+ assertEquals(BLOB_INFO, rewriter.target());
+ assertEquals(BLOB_ID, rewriter.source());
+ assertEquals(BigInteger.valueOf(42L), rewriter.totalBytesRewritten());
+ assertEquals(BigInteger.valueOf(42L), rewriter.blobSize());
+ }
+
+ @Test
+ public void testRewriteMultipleRequests() {
+ RewriteResponse firstResponse = new RewriteResponse()
+ .setDone(false)
+ .setResource(BLOB_INFO.toPb())
+ .setObjectSize(BigInteger.valueOf(42L))
+ .setRewriteToken("token")
+ .setTotalBytesRewritten(BigInteger.valueOf(21L));
+ RewriteResponse secondResponse = new RewriteResponse()
+ .setDone(true)
+ .setResource(BLOB_INFO.toPb())
+ .setObjectSize(BigInteger.valueOf(42L))
+ .setTotalBytesRewritten(BigInteger.valueOf(42L));
+ EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
+ EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()).times(2);
+ EasyMock.expect(storageRpcMock.rewrite(
+ BLOB_ID.toPb(), EMPTY_OPTIONS, BLOB_INFO.toPb(), EMPTY_OPTIONS, null, null))
+ .andReturn(firstResponse);
+ EasyMock.expect(storageRpcMock.rewrite(
+ BLOB_ID.toPb(), EMPTY_OPTIONS, BLOB_INFO.toPb(), EMPTY_OPTIONS, "token", null))
+ .andReturn(secondResponse);
+ EasyMock.replay(optionsMock, storageRpcMock);
+ rewriter = BlobRewriter.builder(optionsMock, BLOB_ID, EMPTY_OPTIONS, BLOB_INFO, EMPTY_OPTIONS)
+ .isDone(false)
+ .build();
+ int loopCount = 0;
+ while (!rewriter.isDone()) {
+ rewriter.copyChunk();
+ loopCount++;
+ }
+ assertTrue(rewriter.isDone());
+ assertEquals(BLOB_INFO, rewriter.target());
+ assertEquals(BLOB_ID, rewriter.source());
+ assertEquals(BigInteger.valueOf(42L), rewriter.totalBytesRewritten());
+ assertEquals(BigInteger.valueOf(42L), rewriter.blobSize());
+ assertEquals(2, loopCount);
+ }
+}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
index 7b29086ecbe5..b7e7d4b415d0 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
@@ -660,4 +660,42 @@ public void testUpdateBlobsFail() {
assertNull(updatedBlobs.get(1));
assertTrue(storage.delete(BUCKET, sourceBlobName1));
}
+
+ @Test
+ public void testRewriteBlob() {
+ String sourceBlobName = "test-rewrite-blob-source";
+ BlobId source = BlobId.of(bucket, sourceBlobName);
+ assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
+ String targetBlobName = "test-rewrite-blob-target";
+ BlobInfo target = BlobInfo.builder(bucket, targetBlobName).contentType(CONTENT_TYPE).build();
+ Storage.RewriteRequest req = Storage.RewriteRequest.of(source, target);
+ BlobRewriter rewriter = storage.rewriter(req);
+ rewriter.copyChunk();
+ assertTrue(rewriter.isDone());
+ assertEquals(rewriter.target(), storage.get(bucket, targetBlobName));
+ assertTrue(storage.delete(bucket, sourceBlobName));
+ assertTrue(storage.delete(bucket, targetBlobName));
+ }
+
+ @Test
+ public void testRewriteBlobFail() {
+ String sourceBlobName = "test-rewrite-blob-source-fail";
+ BlobId source = BlobId.of(bucket, sourceBlobName);
+ assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
+ String targetBlobName = "test-rewrite-blob-target-fail";
+ BlobInfo target = BlobInfo.builder(bucket, targetBlobName).contentType(CONTENT_TYPE).build();
+ Storage.RewriteRequest req = Storage.RewriteRequest.builder()
+ .source(source)
+ .sourceOptions(Storage.BlobSourceOption.generationMatch(-1L))
+ .target(target)
+ .build();
+ BlobRewriter rewriter = storage.rewriter(req);
+ try {
+ rewriter.copyChunk();
+ fail("StorageException was expected");
+ } catch (StorageException ex) {
+ // expected
+ }
+ assertTrue(storage.delete(bucket, sourceBlobName));
+ }
}
From 15372f1920ef32ba0f161ff293f35e0e37664637 Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Tue, 27 Oct 2015 16:41:49 +0100
Subject: [PATCH 025/322] Refactor StorageRpc and Storage rewrite - Split
StorageRpc.rewrite into openRewrite and continueRewrite - Add
StorageRpc.RewriteResponse and RewriteRequest classe - Move first rewrite
request from BlobRewriter to StorageImpl - Change maxBytesRewrittenPerCall to
megabytesRewrittenPerCall - Change BlobWriter.blobSize for BigInteger to Long
- BlobRewriter extends Restorable - Refactor tests and add StorageImpl unit
tests
---
.../google/gcloud/spi/DefaultStorageRpc.java | 49 ++-
.../com/google/gcloud/spi/StorageRpc.java | 91 ++++-
.../google/gcloud/storage/BlobRewriter.java | 318 ++++++++++--------
.../com/google/gcloud/storage/Storage.java | 37 +-
.../google/gcloud/storage/StorageImpl.java | 28 +-
.../gcloud/storage/BlobRewriterTest.java | 140 ++++----
.../google/gcloud/storage/ITStorageTest.java | 19 +-
.../gcloud/storage/StorageImplTest.java | 65 ++++
8 files changed, 489 insertions(+), 258 deletions(-)
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
index f28e3dba8a65..1098ca4c538d 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
@@ -55,7 +55,6 @@
import com.google.api.services.storage.model.ComposeRequest;
import com.google.api.services.storage.model.ComposeRequest.SourceObjects.ObjectPreconditions;
import com.google.api.services.storage.model.Objects;
-import com.google.api.services.storage.model.RewriteResponse;
import com.google.api.services.storage.model.StorageObject;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
@@ -79,6 +78,7 @@ public class DefaultStorageRpc implements StorageRpc {
// see: https://cloud.google.com/storage/docs/concepts-techniques#practices
private static final Set RETRYABLE_CODES = ImmutableSet.of(504, 503, 502, 500, 429, 408);
+ private static final long MEGABYTE = 1024L * 1024L;
public DefaultStorageRpc(StorageOptions options) {
HttpTransport transport = options.httpTransportFactory().create();
@@ -524,27 +524,42 @@ public String open(StorageObject object, Map options)
}
@Override
- public RewriteResponse rewrite(StorageObject source, Map sourceOptions,
- StorageObject target, Map targetOptions, String token, Long maxByteRewrittenPerCall)
- throws StorageException {
+ public RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws StorageException {
+ return rewrite(rewriteRequest, null);
+ }
+
+ @Override
+ public RewriteResponse continueRewrite(RewriteResponse previousResponse) throws StorageException {
+ return rewrite(previousResponse.rewriteRequest, previousResponse.rewriteToken);
+ }
+
+ private RewriteResponse rewrite(RewriteRequest req, String token) throws StorageException {
try {
- return storage
- .objects()
- .rewrite(source.getBucket(), source.getName(), target.getBucket(), target.getName(),
- target)
+ Long maxBytesRewrittenPerCall = req.megabytesRewrittenPerCall != null
+ ? req.megabytesRewrittenPerCall * MEGABYTE : null;
+ com.google.api.services.storage.model.RewriteResponse rewriteReponse = storage.objects()
+ .rewrite(req.source.getBucket(), req.source.getName(), req.target.getBucket(),
+ req.target.getName(), req.target)
.setRewriteToken(token)
- .setMaxBytesRewrittenPerCall(maxByteRewrittenPerCall)
+ .setMaxBytesRewrittenPerCall(maxBytesRewrittenPerCall)
.setProjection(DEFAULT_PROJECTION)
- .setIfSourceMetagenerationMatch(IF_SOURCE_METAGENERATION_MATCH.getLong(sourceOptions))
+ .setIfSourceMetagenerationMatch(IF_SOURCE_METAGENERATION_MATCH.getLong(req.sourceOptions))
.setIfSourceMetagenerationNotMatch(
- IF_SOURCE_METAGENERATION_NOT_MATCH.getLong(sourceOptions))
- .setIfSourceGenerationMatch(IF_SOURCE_GENERATION_MATCH.getLong(sourceOptions))
- .setIfSourceGenerationNotMatch(IF_SOURCE_GENERATION_NOT_MATCH.getLong(sourceOptions))
- .setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(targetOptions))
- .setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(targetOptions))
- .setIfGenerationMatch(IF_GENERATION_MATCH.getLong(targetOptions))
- .setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(targetOptions))
+ IF_SOURCE_METAGENERATION_NOT_MATCH.getLong(req.sourceOptions))
+ .setIfSourceGenerationMatch(IF_SOURCE_GENERATION_MATCH.getLong(req.sourceOptions))
+ .setIfSourceGenerationNotMatch(IF_SOURCE_GENERATION_NOT_MATCH.getLong(req.sourceOptions))
+ .setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(req.targetOptions))
+ .setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(req.targetOptions))
+ .setIfGenerationMatch(IF_GENERATION_MATCH.getLong(req.targetOptions))
+ .setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(req.targetOptions))
.execute();
+ return new RewriteResponse(
+ req,
+ rewriteReponse.getResource(),
+ rewriteReponse.getObjectSize().longValue(),
+ rewriteReponse.getDone(),
+ rewriteReponse.getRewriteToken(),
+ rewriteReponse.getTotalBytesRewritten().longValue());
} catch (IOException ex) {
throw translate(ex);
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java
index a463583a563c..1a4afa0524e0 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java
@@ -19,7 +19,6 @@
import static com.google.common.base.MoreObjects.firstNonNull;
import com.google.api.services.storage.model.Bucket;
-import com.google.api.services.storage.model.RewriteResponse;
import com.google.api.services.storage.model.StorageObject;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -28,6 +27,7 @@
import java.io.InputStream;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
public interface StorageRpc {
@@ -133,6 +133,89 @@ public BatchResponse(Map> delete
}
}
+ class RewriteRequest {
+
+ public final StorageObject source;
+ public final Map sourceOptions;
+ public final StorageObject target;
+ public final Map targetOptions;
+ public final Long megabytesRewrittenPerCall;
+
+ public RewriteRequest(StorageObject source, Map sourceOptions,
+ StorageObject target, Map targetOptions,
+ Long megabytesRewrittenPerCall) {
+ this.source = source;
+ this.sourceOptions = sourceOptions;
+ this.target = target;
+ this.targetOptions = targetOptions;
+ this.megabytesRewrittenPerCall = megabytesRewrittenPerCall;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof RewriteRequest)) {
+ return false;
+ }
+ final RewriteRequest other = (RewriteRequest) obj;
+ return Objects.equals(this.source, other.source)
+ && Objects.equals(this.sourceOptions, other.sourceOptions)
+ && Objects.equals(this.target, other.target)
+ && Objects.equals(this.targetOptions, other.targetOptions)
+ && Objects.equals(this.megabytesRewrittenPerCall, other.megabytesRewrittenPerCall);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(source, sourceOptions, target, targetOptions, megabytesRewrittenPerCall);
+ }
+ }
+
+ class RewriteResponse {
+
+ public final RewriteRequest rewriteRequest;
+ public final StorageObject result;
+ public final Long blobSize;
+ public final Boolean isDone;
+ public final String rewriteToken;
+ public final Long totalBytesRewritten;
+
+ public RewriteResponse(RewriteRequest rewriteRequest, StorageObject result, Long blobSize,
+ Boolean isDone, String rewriteToken, Long totalBytesRewritten) {
+ this.rewriteRequest = rewriteRequest;
+ this.result = result;
+ this.blobSize = blobSize;
+ this.isDone = isDone;
+ this.rewriteToken = rewriteToken;
+ this.totalBytesRewritten = totalBytesRewritten;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof RewriteResponse)) {
+ return false;
+ }
+ final RewriteResponse other = (RewriteResponse) obj;
+ return Objects.equals(this.rewriteRequest, other.rewriteRequest)
+ && Objects.equals(this.result, other.result)
+ && Objects.equals(this.rewriteToken, other.rewriteToken)
+ && Objects.equals(this.blobSize, other.blobSize)
+ && Objects.equals(this.isDone, other.isDone)
+ && Objects.equals(this.totalBytesRewritten, other.totalBytesRewritten);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(rewriteRequest, result, blobSize, isDone, rewriteToken,
+ totalBytesRewritten);
+ }
+ }
+
Bucket create(Bucket bucket, Map options) throws StorageException;
StorageObject create(StorageObject object, InputStream content, Map options)
@@ -176,7 +259,7 @@ byte[] read(StorageObject from, Map options, long position, int bytes
void write(String uploadId, byte[] toWrite, int toWriteOffset, StorageObject dest,
long destOffset, int length, boolean last) throws StorageException;
- RewriteResponse rewrite(StorageObject source, Map sourceOptions,
- StorageObject target, Map targetOptions, String token, Long maxByteRewrittenPerCall)
- throws StorageException;
+ RewriteResponse openRewrite(RewriteRequest rewriteRequest) throws StorageException;
+
+ RewriteResponse continueRewrite(RewriteResponse previousResponse) throws StorageException;
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java
index e144fe013261..75b0516f0acf 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java
@@ -16,157 +16,63 @@
package com.google.gcloud.storage;
-import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.gcloud.RetryHelper.runWithRetries;
-import com.google.api.services.storage.model.RewriteResponse;
+import com.google.common.base.MoreObjects;
+import com.google.gcloud.Restorable;
+import com.google.gcloud.RestorableState;
import com.google.gcloud.RetryHelper;
import com.google.gcloud.spi.StorageRpc;
+import com.google.gcloud.spi.StorageRpc.RewriteRequest;
+import com.google.gcloud.spi.StorageRpc.RewriteResponse;
-import java.math.BigInteger;
+import java.io.Serializable;
import java.util.Map;
+import java.util.Objects;
import java.util.concurrent.Callable;
/**
* Google Storage blob rewriter.
*/
-public final class BlobRewriter {
+public final class BlobRewriter implements Restorable {
private final StorageOptions serviceOptions;
- private final BlobId source;
- private final Map sourceOptions;
- private final Map targetOptions;
- private final Long maxBytesRewrittenPerCall;
- private BigInteger blobSize;
- private BlobInfo target;
- private Boolean isDone;
- private String rewriteToken;
- private BigInteger totalBytesRewritten;
-
private final StorageRpc storageRpc;
+ private RewriteResponse rewriteResponse;
- private BlobRewriter(Builder builder) {
- this.serviceOptions = builder.serviceOptions;
- this.source = builder.source;
- this.sourceOptions = builder.sourceOptions;
- this.target = builder.target;
- this.targetOptions = builder.targetOptions;
- this.blobSize = builder.blobSize;
- this.isDone = builder.isDone;
- this.rewriteToken = builder.rewriteToken;
- this.totalBytesRewritten = firstNonNull(builder.totalBytesRewritten, BigInteger.ZERO);
- this.maxBytesRewrittenPerCall = builder.maxBytesRewrittenPerCall;
- this.storageRpc = serviceOptions.storageRpc();
- }
-
- static class Builder {
-
- private final StorageOptions serviceOptions;
- private final BlobId source;
- private final Map sourceOptions;
- private final BlobInfo target;
- private final Map targetOptions;
- private BigInteger blobSize;
- private Boolean isDone;
- private String rewriteToken;
- private BigInteger totalBytesRewritten;
- private Long maxBytesRewrittenPerCall;
-
- Builder(StorageOptions serviceOptions, BlobId source, Map sourceOptions,
- BlobInfo target, Map targetOptions) {
- this.serviceOptions = serviceOptions;
- this.source = source;
- this.sourceOptions = sourceOptions;
- this.target = target;
- this.targetOptions = targetOptions;
- }
-
- Builder blobSize(BigInteger blobSize) {
- this.blobSize = blobSize;
- return this;
- }
-
- Builder isDone(Boolean isDone) {
- this.isDone = isDone;
- return this;
- }
-
- Builder rewriteToken(String rewriteToken) {
- this.rewriteToken = rewriteToken;
- return this;
- }
-
- Builder totalBytesRewritten(BigInteger totalBytesRewritten) {
- this.totalBytesRewritten = totalBytesRewritten;
- return this;
- }
-
- Builder maxBytesRewrittenPerCall(Long maxBytesRewrittenPerCall) {
- this.maxBytesRewrittenPerCall = maxBytesRewrittenPerCall;
- return this;
- }
-
- BlobRewriter build() {
- return new BlobRewriter(this);
- }
- }
-
- static Builder builder(StorageOptions options, BlobId source,
- Map sourceOpt,
- BlobInfo target, Map targetOpt) {
- return new Builder(options, source, sourceOpt, target, targetOpt);
- }
-
- /**
- * Returns the id of the source blob.
- */
- public BlobId source() {
- return source;
+ BlobRewriter(StorageOptions serviceOptions, RewriteResponse rewriteResponse) {
+ this.serviceOptions = serviceOptions;
+ this.rewriteResponse = rewriteResponse;
+ this.storageRpc = serviceOptions.rpc();
}
/**
- * Returns the info for the target blob. When {@link #isDone} is {@code true} this method returns
- * the updated information for the just written blob.
+ * Returns the updated information for the just written blob when {@link #isDone} is {@code true}.
+ * Returns {@code null} otherwise.
*/
- public BlobInfo target() {
- return target;
+ public BlobInfo result() {
+ return rewriteResponse.result != null ? BlobInfo.fromPb(rewriteResponse.result) : null;
}
/**
- * Size of the blob being copied. Returns {@code null} until the first copy request returns.
+ * Size of the blob being copied.
*/
- public BigInteger blobSize() {
- return blobSize;
+ public Long blobSize() {
+ return rewriteResponse.blobSize;
}
/**
* Returns {@code true} of blob rewrite finished, {@code false} otherwise.
*/
public Boolean isDone() {
- return isDone;
- }
-
- /**
- * Returns the token to be used to rewrite the next chunk of the blob.
- */
- public String rewriteToken() {
- return rewriteToken;
+ return rewriteResponse.isDone;
}
/**
* Returns the number of bytes written.
*/
- public BigInteger totalBytesRewritten() {
- return totalBytesRewritten;
- }
-
- /**
- * Returns the maximum number of bytes to be copied with each {@link #copyChunk()} call. This
- * parameter is ignored if source and target blob share the same location and storage class as
- * rewrite is made with one single RPC.
- */
- public Long maxBytesRewrittenPerCall() {
- return maxBytesRewrittenPerCall;
+ public Long totalBytesRewritten() {
+ return rewriteResponse.totalBytesRewritten;
}
/**
@@ -176,28 +82,178 @@ public Long maxBytesRewrittenPerCall() {
* @throws StorageException upon failure
*/
public void copyChunk() {
- if (!isDone) {
+ if (!isDone()) {
try {
- RewriteResponse response = runWithRetries(new Callable() {
+ this.rewriteResponse = runWithRetries(new Callable() {
@Override
public RewriteResponse call() {
- return storageRpc.rewrite(
- source.toPb(),
- sourceOptions,
- target.toPb(),
- targetOptions,
- rewriteToken,
- maxBytesRewrittenPerCall);
+ return storageRpc.continueRewrite(rewriteResponse);
}
}, serviceOptions.retryParams(), StorageImpl.EXCEPTION_HANDLER);
- rewriteToken = response.getRewriteToken();
- isDone = response.getDone();
- blobSize = response.getObjectSize();
- totalBytesRewritten = response.getTotalBytesRewritten();
- target = response.getResource() != null ? BlobInfo.fromPb(response.getResource()) : target;
} catch (RetryHelper.RetryHelperException e) {
throw StorageException.translateAndThrow(e);
}
}
}
+
+ @Override
+ public RestorableState capture() {
+ return StateImpl.builder(
+ serviceOptions,
+ BlobId.fromPb(rewriteResponse.rewriteRequest.source),
+ rewriteResponse.rewriteRequest.sourceOptions,
+ BlobInfo.fromPb(rewriteResponse.rewriteRequest.target),
+ rewriteResponse.rewriteRequest.targetOptions)
+ .blobSize(blobSize())
+ .isDone(isDone())
+ .megabytesRewrittenPerCall(rewriteResponse.rewriteRequest.megabytesRewrittenPerCall)
+ .rewriteToken(rewriteResponse.rewriteToken)
+ .totalBytesRewritten(totalBytesRewritten())
+ .build();
+ }
+
+ static class StateImpl implements RestorableState, Serializable {
+
+ private static final long serialVersionUID = 8279287678903181701L;
+
+ private final StorageOptions serviceOptions;
+ private final BlobId source;
+ private final Map sourceOptions;
+ private final BlobInfo target;
+ private final Map targetOptions;
+ private final BlobInfo result;
+ private final Long blobSize;
+ private final Boolean isDone;
+ private final String rewriteToken;
+ private final Long totalBytesRewritten;
+ private final Long megabytesRewrittenPerCall;
+
+ StateImpl(Builder builder) {
+ this.serviceOptions = builder.serviceOptions;
+ this.source = builder.source;
+ this.sourceOptions = builder.sourceOptions;
+ this.target = builder.target;
+ this.targetOptions = builder.targetOptions;
+ this.result = builder.result;
+ this.blobSize = builder.blobSize;
+ this.isDone = builder.isDone;
+ this.rewriteToken = builder.rewriteToken;
+ this.totalBytesRewritten = builder.totalBytesRewritten;
+ this.megabytesRewrittenPerCall = builder.megabytesRewrittenPerCall;
+ }
+
+ static class Builder {
+
+ private final StorageOptions serviceOptions;
+ private final BlobId source;
+ private final Map sourceOptions;
+ private final BlobInfo target;
+ private final Map targetOptions;
+ private BlobInfo result;
+ private Long blobSize;
+ private Boolean isDone;
+ private String rewriteToken;
+ private Long totalBytesRewritten;
+ private Long megabytesRewrittenPerCall;
+
+ private Builder(StorageOptions options, BlobId source,
+ Map sourceOptions,
+ BlobInfo target, Map targetOptions) {
+ this.serviceOptions = options;
+ this.source = source;
+ this.sourceOptions = sourceOptions;
+ this.target = target;
+ this.targetOptions = targetOptions;
+ }
+
+ Builder result(BlobInfo result) {
+ this.result = result;
+ return this;
+ }
+
+ Builder blobSize(Long blobSize) {
+ this.blobSize = blobSize;
+ return this;
+ }
+
+ Builder isDone(Boolean isDone) {
+ this.isDone = isDone;
+ return this;
+ }
+
+ Builder rewriteToken(String rewriteToken) {
+ this.rewriteToken = rewriteToken;
+ return this;
+ }
+
+ Builder totalBytesRewritten(Long totalBytesRewritten) {
+ this.totalBytesRewritten = totalBytesRewritten;
+ return this;
+ }
+
+ Builder megabytesRewrittenPerCall(Long megabytesRewrittenPerCall) {
+ this.megabytesRewrittenPerCall = megabytesRewrittenPerCall;
+ return this;
+ }
+
+ RestorableState build() {
+ return new StateImpl(this);
+ }
+ }
+
+ static Builder builder(StorageOptions options, BlobId source,
+ Map sourceOptions, BlobInfo target,
+ Map targetOptions) {
+ return new Builder(options, source, sourceOptions, target, targetOptions);
+ }
+
+ @Override
+ public BlobRewriter restore() {
+ RewriteRequest rewriteRequest = new RewriteRequest(
+ source.toPb(), sourceOptions, target.toPb(), targetOptions, megabytesRewrittenPerCall);
+ RewriteResponse rewriteResponse = new RewriteResponse(rewriteRequest,
+ result != null ? result.toPb() : null, blobSize, isDone, rewriteToken,
+ totalBytesRewritten);
+ return new BlobRewriter(serviceOptions, rewriteResponse);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(serviceOptions, source, sourceOptions, target, targetOptions, result,
+ blobSize, isDone, megabytesRewrittenPerCall, rewriteToken, totalBytesRewritten);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof StateImpl)) {
+ return false;
+ }
+ final StateImpl other = (StateImpl) obj;
+ return Objects.equals(this.serviceOptions, other.serviceOptions)
+ && Objects.equals(this.source, other.source)
+ && Objects.equals(this.sourceOptions, other.sourceOptions)
+ && Objects.equals(this.target, other.target)
+ && Objects.equals(this.targetOptions, other.targetOptions)
+ && Objects.equals(this.result, other.result)
+ && Objects.equals(this.rewriteToken, other.rewriteToken)
+ && Objects.equals(this.blobSize, other.blobSize)
+ && Objects.equals(this.isDone, other.isDone)
+ && Objects.equals(this.megabytesRewrittenPerCall, other.megabytesRewrittenPerCall)
+ && Objects.equals(this.totalBytesRewritten, other.totalBytesRewritten);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("source", source)
+ .add("target", target)
+ .add("isDone", isDone)
+ .add("totalBytesRewritten", totalBytesRewritten)
+ .add("blobSize", blobSize)
+ .toString();
+ }
+ }
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
index f5dfee6f2f70..88f2a80f8b9b 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
@@ -604,7 +604,7 @@ class RewriteRequest implements Serializable {
private final List sourceOptions;
private final BlobInfo target;
private final List targetOptions;
- private final Long maxBytesRewrittenPerCall;
+ private final Long megabytesRewrittenPerCall;
public static class Builder {
@@ -612,7 +612,7 @@ public static class Builder {
private final Set targetOptions = new LinkedHashSet<>();
private BlobId source;
private BlobInfo target;
- private Long maxBytesRewrittenPerCall;
+ private Long megabytesRewrittenPerCall;
/**
* Sets the blob to rewrite given bucket and blob name.
@@ -685,14 +685,14 @@ public Builder targetOptions(Iterable options) {
}
/**
- * Sets the maximum number of bytes to copy for each RPC call. This parameter is ignored if
- * source and target blob share the same location and storage class as rewrite is made with
+ * Sets the maximum number of megabytes to copy for each RPC call. This parameter is ignored
+ * if source and target blob share the same location and storage class as rewrite is made with
* one single RPC.
*
* @return the builder.
*/
- public Builder maxBytesRewrittenPerCall(Long maxBytesRewrittenPerCall) {
- this.maxBytesRewrittenPerCall = maxBytesRewrittenPerCall;
+ public Builder megabytesRewrittenPerCall(Long megabytesRewrittenPerCall) {
+ this.megabytesRewrittenPerCall = megabytesRewrittenPerCall;
return this;
}
@@ -711,27 +711,44 @@ private RewriteRequest(Builder builder) {
sourceOptions = ImmutableList.copyOf(builder.sourceOptions);
target = checkNotNull(builder.target);
targetOptions = ImmutableList.copyOf(builder.targetOptions);
- maxBytesRewrittenPerCall = builder.maxBytesRewrittenPerCall;
+ megabytesRewrittenPerCall = builder.megabytesRewrittenPerCall;
}
+ /**
+ * Returns the blob to rewrite, as a {@link BlobId}.
+ */
public BlobId source() {
return source;
}
+ /**
+ * Returns blob's source options.
+ */
public List sourceOptions() {
return sourceOptions;
}
+ /**
+ * Returns the rewrite target.
+ */
public BlobInfo target() {
return target;
}
+ /**
+ * Returns blob's target options.
+ */
public List targetOptions() {
return targetOptions;
}
- public Long maxBytesRewrittenPerCall() {
- return maxBytesRewrittenPerCall;
+ /**
+ * Returns the maximum number of megabytes to copy for each RPC call. This parameter is ignored
+ * if source and target blob share the same location and storage class as rewrite is made with
+ * one single RPC.
+ */
+ public Long megabytesRewrittenPerCall() {
+ return megabytesRewrittenPerCall;
}
public static RewriteRequest of(String sourceBucket, String sourceBlob, BlobInfo target) {
@@ -1018,7 +1035,7 @@ public static Builder builder() {
List delete(BlobId... blobIds);
/**
- * Returns a {@link BlobRewriter} object for the provided {@code rewriteRequest}. If source and
+ * Returns a {@link BlobRewriter} object for the provided {@code RewriteRequest}. If source and
* destination objects share the same location and storage class the source blob is copied with a
* single call of {@link BlobRewriter#copyChunk()}, regardless of the {@link
* RewriteRequest#maxBytesRewrittenPerCall} parameter. If source and destination have different
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
index bfa760288d6f..7bc39481b8a0 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
@@ -49,6 +49,7 @@
import com.google.gcloud.ExceptionHandler.Interceptor;
import com.google.gcloud.RetryHelper.RetryHelperException;
import com.google.gcloud.spi.StorageRpc;
+import com.google.gcloud.spi.StorageRpc.RewriteResponse;
import com.google.gcloud.spi.StorageRpc.Tuple;
import java.io.ByteArrayInputStream;
@@ -664,14 +665,25 @@ public List delete(BlobId... blobIds) {
}
@Override
- public BlobRewriter rewriter(final RewriteRequest req) {
- final Map sourceOpts = optionMap(null, null, req.sourceOptions(), true);
- final Map targetOpts = optionMap(req.target().generation(),
- req.target().metageneration(), req.targetOptions());
- return BlobRewriter.builder(options(), req.source(), sourceOpts, req.target(), targetOpts)
- .isDone(false)
- .maxBytesRewrittenPerCall(req.maxBytesRewrittenPerCall())
- .build();
+ public BlobRewriter rewriter(final RewriteRequest rewriteRequest) {
+ final StorageObject source = rewriteRequest.source().toPb();
+ final Map sourceOptions =
+ optionMap(null, null, rewriteRequest.sourceOptions(), true);
+ final StorageObject target = rewriteRequest.target().toPb();
+ final Map targetOptions = optionMap(rewriteRequest.target().generation(),
+ rewriteRequest.target().metageneration(), rewriteRequest.targetOptions());
+ try {
+ RewriteResponse rewriteResponse = runWithRetries(new Callable() {
+ @Override
+ public RewriteResponse call() {
+ return storageRpc.openRewrite(new StorageRpc.RewriteRequest(source, sourceOptions, target,
+ targetOptions, rewriteRequest.megabytesRewrittenPerCall()));
+ }
+ }, options().retryParams(), EXCEPTION_HANDLER);
+ return new BlobRewriter(options(), rewriteResponse);
+ } catch (RetryHelperException e) {
+ throw StorageException.translateAndThrow(e);
+ }
}
private static List transformResultList(
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java
index 0f5e009fd95e..83cda633fd6a 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java
@@ -16,23 +16,28 @@
package com.google.gcloud.storage;
-import com.google.api.services.storage.model.RewriteResponse;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import com.google.common.collect.ImmutableMap;
-import com.google.gcloud.RetryParams;
+import com.google.gcloud.RestorableState;
import com.google.gcloud.spi.StorageRpc;
+import com.google.gcloud.spi.StorageRpc.RewriteRequest;
+import com.google.gcloud.spi.StorageRpc.RewriteResponse;
+import com.google.gcloud.spi.StorageRpcFactory;
import org.easymock.EasyMock;
+import org.junit.After;
import org.junit.Test;
import org.junit.Before;
import java.io.IOException;
-import java.math.BigInteger;
import java.util.Map;
-import org.junit.After;
public class BlobRewriterTest {
@@ -43,107 +48,86 @@ public class BlobRewriterTest {
private static final BlobId BLOB_ID = BlobId.of(SOURCE_BUCKET_NAME, SOURCE_BLOB_NAME);
private static final BlobInfo BLOB_INFO =
BlobInfo.builder(DESTINATION_BUCKET_NAME, DESTINATION_BLOB_NAME).build();
+ private static final BlobInfo RESULT =
+ BlobInfo.builder(DESTINATION_BUCKET_NAME, DESTINATION_BLOB_NAME).contentType("type").build();
private static final Map EMPTY_OPTIONS = ImmutableMap.of();
+ private static final RewriteRequest REQUEST = new StorageRpc.RewriteRequest(BLOB_ID.toPb(),
+ EMPTY_OPTIONS, BLOB_INFO.toPb(), EMPTY_OPTIONS, null);
+ private static final RewriteResponse RESPONSE = new StorageRpc.RewriteResponse(REQUEST,
+ null, 42L, false, "token", 21L);
+ private static final RewriteResponse RESPONSE_DONE = new StorageRpc.RewriteResponse(REQUEST,
+ RESULT.toPb(), 42L, true, "token", 42L);
- private StorageOptions optionsMock;
+ private StorageOptions options;
+ private StorageRpcFactory rpcFactoryMock;
private StorageRpc storageRpcMock;
private BlobRewriter rewriter;
@Before
public void setUp() throws IOException, InterruptedException {
- optionsMock = EasyMock.createMock(StorageOptions.class);
- storageRpcMock = EasyMock.createMock(StorageRpc.class);
+ rpcFactoryMock = createMock(StorageRpcFactory.class);
+ storageRpcMock = createMock(StorageRpc.class);
+ expect(rpcFactoryMock.create(anyObject(StorageOptions.class)))
+ .andReturn(storageRpcMock);
+ replay(rpcFactoryMock);
+ options = StorageOptions.builder()
+ .projectId("projectid")
+ .serviceRpcFactory(rpcFactoryMock)
+ .build();
}
@After
public void tearDown() throws Exception {
- verify(optionsMock, storageRpcMock);
+ verify(rpcFactoryMock, storageRpcMock);
}
@Test
public void testRewrite() {
- RewriteResponse response = new RewriteResponse()
- .setDone(true)
- .setResource(BLOB_INFO.toPb())
- .setObjectSize(BigInteger.valueOf(42L))
- .setTotalBytesRewritten(BigInteger.valueOf(42L));
- EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
- EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries());
- EasyMock.expect(storageRpcMock.rewrite(
- BLOB_ID.toPb(), EMPTY_OPTIONS, BLOB_INFO.toPb(), EMPTY_OPTIONS, null, null))
- .andReturn(response);
- EasyMock.replay(optionsMock, storageRpcMock);
- rewriter = BlobRewriter.builder(optionsMock, BLOB_ID, EMPTY_OPTIONS, BLOB_INFO, EMPTY_OPTIONS)
- .isDone(false)
- .build();
+ EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE_DONE);
+ EasyMock.replay(storageRpcMock);
+ rewriter = new BlobRewriter(options, RESPONSE);
rewriter.copyChunk();
assertTrue(rewriter.isDone());
- assertEquals(BLOB_INFO, rewriter.target());
- assertEquals(BLOB_ID, rewriter.source());
- assertEquals(BigInteger.valueOf(42L), rewriter.totalBytesRewritten());
- assertEquals(BigInteger.valueOf(42L), rewriter.blobSize());
- }
-
- @Test
- public void testRewriteCustumSize() {
- RewriteResponse response = new RewriteResponse()
- .setDone(true)
- .setResource(BLOB_INFO.toPb())
- .setObjectSize(BigInteger.valueOf(42L))
- .setTotalBytesRewritten(BigInteger.valueOf(42L));
- EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
- EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries());
- EasyMock.expect(storageRpcMock.rewrite(
- BLOB_ID.toPb(), EMPTY_OPTIONS, BLOB_INFO.toPb(), EMPTY_OPTIONS, null, 1048576L))
- .andReturn(response);
- EasyMock.replay(optionsMock, storageRpcMock);
- rewriter = BlobRewriter.builder(optionsMock, BLOB_ID, EMPTY_OPTIONS, BLOB_INFO, EMPTY_OPTIONS)
- .isDone(false)
- .maxBytesRewrittenPerCall(1048576L)
- .build();
- rewriter.copyChunk();
- assertTrue(rewriter.isDone());
- assertEquals(BLOB_INFO, rewriter.target());
- assertEquals(BLOB_ID, rewriter.source());
- assertEquals(BigInteger.valueOf(42L), rewriter.totalBytesRewritten());
- assertEquals(BigInteger.valueOf(42L), rewriter.blobSize());
+ assertEquals(RESULT, rewriter.result());
+ assertEquals(new Long(42L), rewriter.totalBytesRewritten());
+ assertEquals(new Long(42L), rewriter.blobSize());
}
@Test
public void testRewriteMultipleRequests() {
- RewriteResponse firstResponse = new RewriteResponse()
- .setDone(false)
- .setResource(BLOB_INFO.toPb())
- .setObjectSize(BigInteger.valueOf(42L))
- .setRewriteToken("token")
- .setTotalBytesRewritten(BigInteger.valueOf(21L));
- RewriteResponse secondResponse = new RewriteResponse()
- .setDone(true)
- .setResource(BLOB_INFO.toPb())
- .setObjectSize(BigInteger.valueOf(42L))
- .setTotalBytesRewritten(BigInteger.valueOf(42L));
- EasyMock.expect(optionsMock.storageRpc()).andReturn(storageRpcMock);
- EasyMock.expect(optionsMock.retryParams()).andReturn(RetryParams.noRetries()).times(2);
- EasyMock.expect(storageRpcMock.rewrite(
- BLOB_ID.toPb(), EMPTY_OPTIONS, BLOB_INFO.toPb(), EMPTY_OPTIONS, null, null))
- .andReturn(firstResponse);
- EasyMock.expect(storageRpcMock.rewrite(
- BLOB_ID.toPb(), EMPTY_OPTIONS, BLOB_INFO.toPb(), EMPTY_OPTIONS, "token", null))
- .andReturn(secondResponse);
- EasyMock.replay(optionsMock, storageRpcMock);
- rewriter = BlobRewriter.builder(optionsMock, BLOB_ID, EMPTY_OPTIONS, BLOB_INFO, EMPTY_OPTIONS)
- .isDone(false)
- .build();
+ EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE);
+ EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE_DONE);
+ EasyMock.replay(storageRpcMock);
+ rewriter = new BlobRewriter(options, RESPONSE);
int loopCount = 0;
while (!rewriter.isDone()) {
rewriter.copyChunk();
loopCount++;
}
assertTrue(rewriter.isDone());
- assertEquals(BLOB_INFO, rewriter.target());
- assertEquals(BLOB_ID, rewriter.source());
- assertEquals(BigInteger.valueOf(42L), rewriter.totalBytesRewritten());
- assertEquals(BigInteger.valueOf(42L), rewriter.blobSize());
+ assertEquals(RESULT, rewriter.result());
+ assertEquals(new Long(42L), rewriter.totalBytesRewritten());
+ assertEquals(new Long(42L), rewriter.blobSize());
assertEquals(2, loopCount);
}
+
+ @Test
+ public void testSaveAndRestore() throws IOException {
+ EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE);
+ EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE_DONE);
+ EasyMock.replay(storageRpcMock);
+ rewriter = new BlobRewriter(options, RESPONSE);
+ rewriter.copyChunk();
+ assertTrue(!rewriter.isDone());
+ assertEquals(null, rewriter.result());
+ assertEquals(new Long(21L), rewriter.totalBytesRewritten());
+ assertEquals(new Long(42L), rewriter.blobSize());
+ RestorableState rewriterState = rewriter.capture();
+ BlobRewriter restoredRewriter = rewriterState.restore();
+ restoredRewriter.copyChunk();
+ assertTrue(restoredRewriter.isDone());
+ assertEquals(RESULT, restoredRewriter.result());
+ assertEquals(new Long(42L), restoredRewriter.totalBytesRewritten());
+ assertEquals(new Long(42L), restoredRewriter.blobSize());
+ }
}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
index b7e7d4b415d0..7025227a27f3 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
@@ -664,38 +664,37 @@ public void testUpdateBlobsFail() {
@Test
public void testRewriteBlob() {
String sourceBlobName = "test-rewrite-blob-source";
- BlobId source = BlobId.of(bucket, sourceBlobName);
+ BlobId source = BlobId.of(BUCKET, sourceBlobName);
assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
String targetBlobName = "test-rewrite-blob-target";
- BlobInfo target = BlobInfo.builder(bucket, targetBlobName).contentType(CONTENT_TYPE).build();
+ BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
Storage.RewriteRequest req = Storage.RewriteRequest.of(source, target);
BlobRewriter rewriter = storage.rewriter(req);
rewriter.copyChunk();
assertTrue(rewriter.isDone());
- assertEquals(rewriter.target(), storage.get(bucket, targetBlobName));
- assertTrue(storage.delete(bucket, sourceBlobName));
- assertTrue(storage.delete(bucket, targetBlobName));
+ assertEquals(rewriter.result(), storage.get(BUCKET, targetBlobName));
+ assertTrue(storage.delete(BUCKET, sourceBlobName));
+ assertTrue(storage.delete(BUCKET, targetBlobName));
}
@Test
public void testRewriteBlobFail() {
String sourceBlobName = "test-rewrite-blob-source-fail";
- BlobId source = BlobId.of(bucket, sourceBlobName);
+ BlobId source = BlobId.of(BUCKET, sourceBlobName);
assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
String targetBlobName = "test-rewrite-blob-target-fail";
- BlobInfo target = BlobInfo.builder(bucket, targetBlobName).contentType(CONTENT_TYPE).build();
+ BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
Storage.RewriteRequest req = Storage.RewriteRequest.builder()
.source(source)
.sourceOptions(Storage.BlobSourceOption.generationMatch(-1L))
.target(target)
.build();
- BlobRewriter rewriter = storage.rewriter(req);
try {
- rewriter.copyChunk();
+ storage.rewriter(req);
fail("StorageException was expected");
} catch (StorageException ex) {
// expected
}
- assertTrue(storage.delete(bucket, sourceBlobName));
+ assertTrue(storage.delete(BUCKET, sourceBlobName));
}
}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
index 9c80d43396c0..6248c9720511 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
@@ -38,6 +38,7 @@
import com.google.gcloud.spi.StorageRpc;
import com.google.gcloud.spi.StorageRpc.Tuple;
import com.google.gcloud.spi.StorageRpcFactory;
+import com.google.gcloud.storage.Storage.RewriteRequest;
import org.easymock.Capture;
import org.easymock.EasyMock;
@@ -960,6 +961,70 @@ public Tuple apply(StorageObject f) {
}
}
+ @Test
+ public void testRewriter() {
+ RewriteRequest request = Storage.RewriteRequest.of(BLOB_INFO1.blobId(), BLOB_INFO2);
+ StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
+ EMPTY_RPC_OPTIONS, request.target().toPb(), EMPTY_RPC_OPTIONS, null);
+ StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
+ false, "token", 21L);
+ EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse);
+ EasyMock.replay(storageRpcMock);
+ storage = options.service();
+ BlobRewriter writer = storage.rewriter(request);
+ assertNull(writer.result());
+ assertEquals(new Long(42L), writer.blobSize());
+ assertEquals(new Long(21L), writer.totalBytesRewritten());
+ assertTrue(!writer.isDone());
+ }
+
+ @Test
+ public void testRewriterWithOptions() {
+ RewriteRequest request = Storage.RewriteRequest.builder()
+ .source(BLOB_INFO2.blobId())
+ .sourceOptions(BLOB_SOURCE_GENERATION, BLOB_SOURCE_METAGENERATION)
+ .target(BLOB_INFO1)
+ .targetOptions(BLOB_TARGET_GENERATION, BLOB_TARGET_METAGENERATION)
+ .build();
+ StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
+ BLOB_SOURCE_OPTIONS_COPY, request.target().toPb(), BLOB_TARGET_OPTIONS_COMPOSE, null);
+ StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
+ false, "token", 21L);
+ EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse);
+ EasyMock.replay(storageRpcMock);
+ storage = options.service();
+ BlobRewriter writer = storage.rewriter(request);
+ assertNull(writer.result());
+ assertEquals(new Long(42L), writer.blobSize());
+ assertEquals(new Long(21L), writer.totalBytesRewritten());
+ assertTrue(!writer.isDone());
+ }
+
+ @Test
+ public void testRewriterMultipleRequests() {
+ RewriteRequest request = Storage.RewriteRequest.of(BLOB_INFO1.blobId(), BLOB_INFO2);
+ StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
+ EMPTY_RPC_OPTIONS, request.target().toPb(), EMPTY_RPC_OPTIONS, null);
+ StorageRpc.RewriteResponse rpcResponse1 = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
+ false, "token", 21L);
+ StorageRpc.RewriteResponse rpcResponse2 = new StorageRpc.RewriteResponse(rpcRequest,
+ BLOB_INFO1.toPb(), 42L, true, "token", 42L);
+ EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse1);
+ EasyMock.expect(storageRpcMock.continueRewrite(rpcResponse1)).andReturn(rpcResponse2);
+ EasyMock.replay(storageRpcMock);
+ storage = options.service();
+ BlobRewriter writer = storage.rewriter(request);
+ assertNull(writer.result());
+ assertEquals(new Long(42L), writer.blobSize());
+ assertEquals(new Long(21L), writer.totalBytesRewritten());
+ assertTrue(!writer.isDone());
+ writer.copyChunk();
+ assertTrue(writer.isDone());
+ assertEquals(BLOB_INFO1, writer.result());
+ assertEquals(new Long(42L), writer.totalBytesRewritten());
+ assertEquals(new Long(42L), writer.blobSize());
+ }
+
@Test
public void testRetryableException() {
BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1);
From 43460b9d9e01c52368d670119bf3a357e1d607aa Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Wed, 28 Oct 2015 15:31:54 +0100
Subject: [PATCH 026/322] Use StorageRpc.rewrite to implement Storage.copy -
rename BlobRewriter to CopyWriter - update Storage.copy and Blob.copyTo
methods to use StorageRpc.openRewrite - update Blob and Storage unit and
intergration tests - update StorageExample
---
.../gcloud/examples/StorageExample.java | 15 +-
.../java/com/google/gcloud/storage/Blob.java | 31 ++--
.../{BlobRewriter.java => CopyWriter.java} | 45 +++---
.../com/google/gcloud/storage/Storage.java | 153 +++---------------
.../google/gcloud/storage/StorageImpl.java | 35 +---
.../com/google/gcloud/storage/BlobTest.java | 32 ++--
...bRewriterTest.java => CopyWriterTest.java} | 48 +++---
.../google/gcloud/storage/ITStorageTest.java | 95 ++++-------
.../gcloud/storage/StorageImplTest.java | 129 ++++++---------
9 files changed, 204 insertions(+), 379 deletions(-)
rename gcloud-java-storage/src/main/java/com/google/gcloud/storage/{BlobRewriter.java => CopyWriter.java} (84%)
rename gcloud-java-storage/src/test/java/com/google/gcloud/storage/{BlobRewriterTest.java => CopyWriterTest.java} (78%)
diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
index 274710f10e93..a13e057d2555 100644
--- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
+++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
@@ -24,6 +24,7 @@
import com.google.gcloud.storage.BlobId;
import com.google.gcloud.storage.BlobInfo;
import com.google.gcloud.storage.BlobReadChannel;
+import com.google.gcloud.storage.CopyWriter;
import com.google.gcloud.storage.BlobWriteChannel;
import com.google.gcloud.storage.Bucket;
import com.google.gcloud.storage.BucketInfo;
@@ -366,21 +367,25 @@ public String params() {
private static class CopyAction extends StorageAction {
@Override
public void run(Storage storage, CopyRequest request) {
- BlobInfo copiedBlobInfo = storage.copy(request);
- System.out.println("Copied " + copiedBlobInfo);
+ CopyWriter copyWriter = storage.copy(request);
+ while (!copyWriter.isDone()) {
+ copyWriter.copyChunk();
+ }
+ System.out.println("Copied " + copyWriter.result());
}
@Override
CopyRequest parse(String... args) {
- if (args.length != 4) {
+ if (args.length != 5) {
throw new IllegalArgumentException();
}
- return CopyRequest.of(args[0], args[1], BlobInfo.builder(args[2], args[3]).build());
+ return CopyRequest.of(args[0], args[1],
+ BlobInfo.builder(args[2], args[3]).contentType(args[4]).build());
}
@Override
public String params() {
- return " ";
+ return " ";
}
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java
index bc75408997f4..dfd112d39c55 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java
@@ -213,19 +213,20 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
}
/**
- * Copies this blob to the specified target. Possibly copying also some of the metadata
- * (e.g. content-type).
+ * Sends a copy request for the current blob to the target blob. Possibly also some of the
+ * metadata are copied (e.g. content-type).
*
* @param targetBlob target blob's id
* @param options source blob options
- * @return the copied blob
+ * @return a {@link CopyWriter} object that can be used to get information on the newly created
+ * blob or to complete the copy if more than one RPC request is needed
* @throws StorageException upon failure
*/
- public Blob copyTo(BlobId targetBlob, BlobSourceOption... options) {
+ public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) {
BlobInfo updatedInfo = info.toBuilder().blobId(targetBlob).build();
CopyRequest copyRequest = CopyRequest.builder().source(info.bucket(), info.name())
.sourceOptions(convert(info, options)).target(updatedInfo).build();
- return new Blob(storage, storage.copy(copyRequest));
+ return storage.copy(copyRequest);
}
/**
@@ -240,33 +241,35 @@ public boolean delete(BlobSourceOption... options) {
}
/**
- * Copies this blob to the target bucket, preserving its name. Possibly copying also some of the
- * metadata (e.g. content-type).
+ * Sends a copy request for the current blob to the target bucket, preserving its name. Possibly
+ * copying also some of the metadata (e.g. content-type).
*
* @param targetBucket target bucket's name
* @param options source blob options
- * @return the copied blob
+ * @return a {@link CopyWriter} object that can be used to get information on the newly created
+ * blob or to complete the copy if more than one RPC request is needed
* @throws StorageException upon failure
*/
- public Blob copyTo(String targetBucket, BlobSourceOption... options) {
+ public CopyWriter copyTo(String targetBucket, BlobSourceOption... options) {
return copyTo(targetBucket, info.name(), options);
}
/**
- * Copies this blob to the target bucket with a new name. Possibly copying also some of the
- * metadata (e.g. content-type).
+ * Sends a copy request for the current blob to the target blob. Possibly also some of the
+ * metadata are copied (e.g. content-type).
*
* @param targetBucket target bucket's name
* @param targetBlob target blob's name
* @param options source blob options
- * @return the copied blob
+ * @return a {@link CopyWriter} object that can be used to get information on the newly created
+ * blob or to complete the copy if more than one RPC request is needed
* @throws StorageException upon failure
*/
- public Blob copyTo(String targetBucket, String targetBlob, BlobSourceOption... options) {
+ public CopyWriter copyTo(String targetBucket, String targetBlob, BlobSourceOption... options) {
BlobInfo updatedInfo = info.toBuilder().blobId(BlobId.of(targetBucket, targetBlob)).build();
CopyRequest copyRequest = CopyRequest.builder().source(info.bucket(), info.name())
.sourceOptions(convert(info, options)).target(updatedInfo).build();
- return new Blob(storage, storage.copy(copyRequest));
+ return storage.copy(copyRequest);
}
/**
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java
similarity index 84%
rename from gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java
rename to gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java
index 75b0516f0acf..916d3c18865f 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobRewriter.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java
@@ -32,15 +32,20 @@
import java.util.concurrent.Callable;
/**
- * Google Storage blob rewriter.
+ * Google Storage blob copy writer. This class holds the result of a copy request.
+ * If source and destination blobs do not share the same location or storage class more than one
+ * RPC request is needed to copy the blob. When this is the case {@link #copyChunk()} can be used
+ * to copy to destination other chunks of the source blob.
+ *
+ * @see Rewrite
*/
-public final class BlobRewriter implements Restorable {
+public class CopyWriter implements Restorable {
private final StorageOptions serviceOptions;
private final StorageRpc storageRpc;
private RewriteResponse rewriteResponse;
- BlobRewriter(StorageOptions serviceOptions, RewriteResponse rewriteResponse) {
+ CopyWriter(StorageOptions serviceOptions, RewriteResponse rewriteResponse) {
this.serviceOptions = serviceOptions;
this.rewriteResponse = rewriteResponse;
this.storageRpc = serviceOptions.rpc();
@@ -69,14 +74,14 @@ public Boolean isDone() {
}
/**
- * Returns the number of bytes written.
+ * Returns the number of bytes copied.
*/
- public Long totalBytesRewritten() {
+ public Long totalBytesCopied() {
return rewriteResponse.totalBytesRewritten;
}
/**
- * Rewrite the next chunk of the blob. An RPC is issued only if rewrite has not finished yet
+ * Copies the next chunk of the blob. An RPC is issued only if copy has not finished yet
* ({@link #isDone} returns {@code false}).
*
* @throws StorageException upon failure
@@ -97,7 +102,7 @@ public RewriteResponse call() {
}
@Override
- public RestorableState capture() {
+ public RestorableState capture() {
return StateImpl.builder(
serviceOptions,
BlobId.fromPb(rewriteResponse.rewriteRequest.source),
@@ -108,11 +113,11 @@ public RestorableState capture() {
.isDone(isDone())
.megabytesRewrittenPerCall(rewriteResponse.rewriteRequest.megabytesRewrittenPerCall)
.rewriteToken(rewriteResponse.rewriteToken)
- .totalBytesRewritten(totalBytesRewritten())
+ .totalBytesRewritten(totalBytesCopied())
.build();
}
- static class StateImpl implements RestorableState, Serializable {
+ static class StateImpl implements RestorableState, Serializable {
private static final long serialVersionUID = 8279287678903181701L;
@@ -125,7 +130,7 @@ static class StateImpl implements RestorableState, Serializable {
private final Long blobSize;
private final Boolean isDone;
private final String rewriteToken;
- private final Long totalBytesRewritten;
+ private final Long totalBytesCopied;
private final Long megabytesRewrittenPerCall;
StateImpl(Builder builder) {
@@ -138,7 +143,7 @@ static class StateImpl implements RestorableState, Serializable {
this.blobSize = builder.blobSize;
this.isDone = builder.isDone;
this.rewriteToken = builder.rewriteToken;
- this.totalBytesRewritten = builder.totalBytesRewritten;
+ this.totalBytesCopied = builder.totalBytesCopied;
this.megabytesRewrittenPerCall = builder.megabytesRewrittenPerCall;
}
@@ -153,7 +158,7 @@ static class Builder {
private Long blobSize;
private Boolean isDone;
private String rewriteToken;
- private Long totalBytesRewritten;
+ private Long totalBytesCopied;
private Long megabytesRewrittenPerCall;
private Builder(StorageOptions options, BlobId source,
@@ -187,7 +192,7 @@ Builder rewriteToken(String rewriteToken) {
}
Builder totalBytesRewritten(Long totalBytesRewritten) {
- this.totalBytesRewritten = totalBytesRewritten;
+ this.totalBytesCopied = totalBytesRewritten;
return this;
}
@@ -196,7 +201,7 @@ Builder megabytesRewrittenPerCall(Long megabytesRewrittenPerCall) {
return this;
}
- RestorableState build() {
+ RestorableState build() {
return new StateImpl(this);
}
}
@@ -208,19 +213,19 @@ static Builder builder(StorageOptions options, BlobId source,
}
@Override
- public BlobRewriter restore() {
+ public CopyWriter restore() {
RewriteRequest rewriteRequest = new RewriteRequest(
source.toPb(), sourceOptions, target.toPb(), targetOptions, megabytesRewrittenPerCall);
RewriteResponse rewriteResponse = new RewriteResponse(rewriteRequest,
result != null ? result.toPb() : null, blobSize, isDone, rewriteToken,
- totalBytesRewritten);
- return new BlobRewriter(serviceOptions, rewriteResponse);
+ totalBytesCopied);
+ return new CopyWriter(serviceOptions, rewriteResponse);
}
@Override
public int hashCode() {
return Objects.hash(serviceOptions, source, sourceOptions, target, targetOptions, result,
- blobSize, isDone, megabytesRewrittenPerCall, rewriteToken, totalBytesRewritten);
+ blobSize, isDone, megabytesRewrittenPerCall, rewriteToken, totalBytesCopied);
}
@Override
@@ -242,7 +247,7 @@ public boolean equals(Object obj) {
&& Objects.equals(this.blobSize, other.blobSize)
&& Objects.equals(this.isDone, other.isDone)
&& Objects.equals(this.megabytesRewrittenPerCall, other.megabytesRewrittenPerCall)
- && Objects.equals(this.totalBytesRewritten, other.totalBytesRewritten);
+ && Objects.equals(this.totalBytesCopied, other.totalBytesCopied);
}
@Override
@@ -251,7 +256,7 @@ public String toString() {
.add("source", source)
.add("target", target)
.add("isDone", isDone)
- .add("totalBytesRewritten", totalBytesRewritten)
+ .add("totalBytesRewritten", totalBytesCopied)
.add("blobSize", blobSize)
.toString();
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
index 88f2a80f8b9b..cc9c3770e790 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
@@ -494,110 +494,6 @@ public static Builder builder() {
class CopyRequest implements Serializable {
- private static final long serialVersionUID = -2606508373751748775L;
-
- private final BlobId source;
- private final List sourceOptions;
- private final BlobInfo target;
- private final List targetOptions;
-
- public static class Builder {
-
- private final Set sourceOptions = new LinkedHashSet<>();
- private final Set targetOptions = new LinkedHashSet<>();
- private BlobId source;
- private BlobInfo target;
-
- public Builder source(String bucket, String blob) {
- this.source = BlobId.of(bucket, blob);
- return this;
- }
-
- public Builder source(BlobId source) {
- this.source = source;
- return this;
- }
-
- public Builder sourceOptions(BlobSourceOption... options) {
- Collections.addAll(sourceOptions, options);
- return this;
- }
-
- public Builder sourceOptions(Iterable options) {
- Iterables.addAll(sourceOptions, options);
- return this;
- }
-
- public Builder target(BlobInfo target) {
- this.target = target;
- return this;
- }
-
- public Builder targetOptions(BlobTargetOption... options) {
- Collections.addAll(targetOptions, options);
- return this;
- }
-
- public Builder targetOptions(Iterable options) {
- Iterables.addAll(targetOptions, options);
- return this;
- }
-
- public CopyRequest build() {
- checkNotNull(source);
- checkNotNull(target);
- return new CopyRequest(this);
- }
- }
-
- private CopyRequest(Builder builder) {
- source = checkNotNull(builder.source);
- sourceOptions = ImmutableList.copyOf(builder.sourceOptions);
- target = checkNotNull(builder.target);
- targetOptions = ImmutableList.copyOf(builder.targetOptions);
- }
-
- public BlobId source() {
- return source;
- }
-
- public List sourceOptions() {
- return sourceOptions;
- }
-
- public BlobInfo target() {
- return target;
- }
-
- public List targetOptions() {
- return targetOptions;
- }
-
- public static CopyRequest of(String sourceBucket, String sourceBlob, BlobInfo target) {
- return builder().source(sourceBucket, sourceBlob).target(target).build();
- }
-
- public static CopyRequest of(BlobId sourceBlobId, BlobInfo target) {
- return builder().source(sourceBlobId).target(target).build();
- }
-
- public static CopyRequest of(String sourceBucket, String sourceBlob, String targetBlob) {
- return of(sourceBucket, sourceBlob,
- BlobInfo.builder(BlobId.of(sourceBucket, targetBlob)).build());
- }
-
- public static CopyRequest of(BlobId sourceBlobId, String targetBlob) {
- return of(sourceBlobId,
- BlobInfo.builder(BlobId.of(sourceBlobId.bucket(), targetBlob)).build());
- }
-
- public static Builder builder() {
- return new Builder();
- }
- }
-
- class RewriteRequest implements Serializable {
-
private static final long serialVersionUID = -4498650529476219937L;
private final BlobId source;
@@ -699,14 +595,14 @@ public Builder megabytesRewrittenPerCall(Long megabytesRewrittenPerCall) {
/**
* Creates a {@code RewriteRequest}.
*/
- public RewriteRequest build() {
+ public CopyRequest build() {
checkNotNull(source);
checkNotNull(target);
- return new RewriteRequest(this);
+ return new CopyRequest(this);
}
}
- private RewriteRequest(Builder builder) {
+ private CopyRequest(Builder builder) {
source = checkNotNull(builder.source);
sourceOptions = ImmutableList.copyOf(builder.sourceOptions);
target = checkNotNull(builder.target);
@@ -751,11 +647,11 @@ public Long megabytesRewrittenPerCall() {
return megabytesRewrittenPerCall;
}
- public static RewriteRequest of(String sourceBucket, String sourceBlob, BlobInfo target) {
+ public static CopyRequest of(String sourceBucket, String sourceBlob, BlobInfo target) {
return builder().source(sourceBucket, sourceBlob).target(target).build();
}
- public static RewriteRequest of(BlobId sourceBlobId, BlobInfo target) {
+ public static CopyRequest of(BlobId sourceBlobId, BlobInfo target) {
return builder().source(sourceBlobId).target(target).build();
}
@@ -923,12 +819,26 @@ public static Builder builder() {
BlobInfo compose(ComposeRequest composeRequest);
/**
- * Send a copy request.
+ * Sends a copy request. Returns a {@link CopyWriter} object for the provided
+ * {@code CopyRequest}. If source and destination objects share the same location and storage
+ * class the source blob is copied and its information can be accessed with
+ * {@link CopyWriter#result()}, regardless of the {@link CopyRequest#megabytesRewrittenPerCall}
+ * parameter. If source and destination have different location or storage class multiple RPC
+ * calls might be needed depending on blob's size.
+ *
+ * Example usage of copy:
+ *
{@code CopyWriter copyWriter = service.copy(copyRequest);}
+ * {@code while(!copyWriter.isDone()) {
+ * copyWriter.copyChunk();
+ * }}
+ *
*
- * @return the copied blob.
+ * @return a {@link CopyWriter} object that can be used to get information on the newly created
+ * blob or to complete the copy if more than one RPC request is needed
* @throws StorageException upon failure
+ * @see Rewrite
*/
- BlobInfo copy(CopyRequest copyRequest);
+ CopyWriter copy(CopyRequest copyRequest);
/**
* Reads all the bytes from a blob.
@@ -1033,23 +943,4 @@ public static Builder builder() {
* @throws StorageException upon failure
*/
List delete(BlobId... blobIds);
-
- /**
- * Returns a {@link BlobRewriter} object for the provided {@code RewriteRequest}. If source and
- * destination objects share the same location and storage class the source blob is copied with a
- * single call of {@link BlobRewriter#copyChunk()}, regardless of the {@link
- * RewriteRequest#maxBytesRewrittenPerCall} parameter. If source and destination have different
- * location or storage class multiple RPC calls might be needed depending on blob's size.
- *
- * Example usage of blob rewriter:
- *
{@code BlobRewriter rewriter = service.rewriter(rewriteRequest);}
- * {@code while(!rewriter.isDone()) {
- * rewriter.copyChunk();
- * }}
- *
- *
- * @throws StorageException upon failure
- * @see Rewrite
- */
- BlobRewriter rewriter(RewriteRequest rewriteRequest);
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
index 7bc39481b8a0..a9fdee6705a0 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
@@ -445,21 +445,22 @@ public StorageObject call() {
}
@Override
- public BlobInfo copy(CopyRequest copyRequest) {
+ public CopyWriter copy(final CopyRequest copyRequest) {
final StorageObject source = copyRequest.source().toPb();
- copyRequest.sourceOptions();
final Map sourceOptions =
optionMap(null, null, copyRequest.sourceOptions(), true);
final StorageObject target = copyRequest.target().toPb();
final Map targetOptions = optionMap(copyRequest.target().generation(),
copyRequest.target().metageneration(), copyRequest.targetOptions());
try {
- return BlobInfo.fromPb(runWithRetries(new Callable() {
+ RewriteResponse rewriteResponse = runWithRetries(new Callable() {
@Override
- public StorageObject call() {
- return storageRpc.copy(source, sourceOptions, target, targetOptions);
+ public RewriteResponse call() {
+ return storageRpc.openRewrite(new StorageRpc.RewriteRequest(source, sourceOptions, target,
+ targetOptions, copyRequest.megabytesRewrittenPerCall()));
}
- }, options().retryParams(), EXCEPTION_HANDLER));
+ }, options().retryParams(), EXCEPTION_HANDLER);
+ return new CopyWriter(options(), rewriteResponse);
} catch (RetryHelperException e) {
throw StorageException.translateAndThrow(e);
}
@@ -664,28 +665,6 @@ public List delete(BlobId... blobIds) {
return Collections.unmodifiableList(transformResultList(response.deletes(), Boolean.FALSE));
}
- @Override
- public BlobRewriter rewriter(final RewriteRequest rewriteRequest) {
- final StorageObject source = rewriteRequest.source().toPb();
- final Map sourceOptions =
- optionMap(null, null, rewriteRequest.sourceOptions(), true);
- final StorageObject target = rewriteRequest.target().toPb();
- final Map targetOptions = optionMap(rewriteRequest.target().generation(),
- rewriteRequest.target().metageneration(), rewriteRequest.targetOptions());
- try {
- RewriteResponse rewriteResponse = runWithRetries(new Callable() {
- @Override
- public RewriteResponse call() {
- return storageRpc.openRewrite(new StorageRpc.RewriteRequest(source, sourceOptions, target,
- targetOptions, rewriteRequest.megabytesRewrittenPerCall()));
- }
- }, options().retryParams(), EXCEPTION_HANDLER);
- return new BlobRewriter(options(), rewriteResponse);
- } catch (RetryHelperException e) {
- throw StorageException.translateAndThrow(e);
- }
- }
-
private static List transformResultList(
List> results, final T errorValue) {
return Lists.transform(results, new Function, T>() {
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java
index dddbb763f04c..095937981b7f 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java
@@ -31,10 +31,12 @@
import com.google.api.client.util.Lists;
import com.google.gcloud.storage.Storage.CopyRequest;
+
import org.easymock.Capture;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+
import java.net.URL;
import java.util.Arrays;
import java.util.List;
@@ -120,41 +122,47 @@ public void testDelete() throws Exception {
@Test
public void testCopyToBucket() throws Exception {
BlobInfo target = BLOB_INFO.toBuilder().blobId(BlobId.of("bt", "n")).build();
+ CopyWriter copyWriter = createMock(CopyWriter.class);
Capture capturedCopyRequest = Capture.newInstance();
- expect(storage.copy(capture(capturedCopyRequest))).andReturn(target);
+ expect(storage.copy(capture(capturedCopyRequest))).andReturn(copyWriter);
replay(storage);
- Blob targetBlob = blob.copyTo("bt");
- assertEquals(target, targetBlob.info());
+ CopyWriter returnedCopyWriter = blob.copyTo("bt");
+ assertEquals(copyWriter, returnedCopyWriter);
assertEquals(capturedCopyRequest.getValue().source(), blob.id());
assertEquals(capturedCopyRequest.getValue().target(), target);
- assertSame(storage, targetBlob.storage());
+ assertTrue(capturedCopyRequest.getValue().sourceOptions().isEmpty());
+ assertTrue(capturedCopyRequest.getValue().targetOptions().isEmpty());
}
@Test
public void testCopyTo() throws Exception {
BlobInfo target = BLOB_INFO.toBuilder().blobId(BlobId.of("bt", "nt")).build();
+ CopyWriter copyWriter = createMock(CopyWriter.class);
Capture capturedCopyRequest = Capture.newInstance();
- expect(storage.copy(capture(capturedCopyRequest))).andReturn(target);
+ expect(storage.copy(capture(capturedCopyRequest))).andReturn(copyWriter);
replay(storage);
- Blob targetBlob = blob.copyTo("bt", "nt");
- assertEquals(target, targetBlob.info());
+ CopyWriter returnedCopyWriter = blob.copyTo("bt", "nt");
+ assertEquals(copyWriter, returnedCopyWriter);
assertEquals(capturedCopyRequest.getValue().source(), blob.id());
assertEquals(capturedCopyRequest.getValue().target(), target);
- assertSame(storage, targetBlob.storage());
+ assertTrue(capturedCopyRequest.getValue().sourceOptions().isEmpty());
+ assertTrue(capturedCopyRequest.getValue().targetOptions().isEmpty());
}
@Test
public void testCopyToBlobId() throws Exception {
BlobId targetId = BlobId.of("bt", "nt");
+ CopyWriter copyWriter = createMock(CopyWriter.class);
BlobInfo target = BLOB_INFO.toBuilder().blobId(targetId).build();
Capture capturedCopyRequest = Capture.newInstance();
- expect(storage.copy(capture(capturedCopyRequest))).andReturn(target);
+ expect(storage.copy(capture(capturedCopyRequest))).andReturn(copyWriter);
replay(storage);
- Blob targetBlob = blob.copyTo(targetId);
- assertEquals(target, targetBlob.info());
+ CopyWriter returnedCopyWriter = blob.copyTo(targetId);
+ assertEquals(copyWriter, returnedCopyWriter);
assertEquals(capturedCopyRequest.getValue().source(), blob.id());
assertEquals(capturedCopyRequest.getValue().target(), target);
- assertSame(storage, targetBlob.storage());
+ assertTrue(capturedCopyRequest.getValue().sourceOptions().isEmpty());
+ assertTrue(capturedCopyRequest.getValue().targetOptions().isEmpty());
}
@Test
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyWriterTest.java
similarity index 78%
rename from gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java
rename to gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyWriterTest.java
index 83cda633fd6a..feba88d57118 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobRewriterTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyWriterTest.java
@@ -39,7 +39,7 @@
import java.io.IOException;
import java.util.Map;
-public class BlobRewriterTest {
+public class CopyWriterTest {
private static final String SOURCE_BUCKET_NAME = "b";
private static final String SOURCE_BLOB_NAME = "n";
@@ -61,7 +61,7 @@ public class BlobRewriterTest {
private StorageOptions options;
private StorageRpcFactory rpcFactoryMock;
private StorageRpc storageRpcMock;
- private BlobRewriter rewriter;
+ private CopyWriter copyWriter;
@Before
public void setUp() throws IOException, InterruptedException {
@@ -85,12 +85,12 @@ public void tearDown() throws Exception {
public void testRewrite() {
EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE_DONE);
EasyMock.replay(storageRpcMock);
- rewriter = new BlobRewriter(options, RESPONSE);
- rewriter.copyChunk();
- assertTrue(rewriter.isDone());
- assertEquals(RESULT, rewriter.result());
- assertEquals(new Long(42L), rewriter.totalBytesRewritten());
- assertEquals(new Long(42L), rewriter.blobSize());
+ copyWriter = new CopyWriter(options, RESPONSE);
+ copyWriter.copyChunk();
+ assertTrue(copyWriter.isDone());
+ assertEquals(RESULT, copyWriter.result());
+ assertEquals(new Long(42L), copyWriter.totalBytesCopied());
+ assertEquals(new Long(42L), copyWriter.blobSize());
}
@Test
@@ -98,16 +98,16 @@ public void testRewriteMultipleRequests() {
EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE);
EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE_DONE);
EasyMock.replay(storageRpcMock);
- rewriter = new BlobRewriter(options, RESPONSE);
+ copyWriter = new CopyWriter(options, RESPONSE);
int loopCount = 0;
- while (!rewriter.isDone()) {
- rewriter.copyChunk();
+ while (!copyWriter.isDone()) {
+ copyWriter.copyChunk();
loopCount++;
}
- assertTrue(rewriter.isDone());
- assertEquals(RESULT, rewriter.result());
- assertEquals(new Long(42L), rewriter.totalBytesRewritten());
- assertEquals(new Long(42L), rewriter.blobSize());
+ assertTrue(copyWriter.isDone());
+ assertEquals(RESULT, copyWriter.result());
+ assertEquals(new Long(42L), copyWriter.totalBytesCopied());
+ assertEquals(new Long(42L), copyWriter.blobSize());
assertEquals(2, loopCount);
}
@@ -116,18 +116,18 @@ public void testSaveAndRestore() throws IOException {
EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE);
EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE_DONE);
EasyMock.replay(storageRpcMock);
- rewriter = new BlobRewriter(options, RESPONSE);
- rewriter.copyChunk();
- assertTrue(!rewriter.isDone());
- assertEquals(null, rewriter.result());
- assertEquals(new Long(21L), rewriter.totalBytesRewritten());
- assertEquals(new Long(42L), rewriter.blobSize());
- RestorableState rewriterState = rewriter.capture();
- BlobRewriter restoredRewriter = rewriterState.restore();
+ copyWriter = new CopyWriter(options, RESPONSE);
+ copyWriter.copyChunk();
+ assertTrue(!copyWriter.isDone());
+ assertEquals(null, copyWriter.result());
+ assertEquals(new Long(21L), copyWriter.totalBytesCopied());
+ assertEquals(new Long(42L), copyWriter.blobSize());
+ RestorableState rewriterState = copyWriter.capture();
+ CopyWriter restoredRewriter = rewriterState.restore();
restoredRewriter.copyChunk();
assertTrue(restoredRewriter.isDone());
assertEquals(RESULT, restoredRewriter.result());
- assertEquals(new Long(42L), restoredRewriter.totalBytesRewritten());
+ assertEquals(new Long(42L), restoredRewriter.totalBytesCopied());
assertEquals(new Long(42L), restoredRewriter.blobSize());
}
}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
index 7025227a27f3..612d4c37aa07 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
@@ -317,16 +317,15 @@ public void testComposeBlobFail() {
@Test
public void testCopyBlob() {
String sourceBlobName = "test-copy-blob-source";
- BlobInfo blob = BlobInfo.builder(BUCKET, sourceBlobName).build();
- assertNotNull(storage.create(blob, BLOB_BYTE_CONTENT));
- String targetBlobName = "test-copy-blob-target";
- Storage.CopyRequest req = Storage.CopyRequest.of(blob.blobId(), targetBlobName);
- BlobInfo remoteBlob = storage.copy(req);
- assertNotNull(remoteBlob);
- assertEquals(BUCKET, remoteBlob.bucket());
- assertEquals(targetBlobName, remoteBlob.name());
- byte[] readBytes = storage.readAllBytes(BUCKET, targetBlobName);
- assertArrayEquals(BLOB_BYTE_CONTENT, readBytes);
+ BlobId source = BlobId.of(BUCKET, sourceBlobName);
+ assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
+ String targetBlobName = "test-rewrite-blob-target";
+ BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
+ Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
+ CopyWriter rewriter = storage.copy(req);
+ rewriter.copyChunk();
+ assertTrue(rewriter.isDone());
+ assertEquals(rewriter.result(), storage.get(BUCKET, targetBlobName));
assertTrue(storage.delete(BUCKET, sourceBlobName));
assertTrue(storage.delete(BUCKET, targetBlobName));
}
@@ -334,30 +333,33 @@ public void testCopyBlob() {
@Test
public void testCopyBlobUpdateMetadata() {
String sourceBlobName = "test-copy-blob-update-metadata-source";
- BlobInfo sourceBlob = BlobInfo.builder(BUCKET, sourceBlobName).build();
- assertNotNull(storage.create(sourceBlob));
- String targetBlobName = "test-copy-blob-update-metadata-target";
- BlobInfo targetBlob =
- BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
- Storage.CopyRequest req = Storage.CopyRequest.of(BUCKET, sourceBlobName, targetBlob);
- BlobInfo remoteBlob = storage.copy(req);
- assertNotNull(remoteBlob);
- assertEquals(targetBlob.blobId(), remoteBlob.blobId());
- assertEquals(CONTENT_TYPE, remoteBlob.contentType());
+ BlobId source = BlobId.of(BUCKET, sourceBlobName);
+ assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
+ String targetBlobName = "test-rewrite-blob-target";
+ BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName)
+ .contentType(CONTENT_TYPE)
+ .metadata(ImmutableMap.of("k", "v"))
+ .build();
+ Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
+ CopyWriter rewriter = storage.copy(req);
+ rewriter.copyChunk();
+ assertTrue(rewriter.isDone());
+ assertEquals(rewriter.result(), storage.get(BUCKET, targetBlobName));
assertTrue(storage.delete(BUCKET, sourceBlobName));
assertTrue(storage.delete(BUCKET, targetBlobName));
}
@Test
public void testCopyBlobFail() {
- String sourceBlobName = "test-copy-blob-fail-source";
- BlobInfo blob = BlobInfo.builder(BUCKET, sourceBlobName).build();
- assertNotNull(storage.create(blob));
- String targetBlobName = "test-copy-blob-fail-target";
- Storage.CopyRequest req = new Storage.CopyRequest.Builder()
- .source(BUCKET, sourceBlobName)
- .target(BlobInfo.builder(BUCKET, targetBlobName).build())
- .sourceOptions(Storage.BlobSourceOption.metagenerationMatch(-1L))
+ String sourceBlobName = "test-copy-blob-source-fail";
+ BlobId source = BlobId.of(BUCKET, sourceBlobName);
+ assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
+ String targetBlobName = "test-rewrite-blob-target-fail";
+ BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
+ Storage.CopyRequest req = Storage.CopyRequest.builder()
+ .source(source)
+ .sourceOptions(Storage.BlobSourceOption.generationMatch(-1L))
+ .target(target)
.build();
try {
storage.copy(req);
@@ -660,41 +662,4 @@ public void testUpdateBlobsFail() {
assertNull(updatedBlobs.get(1));
assertTrue(storage.delete(BUCKET, sourceBlobName1));
}
-
- @Test
- public void testRewriteBlob() {
- String sourceBlobName = "test-rewrite-blob-source";
- BlobId source = BlobId.of(BUCKET, sourceBlobName);
- assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
- String targetBlobName = "test-rewrite-blob-target";
- BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
- Storage.RewriteRequest req = Storage.RewriteRequest.of(source, target);
- BlobRewriter rewriter = storage.rewriter(req);
- rewriter.copyChunk();
- assertTrue(rewriter.isDone());
- assertEquals(rewriter.result(), storage.get(BUCKET, targetBlobName));
- assertTrue(storage.delete(BUCKET, sourceBlobName));
- assertTrue(storage.delete(BUCKET, targetBlobName));
- }
-
- @Test
- public void testRewriteBlobFail() {
- String sourceBlobName = "test-rewrite-blob-source-fail";
- BlobId source = BlobId.of(BUCKET, sourceBlobName);
- assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
- String targetBlobName = "test-rewrite-blob-target-fail";
- BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
- Storage.RewriteRequest req = Storage.RewriteRequest.builder()
- .source(source)
- .sourceOptions(Storage.BlobSourceOption.generationMatch(-1L))
- .target(target)
- .build();
- try {
- storage.rewriter(req);
- fail("StorageException was expected");
- } catch (StorageException ex) {
- // expected
- }
- assertTrue(storage.delete(BUCKET, sourceBlobName));
- }
}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
index 6248c9720511..1a99741fa4d0 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
@@ -38,7 +38,7 @@
import com.google.gcloud.spi.StorageRpc;
import com.google.gcloud.spi.StorageRpc.Tuple;
import com.google.gcloud.spi.StorageRpcFactory;
-import com.google.gcloud.storage.Storage.RewriteRequest;
+import com.google.gcloud.storage.Storage.CopyRequest;
import org.easymock.Capture;
import org.easymock.EasyMock;
@@ -591,33 +591,66 @@ public void testComposeWithOptions() {
@Test
public void testCopy() {
- Storage.CopyRequest req = Storage.CopyRequest.builder()
- .source(BUCKET_NAME1, BLOB_NAME2)
- .target(BLOB_INFO1)
- .build();
- EasyMock.expect(storageRpcMock.copy(BLOB_INFO2.toPb(), EMPTY_RPC_OPTIONS, BLOB_INFO1.toPb(),
- EMPTY_RPC_OPTIONS)).andReturn(BLOB_INFO1.toPb());
+ CopyRequest request = Storage.CopyRequest.of(BLOB_INFO1.blobId(), BLOB_INFO2);
+ StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
+ EMPTY_RPC_OPTIONS, request.target().toPb(), EMPTY_RPC_OPTIONS, null);
+ StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
+ false, "token", 21L);
+ EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse);
EasyMock.replay(storageRpcMock);
storage = options.service();
- BlobInfo blob = storage.copy(req);
- assertEquals(BLOB_INFO1, blob);
+ CopyWriter writer = storage.copy(request);
+ assertNull(writer.result());
+ assertEquals(new Long(42L), writer.blobSize());
+ assertEquals(new Long(21L), writer.totalBytesCopied());
+ assertTrue(!writer.isDone());
}
@Test
public void testCopyWithOptions() {
- Storage.CopyRequest req = Storage.CopyRequest.builder()
- .source(BUCKET_NAME1, BLOB_NAME2)
+ CopyRequest request = Storage.CopyRequest.builder()
+ .source(BLOB_INFO2.blobId())
.sourceOptions(BLOB_SOURCE_GENERATION, BLOB_SOURCE_METAGENERATION)
.target(BLOB_INFO1)
.targetOptions(BLOB_TARGET_GENERATION, BLOB_TARGET_METAGENERATION)
.build();
- EasyMock.expect(
- storageRpcMock.copy(BLOB_INFO2.toPb(), BLOB_SOURCE_OPTIONS_COPY, BLOB_INFO1.toPb(),
- BLOB_TARGET_OPTIONS_COMPOSE)).andReturn(BLOB_INFO1.toPb());
+ StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
+ BLOB_SOURCE_OPTIONS_COPY, request.target().toPb(), BLOB_TARGET_OPTIONS_COMPOSE, null);
+ StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
+ false, "token", 21L);
+ EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse);
EasyMock.replay(storageRpcMock);
storage = options.service();
- BlobInfo blob = storage.copy(req);
- assertEquals(BLOB_INFO1, blob);
+ CopyWriter writer = storage.copy(request);
+ assertNull(writer.result());
+ assertEquals(new Long(42L), writer.blobSize());
+ assertEquals(new Long(21L), writer.totalBytesCopied());
+ assertTrue(!writer.isDone());
+ }
+
+ @Test
+ public void testCopyMultipleRequests() {
+ CopyRequest request = Storage.CopyRequest.of(BLOB_INFO1.blobId(), BLOB_INFO2);
+ StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
+ EMPTY_RPC_OPTIONS, request.target().toPb(), EMPTY_RPC_OPTIONS, null);
+ StorageRpc.RewriteResponse rpcResponse1 = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
+ false, "token", 21L);
+ StorageRpc.RewriteResponse rpcResponse2 = new StorageRpc.RewriteResponse(rpcRequest,
+ BLOB_INFO1.toPb(), 42L, true, "token", 42L);
+ EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse1);
+ EasyMock.expect(storageRpcMock.continueRewrite(rpcResponse1)).andReturn(rpcResponse2);
+ EasyMock.replay(storageRpcMock);
+ storage = options.service();
+ CopyWriter writer = storage.copy(request);
+ assertNull(writer.result());
+ assertEquals(new Long(42L), writer.blobSize());
+ assertEquals(new Long(21L), writer.totalBytesCopied());
+ assertTrue(!writer.isDone());
+ writer.copyChunk();
+ assertTrue(writer.isDone());
+ assertEquals(BLOB_INFO1, writer.result());
+ assertEquals(new Long(42L), writer.totalBytesCopied());
+ assertEquals(new Long(42L), writer.blobSize());
}
@Test
@@ -961,70 +994,6 @@ public Tuple apply(StorageObject f) {
}
}
- @Test
- public void testRewriter() {
- RewriteRequest request = Storage.RewriteRequest.of(BLOB_INFO1.blobId(), BLOB_INFO2);
- StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
- EMPTY_RPC_OPTIONS, request.target().toPb(), EMPTY_RPC_OPTIONS, null);
- StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
- false, "token", 21L);
- EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse);
- EasyMock.replay(storageRpcMock);
- storage = options.service();
- BlobRewriter writer = storage.rewriter(request);
- assertNull(writer.result());
- assertEquals(new Long(42L), writer.blobSize());
- assertEquals(new Long(21L), writer.totalBytesRewritten());
- assertTrue(!writer.isDone());
- }
-
- @Test
- public void testRewriterWithOptions() {
- RewriteRequest request = Storage.RewriteRequest.builder()
- .source(BLOB_INFO2.blobId())
- .sourceOptions(BLOB_SOURCE_GENERATION, BLOB_SOURCE_METAGENERATION)
- .target(BLOB_INFO1)
- .targetOptions(BLOB_TARGET_GENERATION, BLOB_TARGET_METAGENERATION)
- .build();
- StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
- BLOB_SOURCE_OPTIONS_COPY, request.target().toPb(), BLOB_TARGET_OPTIONS_COMPOSE, null);
- StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
- false, "token", 21L);
- EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse);
- EasyMock.replay(storageRpcMock);
- storage = options.service();
- BlobRewriter writer = storage.rewriter(request);
- assertNull(writer.result());
- assertEquals(new Long(42L), writer.blobSize());
- assertEquals(new Long(21L), writer.totalBytesRewritten());
- assertTrue(!writer.isDone());
- }
-
- @Test
- public void testRewriterMultipleRequests() {
- RewriteRequest request = Storage.RewriteRequest.of(BLOB_INFO1.blobId(), BLOB_INFO2);
- StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
- EMPTY_RPC_OPTIONS, request.target().toPb(), EMPTY_RPC_OPTIONS, null);
- StorageRpc.RewriteResponse rpcResponse1 = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
- false, "token", 21L);
- StorageRpc.RewriteResponse rpcResponse2 = new StorageRpc.RewriteResponse(rpcRequest,
- BLOB_INFO1.toPb(), 42L, true, "token", 42L);
- EasyMock.expect(storageRpcMock.openRewrite(rpcRequest)).andReturn(rpcResponse1);
- EasyMock.expect(storageRpcMock.continueRewrite(rpcResponse1)).andReturn(rpcResponse2);
- EasyMock.replay(storageRpcMock);
- storage = options.service();
- BlobRewriter writer = storage.rewriter(request);
- assertNull(writer.result());
- assertEquals(new Long(42L), writer.blobSize());
- assertEquals(new Long(21L), writer.totalBytesRewritten());
- assertTrue(!writer.isDone());
- writer.copyChunk();
- assertTrue(writer.isDone());
- assertEquals(BLOB_INFO1, writer.result());
- assertEquals(new Long(42L), writer.totalBytesRewritten());
- assertEquals(new Long(42L), writer.blobSize());
- }
-
@Test
public void testRetryableException() {
BlobId blob = BlobId.of(BUCKET_NAME1, BLOB_NAME1);
From f90e70c4e9784d1d99784d863a5ae2c5ec257985 Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Wed, 28 Oct 2015 17:13:44 +0100
Subject: [PATCH 027/322] Check contentType != null before adding object to
rewrite
---
.../com/google/gcloud/examples/StorageExample.java | 7 +++----
.../java/com/google/gcloud/spi/DefaultStorageRpc.java | 2 +-
.../main/java/com/google/gcloud/storage/Storage.java | 10 ++++++++++
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
index a13e057d2555..184c4f3d5e0f 100644
--- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
+++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
@@ -376,16 +376,15 @@ public void run(Storage storage, CopyRequest request) {
@Override
CopyRequest parse(String... args) {
- if (args.length != 5) {
+ if (args.length != 4) {
throw new IllegalArgumentException();
}
- return CopyRequest.of(args[0], args[1],
- BlobInfo.builder(args[2], args[3]).contentType(args[4]).build());
+ return CopyRequest.of(args[0], args[1], BlobInfo.builder(args[2], args[3]).build());
}
@Override
public String params() {
- return " ";
+ return " ";
}
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
index 1098ca4c538d..c627d65363f6 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
@@ -539,7 +539,7 @@ private RewriteResponse rewrite(RewriteRequest req, String token) throws Storage
? req.megabytesRewrittenPerCall * MEGABYTE : null;
com.google.api.services.storage.model.RewriteResponse rewriteReponse = storage.objects()
.rewrite(req.source.getBucket(), req.source.getName(), req.target.getBucket(),
- req.target.getName(), req.target)
+ req.target.getName(), req.target.getContentType() != null ? req.target : null)
.setRewriteToken(token)
.setMaxBytesRewrittenPerCall(maxBytesRewrittenPerCall)
.setProjection(DEFAULT_PROJECTION)
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
index cc9c3770e790..8c505a7826aa 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
@@ -655,6 +655,16 @@ public static CopyRequest of(BlobId sourceBlobId, BlobInfo target) {
return builder().source(sourceBlobId).target(target).build();
}
+ public static CopyRequest of(String sourceBucket, String sourceBlob, String targetBlob) {
+ return of(sourceBucket, sourceBlob,
+ BlobInfo.builder(BlobId.of(sourceBucket, targetBlob)).build());
+ }
+
+ public static CopyRequest of(BlobId sourceBlobId, String targetBlob) {
+ return of(sourceBlobId,
+ BlobInfo.builder(BlobId.of(sourceBlobId.bucket(), targetBlob)).build());
+ }
+
public static Builder builder() {
return new Builder();
}
From f2dc019ebc193c5af9e7ed3b7e2030bc97faf1ef Mon Sep 17 00:00:00 2001
From: Ajay Kannan
Date: Wed, 28 Oct 2015 10:31:48 -0700
Subject: [PATCH 028/322] Remove todos from core and datastore
---
.../src/main/java/com/google/gcloud/ServiceOptions.java | 2 --
.../main/java/com/google/gcloud/datastore/DatastoreOptions.java | 2 --
.../test/java/com/google/gcloud/datastore/DatastoreTest.java | 1 -
3 files changed, 5 deletions(-)
diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
index 8555b8d61ed4..c58a71c8b7ef 100644
--- a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
+++ b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
@@ -411,8 +411,6 @@ private static boolean isWindows() {
}
protected static String getAppEngineProjectId() {
- // TODO(ozarov): An alternative to reflection would be to depend on AE api jar:
- // http://mvnrepository.com/artifact/com.google.appengine/appengine-api-1.0-sdk/1.2.0
try {
Class> factoryClass =
Class.forName("com.google.appengine.api.appidentity.AppIdentityServiceFactory");
diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java
index 328573ac7164..5338c03a6d56 100644
--- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java
+++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreOptions.java
@@ -172,8 +172,6 @@ public String namespace() {
}
private static String defaultNamespace() {
- // TODO(ozarov): An alternative to reflection would be to depend on AE api jar:
- // http://mvnrepository.com/artifact/com.google.appengine/appengine-api-1.0-sdk/1.2.0
try {
Class> clazz = Class.forName("com.google.appengine.api.NamespaceManager");
Method method = clazz.getMethod("get");
diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java
index 1d2bb4889658..f639ca3fdac0 100644
--- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java
+++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java
@@ -459,7 +459,6 @@ public void testRunStructuredQuery() {
assertEquals("Dan", entity.getString("name"));
assertEquals(2, entity.properties().size());
assertFalse(results4.hasNext());
- // TODO(ozarov): construct a test to verify nextQuery/pagination
}
@Test
From 22ca3f92e81a6fa1522dc922178652fd103bf312 Mon Sep 17 00:00:00 2001
From: Ajay Kannan
Date: Wed, 28 Oct 2015 11:56:29 -0700
Subject: [PATCH 029/322] Condense modules' pom.xml for site generation
---
gcloud-java-core/pom.xml | 101 +---------------------------------
gcloud-java-datastore/pom.xml | 101 +---------------------------------
gcloud-java-examples/pom.xml | 97 +-------------------------------
gcloud-java-storage/pom.xml | 101 +---------------------------------
gcloud-java/pom.xml | 98 ---------------------------------
pom.xml | 3 +-
6 files changed, 14 insertions(+), 487 deletions(-)
diff --git a/gcloud-java-core/pom.xml b/gcloud-java-core/pom.xml
index 6d25aa42ce95..e849594226db 100644
--- a/gcloud-java-core/pom.xml
+++ b/gcloud-java-core/pom.xml
@@ -13,6 +13,9 @@
gcloud-java-pom
0.0.11-SNAPSHOT
+
+ gcloud-java-core
+
com.google.auth
@@ -90,102 +93,4 @@
test
-
-
-
- org.apache.maven.plugins
- maven-site-plugin
- 3.4
-
- true
-
-
- org.apache.maven.plugins
- maven-changelog-plugin
- 2.3
-
-
- org.apache.maven.plugins
- maven-project-info-reports-plugin
- 2.8
-
-
-
- index
- dependency-info
- dependencies
- dependency-convergence
- project-team
- mailing-list
- cim
- issue-tracking
- license
- scm
- dependency-management
- distribution-management
- summary
- modules
-
-
-
-
- true
- true
- true
- true
- gcloud-java-core
- jar
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
- 2.10
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.10.3
-
-
- html
-
- javadoc
-
-
-
-
- true
- protected
- true
- ${project.build.directory}/javadoc
-
-
-
- org.apache.maven.plugins
- maven-surefire-report-plugin
- 2.18.1
-
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 2.16
-
- checkstyle.xml
- false
-
-
-
- org.codehaus.mojo
- cobertura-maven-plugin
- 2.7
-
- true
-
-
-
-
-
-
-
diff --git a/gcloud-java-datastore/pom.xml b/gcloud-java-datastore/pom.xml
index 6cd56e2c2211..c7c57d91ae1d 100644
--- a/gcloud-java-datastore/pom.xml
+++ b/gcloud-java-datastore/pom.xml
@@ -13,6 +13,9 @@
gcloud-java-pom
0.0.11-SNAPSHOT
+
+ gcloud-java-datastore
+
${project.groupId}
@@ -38,102 +41,4 @@
test
-
-
-
- org.apache.maven.plugins
- maven-site-plugin
- 3.4
-
- true
-
-
- org.apache.maven.plugins
- maven-changelog-plugin
- 2.3
-
-
- org.apache.maven.plugins
- maven-project-info-reports-plugin
- 2.8
-
-
-
- index
- dependency-info
- dependencies
- dependency-convergence
- project-team
- mailing-list
- cim
- issue-tracking
- license
- scm
- dependency-management
- distribution-management
- summary
- modules
-
-
-
-
- true
- true
- true
- true
- gcloud-java-datastore
- jar
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
- 2.10
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.10.3
-
-
- html
-
- javadoc
-
-
-
-
- true
- protected
- true
- ${project.build.directory}/javadoc
-
-
-
- org.apache.maven.plugins
- maven-surefire-report-plugin
- 2.18.1
-
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 2.16
-
- checkstyle.xml
- false
-
-
-
- org.codehaus.mojo
- cobertura-maven-plugin
- 2.7
-
- true
-
-
-
-
-
-
-
diff --git a/gcloud-java-examples/pom.xml b/gcloud-java-examples/pom.xml
index c795571a0ff1..55548e756be3 100644
--- a/gcloud-java-examples/pom.xml
+++ b/gcloud-java-examples/pom.xml
@@ -13,6 +13,9 @@
gcloud-java-pom
0.0.11-SNAPSHOT
+
+ gcloud-java-examples
+
${project.groupId}
@@ -29,100 +32,6 @@
false
-
- org.apache.maven.plugins
- maven-site-plugin
- 3.4
-
- true
-
-
- org.apache.maven.plugins
- maven-changelog-plugin
- 2.3
-
-
- org.apache.maven.plugins
- maven-project-info-reports-plugin
- 2.8
-
-
-
- index
- dependency-info
- dependencies
- dependency-convergence
- project-team
- mailing-list
- cim
- issue-tracking
- license
- scm
- dependency-management
- distribution-management
- summary
- modules
-
-
-
-
- true
- true
- true
- true
- gcloud-java-examples
- jar
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
- 2.10
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.10.3
-
-
- html
-
- javadoc
-
-
-
-
- true
- protected
- true
- ${project.build.directory}/javadoc
-
-
-
- org.apache.maven.plugins
- maven-surefire-report-plugin
- 2.18.1
-
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 2.16
-
- checkstyle.xml
- false
-
-
-
- org.codehaus.mojo
- cobertura-maven-plugin
- 2.7
-
- true
-
-
-
-
-
diff --git a/gcloud-java-storage/pom.xml b/gcloud-java-storage/pom.xml
index f682f498da6c..82b67277f4fe 100644
--- a/gcloud-java-storage/pom.xml
+++ b/gcloud-java-storage/pom.xml
@@ -13,6 +13,9 @@
gcloud-java-pom
0.0.11-SNAPSHOT
+
+ gcloud-java-storage
+
${project.groupId}
@@ -44,102 +47,4 @@
test
-
-
-
- org.apache.maven.plugins
- maven-site-plugin
- 3.4
-
- true
-
-
- org.apache.maven.plugins
- maven-changelog-plugin
- 2.3
-
-
- org.apache.maven.plugins
- maven-project-info-reports-plugin
- 2.8
-
-
-
- index
- dependency-info
- dependencies
- dependency-convergence
- project-team
- mailing-list
- cim
- issue-tracking
- license
- scm
- dependency-management
- distribution-management
- summary
- modules
-
-
-
-
- true
- true
- true
- true
- gcloud-java-storage
- jar
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
- 2.10
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.10.3
-
-
- html
-
- javadoc
-
-
-
-
- true
- protected
- true
- ${project.build.directory}/javadoc
-
-
-
- org.apache.maven.plugins
- maven-surefire-report-plugin
- 2.18.1
-
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 2.16
-
- checkstyle.xml
- false
-
-
-
- org.codehaus.mojo
- cobertura-maven-plugin
- 2.7
-
- true
-
-
-
-
-
-
-
diff --git a/gcloud-java/pom.xml b/gcloud-java/pom.xml
index df5f1352881e..6ad0fce8f1b1 100644
--- a/gcloud-java/pom.xml
+++ b/gcloud-java/pom.xml
@@ -30,102 +30,4 @@
${project.version}
-
-
-
- org.apache.maven.plugins
- maven-site-plugin
- 3.4
-
- true
-
-
- org.apache.maven.plugins
- maven-changelog-plugin
- 2.3
-
-
- org.apache.maven.plugins
- maven-project-info-reports-plugin
- 2.8
-
-
-
- index
- dependency-info
- dependencies
- dependency-convergence
- project-team
- mailing-list
- cim
- issue-tracking
- license
- scm
- dependency-management
- distribution-management
- summary
- modules
-
-
-
-
- true
- true
- true
- true
- gcloud-java
- jar
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
- 2.10
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- 2.10.3
-
-
- html
-
- javadoc
-
-
-
-
- true
- protected
- true
- ${project.build.directory}/javadoc
-
-
-
- org.apache.maven.plugins
- maven-surefire-report-plugin
- 2.18.1
-
-
- org.apache.maven.plugins
- maven-checkstyle-plugin
- 2.16
-
- checkstyle.xml
- false
-
-
-
- org.codehaus.mojo
- cobertura-maven-plugin
- 2.7
-
- true
-
-
-
-
-
-
-
diff --git a/pom.xml b/pom.xml
index 91f88db02c0a..e35a620247d1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,6 +63,7 @@
UTF-8
UTF-8
github
+ gcloud-java
gcloud-java-core
@@ -332,7 +333,7 @@
true
true
true
- gcloud-java
+ ${site.installationModule}
jar
From 352e09756f24b339619ea5384db9020299766c6a Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Wed, 28 Oct 2015 22:25:42 +0100
Subject: [PATCH 030/322] Refactor CopyWriter, Storage and StorageRpc - remove
StorageRpc.copy - make CopyWriter.result issue requests until copy completes
- make RewriteResponse and CopyWriter blobSize isDone and totalBytesCopied
primitive - rename Storage.RewriteRequest megabytesRewrittenPerCall to
megabytesCopiedPerChunk - update tests - update StorageExample
---
.../gcloud/examples/StorageExample.java | 3 -
.../google/gcloud/spi/DefaultStorageRpc.java | 24 -------
.../com/google/gcloud/spi/StorageRpc.java | 17 +++--
.../java/com/google/gcloud/storage/Blob.java | 4 +-
.../com/google/gcloud/storage/CopyWriter.java | 63 ++++++++++---------
.../com/google/gcloud/storage/Storage.java | 39 ++++++------
.../google/gcloud/storage/StorageImpl.java | 2 +-
.../com/google/gcloud/storage/BlobTest.java | 6 +-
.../google/gcloud/storage/CopyWriterTest.java | 31 ++++-----
.../google/gcloud/storage/ITStorageTest.java | 20 +++---
.../gcloud/storage/StorageImplTest.java | 22 +++----
11 files changed, 94 insertions(+), 137 deletions(-)
diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
index 184c4f3d5e0f..b71a51fe6ac6 100644
--- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
+++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
@@ -368,9 +368,6 @@ private static class CopyAction extends StorageAction {
@Override
public void run(Storage storage, CopyRequest request) {
CopyWriter copyWriter = storage.copy(request);
- while (!copyWriter.isDone()) {
- copyWriter.copyChunk();
- }
System.out.println("Copied " + copyWriter.result());
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
index c627d65363f6..957fbc90095d 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
@@ -321,30 +321,6 @@ public StorageObject compose(Iterable sources, StorageObject targ
}
}
- @Override
- public StorageObject copy(StorageObject source, Map sourceOptions,
- StorageObject target, Map targetOptions) throws StorageException {
- try {
- return storage
- .objects()
- .copy(source.getBucket(), source.getName(), target.getBucket(), target.getName(),
- target.getContentType() != null ? target : null)
- .setProjection(DEFAULT_PROJECTION)
- .setIfSourceMetagenerationMatch(IF_SOURCE_METAGENERATION_MATCH.getLong(sourceOptions))
- .setIfSourceMetagenerationNotMatch(
- IF_SOURCE_METAGENERATION_NOT_MATCH.getLong(sourceOptions))
- .setIfSourceGenerationMatch(IF_SOURCE_GENERATION_MATCH.getLong(sourceOptions))
- .setIfSourceGenerationNotMatch(IF_SOURCE_GENERATION_NOT_MATCH.getLong(sourceOptions))
- .setIfMetagenerationMatch(IF_METAGENERATION_MATCH.getLong(targetOptions))
- .setIfMetagenerationNotMatch(IF_METAGENERATION_NOT_MATCH.getLong(targetOptions))
- .setIfGenerationMatch(IF_GENERATION_MATCH.getLong(targetOptions))
- .setIfGenerationNotMatch(IF_GENERATION_NOT_MATCH.getLong(targetOptions))
- .execute();
- } catch (IOException ex) {
- throw translate(ex);
- }
- }
-
@Override
public byte[] load(StorageObject from, Map options)
throws StorageException {
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java
index 1a4afa0524e0..40382a857fca 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/StorageRpc.java
@@ -177,13 +177,13 @@ class RewriteResponse {
public final RewriteRequest rewriteRequest;
public final StorageObject result;
- public final Long blobSize;
- public final Boolean isDone;
+ public final long blobSize;
+ public final boolean isDone;
public final String rewriteToken;
- public final Long totalBytesRewritten;
+ public final long totalBytesRewritten;
- public RewriteResponse(RewriteRequest rewriteRequest, StorageObject result, Long blobSize,
- Boolean isDone, String rewriteToken, Long totalBytesRewritten) {
+ public RewriteResponse(RewriteRequest rewriteRequest, StorageObject result, long blobSize,
+ boolean isDone, String rewriteToken, long totalBytesRewritten) {
this.rewriteRequest = rewriteRequest;
this.result = result;
this.blobSize = blobSize;
@@ -204,9 +204,9 @@ public boolean equals(Object obj) {
return Objects.equals(this.rewriteRequest, other.rewriteRequest)
&& Objects.equals(this.result, other.result)
&& Objects.equals(this.rewriteToken, other.rewriteToken)
- && Objects.equals(this.blobSize, other.blobSize)
+ && this.blobSize == other.blobSize
&& Objects.equals(this.isDone, other.isDone)
- && Objects.equals(this.totalBytesRewritten, other.totalBytesRewritten);
+ && this.totalBytesRewritten == other.totalBytesRewritten;
}
@Override
@@ -245,9 +245,6 @@ StorageObject patch(StorageObject storageObject, Map options)
StorageObject compose(Iterable sources, StorageObject target,
Map targetOptions) throws StorageException;
- StorageObject copy(StorageObject source, Map sourceOptions,
- StorageObject target, Map targetOptions) throws StorageException;
-
byte[] load(StorageObject storageObject, Map options)
throws StorageException;
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java
index dfd112d39c55..284a7818457c 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java
@@ -223,7 +223,7 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
* @throws StorageException upon failure
*/
public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) {
- BlobInfo updatedInfo = info.toBuilder().blobId(targetBlob).build();
+ BlobInfo updatedInfo = BlobInfo.builder(targetBlob).build();
CopyRequest copyRequest = CopyRequest.builder().source(info.bucket(), info.name())
.sourceOptions(convert(info, options)).target(updatedInfo).build();
return storage.copy(copyRequest);
@@ -266,7 +266,7 @@ public CopyWriter copyTo(String targetBucket, BlobSourceOption... options) {
* @throws StorageException upon failure
*/
public CopyWriter copyTo(String targetBucket, String targetBlob, BlobSourceOption... options) {
- BlobInfo updatedInfo = info.toBuilder().blobId(BlobId.of(targetBucket, targetBlob)).build();
+ BlobInfo updatedInfo = BlobInfo.builder(targetBucket, targetBlob).build();
CopyRequest copyRequest = CopyRequest.builder().source(info.bucket(), info.name())
.sourceOptions(convert(info, options)).target(updatedInfo).build();
return storage.copy(copyRequest);
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java
index 916d3c18865f..592cd6e0289a 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java
@@ -34,8 +34,8 @@
/**
* Google Storage blob copy writer. This class holds the result of a copy request.
* If source and destination blobs do not share the same location or storage class more than one
- * RPC request is needed to copy the blob. When this is the case {@link #copyChunk()} can be used
- * to copy to destination other chunks of the source blob.
+ * RPC request is needed to copy the blob otherwise one or more {@link #copyChunk()} calls are
+ * necessary to complete the copy.
*
* @see Rewrite
*/
@@ -52,31 +52,36 @@ public class CopyWriter implements Restorable {
}
/**
- * Returns the updated information for the just written blob when {@link #isDone} is {@code true}.
- * Returns {@code null} otherwise.
+ * Returns the updated information for the just written blob. This method might block and issue
+ * several RPC requests to complete blob copy.
+ *
+ * @throws StorageException upon failure
*/
public BlobInfo result() {
- return rewriteResponse.result != null ? BlobInfo.fromPb(rewriteResponse.result) : null;
+ while(!isDone()) {
+ copyChunk();
+ }
+ return BlobInfo.fromPb(rewriteResponse.result);
}
/**
* Size of the blob being copied.
*/
- public Long blobSize() {
+ public long blobSize() {
return rewriteResponse.blobSize;
}
/**
* Returns {@code true} of blob rewrite finished, {@code false} otherwise.
*/
- public Boolean isDone() {
+ public boolean isDone() {
return rewriteResponse.isDone;
}
/**
* Returns the number of bytes copied.
*/
- public Long totalBytesCopied() {
+ public long totalBytesCopied() {
return rewriteResponse.totalBytesRewritten;
}
@@ -111,7 +116,7 @@ public RestorableState capture() {
rewriteResponse.rewriteRequest.targetOptions)
.blobSize(blobSize())
.isDone(isDone())
- .megabytesRewrittenPerCall(rewriteResponse.rewriteRequest.megabytesRewrittenPerCall)
+ .megabytesCopiedPerChunk(rewriteResponse.rewriteRequest.megabytesRewrittenPerCall)
.rewriteToken(rewriteResponse.rewriteToken)
.totalBytesRewritten(totalBytesCopied())
.build();
@@ -127,11 +132,11 @@ static class StateImpl implements RestorableState, Serializable {
private final BlobInfo target;
private final Map targetOptions;
private final BlobInfo result;
- private final Long blobSize;
- private final Boolean isDone;
+ private final long blobSize;
+ private final boolean isDone;
private final String rewriteToken;
- private final Long totalBytesCopied;
- private final Long megabytesRewrittenPerCall;
+ private final long totalBytesCopied;
+ private final Long megabytesCopiedPerChunk;
StateImpl(Builder builder) {
this.serviceOptions = builder.serviceOptions;
@@ -144,7 +149,7 @@ static class StateImpl implements RestorableState, Serializable {
this.isDone = builder.isDone;
this.rewriteToken = builder.rewriteToken;
this.totalBytesCopied = builder.totalBytesCopied;
- this.megabytesRewrittenPerCall = builder.megabytesRewrittenPerCall;
+ this.megabytesCopiedPerChunk = builder.megabytesCopiedPerChunk;
}
static class Builder {
@@ -155,11 +160,11 @@ static class Builder {
private final BlobInfo target;
private final Map targetOptions;
private BlobInfo result;
- private Long blobSize;
- private Boolean isDone;
+ private long blobSize;
+ private boolean isDone;
private String rewriteToken;
- private Long totalBytesCopied;
- private Long megabytesRewrittenPerCall;
+ private long totalBytesCopied;
+ private Long megabytesCopiedPerChunk;
private Builder(StorageOptions options, BlobId source,
Map sourceOptions,
@@ -176,12 +181,12 @@ Builder result(BlobInfo result) {
return this;
}
- Builder blobSize(Long blobSize) {
+ Builder blobSize(long blobSize) {
this.blobSize = blobSize;
return this;
}
- Builder isDone(Boolean isDone) {
+ Builder isDone(boolean isDone) {
this.isDone = isDone;
return this;
}
@@ -191,13 +196,13 @@ Builder rewriteToken(String rewriteToken) {
return this;
}
- Builder totalBytesRewritten(Long totalBytesRewritten) {
+ Builder totalBytesRewritten(long totalBytesRewritten) {
this.totalBytesCopied = totalBytesRewritten;
return this;
}
- Builder megabytesRewrittenPerCall(Long megabytesRewrittenPerCall) {
- this.megabytesRewrittenPerCall = megabytesRewrittenPerCall;
+ Builder megabytesCopiedPerChunk(Long megabytesCopiedPerChunk) {
+ this.megabytesCopiedPerChunk = megabytesCopiedPerChunk;
return this;
}
@@ -215,7 +220,7 @@ static Builder builder(StorageOptions options, BlobId source,
@Override
public CopyWriter restore() {
RewriteRequest rewriteRequest = new RewriteRequest(
- source.toPb(), sourceOptions, target.toPb(), targetOptions, megabytesRewrittenPerCall);
+ source.toPb(), sourceOptions, target.toPb(), targetOptions, megabytesCopiedPerChunk);
RewriteResponse rewriteResponse = new RewriteResponse(rewriteRequest,
result != null ? result.toPb() : null, blobSize, isDone, rewriteToken,
totalBytesCopied);
@@ -225,7 +230,7 @@ public CopyWriter restore() {
@Override
public int hashCode() {
return Objects.hash(serviceOptions, source, sourceOptions, target, targetOptions, result,
- blobSize, isDone, megabytesRewrittenPerCall, rewriteToken, totalBytesCopied);
+ blobSize, isDone, megabytesCopiedPerChunk, rewriteToken, totalBytesCopied);
}
@Override
@@ -244,10 +249,10 @@ public boolean equals(Object obj) {
&& Objects.equals(this.targetOptions, other.targetOptions)
&& Objects.equals(this.result, other.result)
&& Objects.equals(this.rewriteToken, other.rewriteToken)
- && Objects.equals(this.blobSize, other.blobSize)
- && Objects.equals(this.isDone, other.isDone)
- && Objects.equals(this.megabytesRewrittenPerCall, other.megabytesRewrittenPerCall)
- && Objects.equals(this.totalBytesCopied, other.totalBytesCopied);
+ && Objects.equals(this.megabytesCopiedPerChunk, other.megabytesCopiedPerChunk)
+ && this.blobSize == other.blobSize
+ && this.isDone == other.isDone
+ && this.totalBytesCopied == other.totalBytesCopied;
}
@Override
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
index 8c505a7826aa..1c65ff82dfaa 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
@@ -500,7 +500,7 @@ class CopyRequest implements Serializable {
private final List sourceOptions;
private final BlobInfo target;
private final List targetOptions;
- private final Long megabytesRewrittenPerCall;
+ private final Long megabytesCopiedPerChunk;
public static class Builder {
@@ -508,10 +508,10 @@ public static class Builder {
private final Set targetOptions = new LinkedHashSet<>();
private BlobId source;
private BlobInfo target;
- private Long megabytesRewrittenPerCall;
+ private Long megabytesCopiedPerChunk;
/**
- * Sets the blob to rewrite given bucket and blob name.
+ * Sets the blob to copy given bucket and blob name.
*
* @return the builder.
*/
@@ -521,7 +521,7 @@ public Builder source(String bucket, String blob) {
}
/**
- * Sets the blob to rewrite given a {@link BlobId}.
+ * Sets the blob to copy given a {@link BlobId}.
*
* @return the builder.
*/
@@ -551,7 +551,7 @@ public Builder sourceOptions(Iterable options) {
}
/**
- * Sets the rewrite target.
+ * Sets the copy target.
*
* @return the builder.
*/
@@ -582,18 +582,18 @@ public Builder targetOptions(Iterable options) {
/**
* Sets the maximum number of megabytes to copy for each RPC call. This parameter is ignored
- * if source and target blob share the same location and storage class as rewrite is made with
+ * if source and target blob share the same location and storage class as copy is made with
* one single RPC.
*
* @return the builder.
*/
- public Builder megabytesRewrittenPerCall(Long megabytesRewrittenPerCall) {
- this.megabytesRewrittenPerCall = megabytesRewrittenPerCall;
+ public Builder megabytesCopiedPerChunk(Long megabytesCopiedPerChunk) {
+ this.megabytesCopiedPerChunk = megabytesCopiedPerChunk;
return this;
}
/**
- * Creates a {@code RewriteRequest}.
+ * Creates a {@code CopyRequest}.
*/
public CopyRequest build() {
checkNotNull(source);
@@ -607,7 +607,7 @@ private CopyRequest(Builder builder) {
sourceOptions = ImmutableList.copyOf(builder.sourceOptions);
target = checkNotNull(builder.target);
targetOptions = ImmutableList.copyOf(builder.targetOptions);
- megabytesRewrittenPerCall = builder.megabytesRewrittenPerCall;
+ megabytesCopiedPerChunk = builder.megabytesCopiedPerChunk;
}
/**
@@ -640,11 +640,11 @@ public List targetOptions() {
/**
* Returns the maximum number of megabytes to copy for each RPC call. This parameter is ignored
- * if source and target blob share the same location and storage class as rewrite is made with
+ * if source and target blob share the same location and storage class as copy is made with
* one single RPC.
*/
- public Long megabytesRewrittenPerCall() {
- return megabytesRewrittenPerCall;
+ public Long megabytesCopiedPerChunk() {
+ return megabytesCopiedPerChunk;
}
public static CopyRequest of(String sourceBucket, String sourceBlob, BlobInfo target) {
@@ -831,16 +831,13 @@ public static Builder builder() {
/**
* Sends a copy request. Returns a {@link CopyWriter} object for the provided
* {@code CopyRequest}. If source and destination objects share the same location and storage
- * class the source blob is copied and its information can be accessed with
- * {@link CopyWriter#result()}, regardless of the {@link CopyRequest#megabytesRewrittenPerCall}
- * parameter. If source and destination have different location or storage class multiple RPC
- * calls might be needed depending on blob's size.
+ * class the source blob is copied with one request and {@link CopyWriter#result()} immediately
+ * returns, regardless of the {@link CopyRequest#megabytesCopiedPerChunk} parameter.
+ * If source and destination have different location or storage class {@link CopyWriter#result()}
+ * might issue multiple RPC calls depending on blob's size.
*
* Example usage of copy:
- *
{@code CopyWriter copyWriter = service.copy(copyRequest);}
- * {@code while(!copyWriter.isDone()) {
- * copyWriter.copyChunk();
- * }}
+ * {@code BlobInfo blob = service.copy(copyRequest).result();}
*
*
* @return a {@link CopyWriter} object that can be used to get information on the newly created
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
index a9fdee6705a0..ab85dc8b4609 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java
@@ -457,7 +457,7 @@ public CopyWriter copy(final CopyRequest copyRequest) {
@Override
public RewriteResponse call() {
return storageRpc.openRewrite(new StorageRpc.RewriteRequest(source, sourceOptions, target,
- targetOptions, copyRequest.megabytesRewrittenPerCall()));
+ targetOptions, copyRequest.megabytesCopiedPerChunk()));
}
}, options().retryParams(), EXCEPTION_HANDLER);
return new CopyWriter(options(), rewriteResponse);
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java
index 095937981b7f..defb1d35e3f4 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobTest.java
@@ -121,7 +121,7 @@ public void testDelete() throws Exception {
@Test
public void testCopyToBucket() throws Exception {
- BlobInfo target = BLOB_INFO.toBuilder().blobId(BlobId.of("bt", "n")).build();
+ BlobInfo target = BlobInfo.builder(BlobId.of("bt", "n")).build();
CopyWriter copyWriter = createMock(CopyWriter.class);
Capture capturedCopyRequest = Capture.newInstance();
expect(storage.copy(capture(capturedCopyRequest))).andReturn(copyWriter);
@@ -136,7 +136,7 @@ public void testCopyToBucket() throws Exception {
@Test
public void testCopyTo() throws Exception {
- BlobInfo target = BLOB_INFO.toBuilder().blobId(BlobId.of("bt", "nt")).build();
+ BlobInfo target = BlobInfo.builder(BlobId.of("bt", "nt")).build();
CopyWriter copyWriter = createMock(CopyWriter.class);
Capture capturedCopyRequest = Capture.newInstance();
expect(storage.copy(capture(capturedCopyRequest))).andReturn(copyWriter);
@@ -153,7 +153,7 @@ public void testCopyTo() throws Exception {
public void testCopyToBlobId() throws Exception {
BlobId targetId = BlobId.of("bt", "nt");
CopyWriter copyWriter = createMock(CopyWriter.class);
- BlobInfo target = BLOB_INFO.toBuilder().blobId(targetId).build();
+ BlobInfo target = BLOB_INFO.builder(targetId).build();
Capture capturedCopyRequest = Capture.newInstance();
expect(storage.copy(capture(capturedCopyRequest))).andReturn(copyWriter);
replay(storage);
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyWriterTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyWriterTest.java
index feba88d57118..0fcdb744c244 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyWriterTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyWriterTest.java
@@ -86,11 +86,10 @@ public void testRewrite() {
EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE_DONE);
EasyMock.replay(storageRpcMock);
copyWriter = new CopyWriter(options, RESPONSE);
- copyWriter.copyChunk();
- assertTrue(copyWriter.isDone());
assertEquals(RESULT, copyWriter.result());
- assertEquals(new Long(42L), copyWriter.totalBytesCopied());
- assertEquals(new Long(42L), copyWriter.blobSize());
+ assertTrue(copyWriter.isDone());
+ assertEquals(42L, copyWriter.totalBytesCopied());
+ assertEquals(42L, copyWriter.blobSize());
}
@Test
@@ -99,16 +98,10 @@ public void testRewriteMultipleRequests() {
EasyMock.expect(storageRpcMock.continueRewrite(RESPONSE)).andReturn(RESPONSE_DONE);
EasyMock.replay(storageRpcMock);
copyWriter = new CopyWriter(options, RESPONSE);
- int loopCount = 0;
- while (!copyWriter.isDone()) {
- copyWriter.copyChunk();
- loopCount++;
- }
- assertTrue(copyWriter.isDone());
assertEquals(RESULT, copyWriter.result());
- assertEquals(new Long(42L), copyWriter.totalBytesCopied());
- assertEquals(new Long(42L), copyWriter.blobSize());
- assertEquals(2, loopCount);
+ assertTrue(copyWriter.isDone());
+ assertEquals(42L, copyWriter.totalBytesCopied());
+ assertEquals(42L, copyWriter.blobSize());
}
@Test
@@ -119,15 +112,13 @@ public void testSaveAndRestore() throws IOException {
copyWriter = new CopyWriter(options, RESPONSE);
copyWriter.copyChunk();
assertTrue(!copyWriter.isDone());
- assertEquals(null, copyWriter.result());
- assertEquals(new Long(21L), copyWriter.totalBytesCopied());
- assertEquals(new Long(42L), copyWriter.blobSize());
+ assertEquals(21L, copyWriter.totalBytesCopied());
+ assertEquals(42L, copyWriter.blobSize());
RestorableState rewriterState = copyWriter.capture();
CopyWriter restoredRewriter = rewriterState.restore();
- restoredRewriter.copyChunk();
- assertTrue(restoredRewriter.isDone());
assertEquals(RESULT, restoredRewriter.result());
- assertEquals(new Long(42L), restoredRewriter.totalBytesCopied());
- assertEquals(new Long(42L), restoredRewriter.blobSize());
+ assertTrue(restoredRewriter.isDone());
+ assertEquals(42L, restoredRewriter.totalBytesCopied());
+ assertEquals(42L, restoredRewriter.blobSize());
}
}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
index 612d4c37aa07..408c6e7ed6d6 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
@@ -319,13 +319,12 @@ public void testCopyBlob() {
String sourceBlobName = "test-copy-blob-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
- String targetBlobName = "test-rewrite-blob-target";
+ String targetBlobName = "test-copy-blob-target";
BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
- CopyWriter rewriter = storage.copy(req);
- rewriter.copyChunk();
- assertTrue(rewriter.isDone());
- assertEquals(rewriter.result(), storage.get(BUCKET, targetBlobName));
+ CopyWriter copyWriter = storage.copy(req);
+ assertEquals(copyWriter.result(), storage.get(BUCKET, targetBlobName));
+ assertTrue(copyWriter.isDone());
assertTrue(storage.delete(BUCKET, sourceBlobName));
assertTrue(storage.delete(BUCKET, targetBlobName));
}
@@ -335,16 +334,15 @@ public void testCopyBlobUpdateMetadata() {
String sourceBlobName = "test-copy-blob-update-metadata-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
- String targetBlobName = "test-rewrite-blob-target";
+ String targetBlobName = "test-copy-blob-target";
BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName)
.contentType(CONTENT_TYPE)
.metadata(ImmutableMap.of("k", "v"))
.build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
- CopyWriter rewriter = storage.copy(req);
- rewriter.copyChunk();
- assertTrue(rewriter.isDone());
- assertEquals(rewriter.result(), storage.get(BUCKET, targetBlobName));
+ CopyWriter copyWriter = storage.copy(req);
+ assertEquals(copyWriter.result(), storage.get(BUCKET, targetBlobName));
+ assertTrue(copyWriter.isDone());
assertTrue(storage.delete(BUCKET, sourceBlobName));
assertTrue(storage.delete(BUCKET, targetBlobName));
}
@@ -354,7 +352,7 @@ public void testCopyBlobFail() {
String sourceBlobName = "test-copy-blob-source-fail";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
- String targetBlobName = "test-rewrite-blob-target-fail";
+ String targetBlobName = "test-copy-blob-target-fail";
BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
Storage.CopyRequest req = Storage.CopyRequest.builder()
.source(source)
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
index 1a99741fa4d0..910d614c64d7 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
@@ -600,9 +600,8 @@ public void testCopy() {
EasyMock.replay(storageRpcMock);
storage = options.service();
CopyWriter writer = storage.copy(request);
- assertNull(writer.result());
- assertEquals(new Long(42L), writer.blobSize());
- assertEquals(new Long(21L), writer.totalBytesCopied());
+ assertEquals(42L, writer.blobSize());
+ assertEquals(21L, writer.totalBytesCopied());
assertTrue(!writer.isDone());
}
@@ -622,9 +621,8 @@ public void testCopyWithOptions() {
EasyMock.replay(storageRpcMock);
storage = options.service();
CopyWriter writer = storage.copy(request);
- assertNull(writer.result());
- assertEquals(new Long(42L), writer.blobSize());
- assertEquals(new Long(21L), writer.totalBytesCopied());
+ assertEquals(42L, writer.blobSize());
+ assertEquals(21L, writer.totalBytesCopied());
assertTrue(!writer.isDone());
}
@@ -642,15 +640,13 @@ public void testCopyMultipleRequests() {
EasyMock.replay(storageRpcMock);
storage = options.service();
CopyWriter writer = storage.copy(request);
- assertNull(writer.result());
- assertEquals(new Long(42L), writer.blobSize());
- assertEquals(new Long(21L), writer.totalBytesCopied());
+ assertEquals(42L, writer.blobSize());
+ assertEquals(21L, writer.totalBytesCopied());
assertTrue(!writer.isDone());
- writer.copyChunk();
- assertTrue(writer.isDone());
assertEquals(BLOB_INFO1, writer.result());
- assertEquals(new Long(42L), writer.totalBytesCopied());
- assertEquals(new Long(42L), writer.blobSize());
+ assertTrue(writer.isDone());
+ assertEquals(42L, writer.totalBytesCopied());
+ assertEquals(42L, writer.blobSize());
}
@Test
From 23215a1547449f044b0148b7d37cc4ecb958b83e Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Thu, 29 Oct 2015 09:02:41 +0100
Subject: [PATCH 031/322] Better javadoc, check contentType and metadata in
integrationt tests
---
.../com/google/gcloud/storage/CopyWriter.java | 23 +++++++++++-------
.../com/google/gcloud/storage/Storage.java | 8 +++++++
.../google/gcloud/storage/ITStorageTest.java | 24 ++++++++++++++-----
3 files changed, 41 insertions(+), 14 deletions(-)
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java
index 592cd6e0289a..142f8d4b6de7 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/CopyWriter.java
@@ -32,10 +32,11 @@
import java.util.concurrent.Callable;
/**
- * Google Storage blob copy writer. This class holds the result of a copy request.
- * If source and destination blobs do not share the same location or storage class more than one
- * RPC request is needed to copy the blob otherwise one or more {@link #copyChunk()} calls are
- * necessary to complete the copy.
+ * Google Storage blob copy writer. This class holds the result of a copy request. If source and
+ * destination blobs share the same location and storage class the copy is completed in one RPC call
+ * otherwise one or more {@link #copyChunk} calls are necessary to complete the copy. In addition,
+ * {@link CopyWriter#result()} can be used to automatically complete the copy and return information
+ * on the newly created blob.
*
* @see Rewrite
*/
@@ -52,20 +53,26 @@ public class CopyWriter implements Restorable {
}
/**
- * Returns the updated information for the just written blob. This method might block and issue
- * several RPC requests to complete blob copy.
+ * Returns the updated information for the written blob. Calling this method when {@code isDone()}
+ * is {@code false} will block until all pending chunks are copied.
+ *
+ * This method has the same effect of doing:
+ *
{@code while (!copyWriter.isDone()) {
+ * copyWriter.copyChunk();
+ * }}
+ *
*
* @throws StorageException upon failure
*/
public BlobInfo result() {
- while(!isDone()) {
+ while (!isDone()) {
copyChunk();
}
return BlobInfo.fromPb(rewriteResponse.result);
}
/**
- * Size of the blob being copied.
+ * Returns the size of the blob being copied.
*/
public long blobSize() {
return rewriteResponse.blobSize;
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
index 1c65ff82dfaa..98698107a205 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
@@ -839,6 +839,14 @@ public static Builder builder() {
* Example usage of copy:
* {@code BlobInfo blob = service.copy(copyRequest).result();}
*
+ * To explicitly issue chunk copy requests use {@link CopyWriter#copyChunk()} instead:
+ * {@code CopyWriter copyWriter = service.copy(copyRequest);
+ * while (!copyWriter.isDone()) {
+ * copyWriter.copyChunk();
+ * }
+ * BlobInfo blob = copyWriter.result();
+ * }
+ *
*
* @return a {@link CopyWriter} object that can be used to get information on the newly created
* blob or to complete the copy if more than one RPC request is needed
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
index 408c6e7ed6d6..8957ed2b8364 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
@@ -318,12 +318,20 @@ public void testComposeBlobFail() {
public void testCopyBlob() {
String sourceBlobName = "test-copy-blob-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
- assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
+ ImmutableMap metadata = ImmutableMap.of("k", "v");
+ BlobInfo blob = BlobInfo.builder(source)
+ .contentType(CONTENT_TYPE)
+ .metadata(metadata)
+ .build();
+ assertNotNull(storage.create(blob, BLOB_BYTE_CONTENT));
String targetBlobName = "test-copy-blob-target";
- BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).contentType(CONTENT_TYPE).build();
+ BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
CopyWriter copyWriter = storage.copy(req);
- assertEquals(copyWriter.result(), storage.get(BUCKET, targetBlobName));
+ assertEquals(BUCKET, copyWriter.result().bucket());
+ assertEquals(targetBlobName, copyWriter.result().name());
+ assertEquals(CONTENT_TYPE, copyWriter.result().contentType());
+ assertEquals(metadata, copyWriter.result().metadata());
assertTrue(copyWriter.isDone());
assertTrue(storage.delete(BUCKET, sourceBlobName));
assertTrue(storage.delete(BUCKET, targetBlobName));
@@ -334,14 +342,18 @@ public void testCopyBlobUpdateMetadata() {
String sourceBlobName = "test-copy-blob-update-metadata-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
assertNotNull(storage.create(BlobInfo.builder(source).build(), BLOB_BYTE_CONTENT));
- String targetBlobName = "test-copy-blob-target";
+ String targetBlobName = "test-copy-blob-update-metadata-target";
+ ImmutableMap metadata = ImmutableMap.of("k", "v");
BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName)
.contentType(CONTENT_TYPE)
- .metadata(ImmutableMap.of("k", "v"))
+ .metadata(metadata)
.build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
CopyWriter copyWriter = storage.copy(req);
- assertEquals(copyWriter.result(), storage.get(BUCKET, targetBlobName));
+ assertEquals(BUCKET, copyWriter.result().bucket());
+ assertEquals(targetBlobName, copyWriter.result().name());
+ assertEquals(CONTENT_TYPE, copyWriter.result().contentType());
+ assertEquals(metadata, copyWriter.result().metadata());
assertTrue(copyWriter.isDone());
assertTrue(storage.delete(BUCKET, sourceBlobName));
assertTrue(storage.delete(BUCKET, targetBlobName));
From f0fe56a51fbe05f30d53d37fb2ee4bd4c5417bb9 Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Thu, 29 Oct 2015 16:19:30 +0100
Subject: [PATCH 032/322] Add applicationName to Options, set user agent
accordingly in Storage
---
.../com/google/gcloud/ServiceOptions.java | 35 +++++++++++++++++++
.../google/gcloud/spi/DefaultStorageRpc.java | 2 +-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
index c58a71c8b7ef..1be1f16115ad 100644
--- a/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
+++ b/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java
@@ -40,10 +40,14 @@
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.util.Enumeration;
import java.util.Locale;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -56,6 +60,11 @@ public abstract class ServiceOptions<
private static final String DEFAULT_HOST = "https://www.googleapis.com";
private static final long serialVersionUID = 1203687993961393350L;
private static final String PROJECT_ENV_NAME = "GCLOUD_PROJECT";
+ private static final String MANIFEST_ARTIFACT_ID_KEY = "artifactId";
+ private static final String MANIFEST_VERSION_KEY = "Implementation-Version";
+ private static final String ARTIFACT_ID = "gcloud-java-core";
+ private static final String APPLICATION_BASE_NAME = "gcloud-java";
+ private static final String APPLICATION_NAME = getApplicationName();
private final String projectId;
private final String host;
@@ -522,6 +531,13 @@ public Clock clock() {
return clock;
}
+ /**
+ * Returns the application's name as a string in the format {@code gcloud-java/[version]}.
+ */
+ public String applicationName() {
+ return APPLICATION_NAME;
+ }
+
protected int baseHashCode() {
return Objects.hash(projectId, host, httpTransportFactoryClassName, authCredentialsState,
retryParams, serviceFactoryClassName, serviceRpcFactoryClassName, connectTimeout,
@@ -568,4 +584,23 @@ private static T newInstance(String className) throws IOException, ClassNotF
private static T getFromServiceLoader(Class extends T> clazz, T defaultInstance) {
return Iterables.getFirst(ServiceLoader.load(clazz), defaultInstance);
}
+
+ private static String getApplicationName() {
+ String version = null;
+ try {
+ Enumeration resources =
+ ServiceOptions.class.getClassLoader().getResources(JarFile.MANIFEST_NAME);
+ while (resources.hasMoreElements() && version == null) {
+ Manifest manifest = new Manifest(resources.nextElement().openStream());
+ Attributes manifestAttributes = manifest.getMainAttributes();
+ String artifactId = manifestAttributes.getValue(MANIFEST_ARTIFACT_ID_KEY);
+ if (artifactId != null && artifactId.equals(ARTIFACT_ID)) {
+ version = manifestAttributes.getValue(MANIFEST_VERSION_KEY);
+ }
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ return version != null ? APPLICATION_BASE_NAME + "/" + version : APPLICATION_BASE_NAME;
+ }
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
index 90f2c98ad4b8..349cfbf771cb 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java
@@ -85,7 +85,7 @@ public DefaultStorageRpc(StorageOptions options) {
this.options = options;
storage = new Storage.Builder(transport, new JacksonFactory(), initializer)
.setRootUrl(options.host())
- .setApplicationName("gcloud-java")
+ .setApplicationName(options.applicationName())
.build();
}
From 1410494164840cf434a6619619f917d1fe9dd153 Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Thu, 29 Oct 2015 19:17:41 +0100
Subject: [PATCH 033/322] Update CopyRequest to check target content type - Add
CopyRequest.target(BlobId) to add target with no contentType checks - Change
CopyRequest.target(BlobInfo) to CopyRequest.target(BlobInfo,
BlobTargetOptions...) - Remove CopyRequest.targetOptions method, options are
only set with a BlobInfo target - Add new CopyRequest.of methods - Update
tests and example
---
.../gcloud/examples/StorageExample.java | 7 +-
.../java/com/google/gcloud/storage/Blob.java | 8 +-
.../com/google/gcloud/storage/Storage.java | 108 +++++++++++++--
.../gcloud/storage/CopyRequestTest.java | 129 ++++++++++++++++++
.../google/gcloud/storage/ITStorageTest.java | 3 +-
.../gcloud/storage/StorageImplTest.java | 7 +-
6 files changed, 236 insertions(+), 26 deletions(-)
create mode 100644 gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyRequestTest.java
diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
index b71a51fe6ac6..fb207023203f 100644
--- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
+++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/StorageExample.java
@@ -376,7 +376,7 @@ CopyRequest parse(String... args) {
if (args.length != 4) {
throw new IllegalArgumentException();
}
- return CopyRequest.of(args[0], args[1], BlobInfo.builder(args[2], args[3]).build());
+ return CopyRequest.of(args[0], args[1], BlobId.of(args[2], args[3]));
}
@Override
@@ -544,11 +544,14 @@ public static void main(String... args) throws Exception {
StorageOptions.Builder optionsBuilder =
StorageOptions.builder().retryParams(RetryParams.getDefaultInstance());
StorageAction action;
+ String actionName;
if (args.length >= 2 && !ACTIONS.containsKey(args[0])) {
+ actionName = args[1];
optionsBuilder.projectId(args[0]);
action = ACTIONS.get(args[1]);
args = Arrays.copyOfRange(args, 2, args.length);
} else {
+ actionName = args[0];
action = ACTIONS.get(args[0]);
args = Arrays.copyOfRange(args, 1, args.length);
}
@@ -562,7 +565,7 @@ public static void main(String... args) throws Exception {
try {
request = action.parse(args);
} catch (IllegalArgumentException ex) {
- System.out.println("Invalid input for action '" + args[1] + "'");
+ System.out.println("Invalid input for action '" + actionName + "'");
System.out.println("Expected: " + action.params());
return;
} catch (Exception ex) {
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java
index 284a7818457c..8f988922aad9 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Blob.java
@@ -223,9 +223,8 @@ public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
* @throws StorageException upon failure
*/
public CopyWriter copyTo(BlobId targetBlob, BlobSourceOption... options) {
- BlobInfo updatedInfo = BlobInfo.builder(targetBlob).build();
CopyRequest copyRequest = CopyRequest.builder().source(info.bucket(), info.name())
- .sourceOptions(convert(info, options)).target(updatedInfo).build();
+ .sourceOptions(convert(info, options)).target(targetBlob).build();
return storage.copy(copyRequest);
}
@@ -266,10 +265,7 @@ public CopyWriter copyTo(String targetBucket, BlobSourceOption... options) {
* @throws StorageException upon failure
*/
public CopyWriter copyTo(String targetBucket, String targetBlob, BlobSourceOption... options) {
- BlobInfo updatedInfo = BlobInfo.builder(targetBucket, targetBlob).build();
- CopyRequest copyRequest = CopyRequest.builder().source(info.bucket(), info.name())
- .sourceOptions(convert(info, options)).target(updatedInfo).build();
- return storage.copy(copyRequest);
+ return copyTo(BlobId.of(targetBucket, targetBlob), options);
}
/**
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
index 98698107a205..b35abbea8a88 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
@@ -555,27 +555,37 @@ public Builder sourceOptions(Iterable options) {
*
* @return the builder.
*/
- public Builder target(BlobInfo target) {
- this.target = target;
+ public Builder target(BlobId target) {
+ this.target = BlobInfo.builder(target).build();
return this;
}
/**
- * Sets blob's target options.
+ * Sets the copy target and target options. Copied blob metadata is set to {@code target}.
+ * This method throws an exception if target blob's content type is {@code null}.
*
* @return the builder.
+ * @throws IllegalArgumentException if {@code target.contentType} is {@code null}
*/
- public Builder targetOptions(BlobTargetOption... options) {
+ public Builder target(BlobInfo target, BlobTargetOption... options)
+ throws IllegalArgumentException {
+ checkContentType(target);
+ this.target = target;
Collections.addAll(targetOptions, options);
return this;
}
/**
- * Sets blob's target options.
+ * Sets the copy target and target options. Copied blob metadata is set to {@code target}.
+ * This method throws an exception if target blob's content type is {@code null}.
*
* @return the builder.
+ * @throws IllegalArgumentException if {@code target.contentType} is {@code null}
*/
- public Builder targetOptions(Iterable options) {
+ public Builder target(BlobInfo target, Iterable options)
+ throws IllegalArgumentException {
+ checkContentType(target);
+ this.target = target;
Iterables.addAll(targetOptions, options);
return this;
}
@@ -647,27 +657,101 @@ public Long megabytesCopiedPerChunk() {
return megabytesCopiedPerChunk;
}
- public static CopyRequest of(String sourceBucket, String sourceBlob, BlobInfo target) {
+ /**
+ * Creates a copy request. Copied blob metadata is set to {@code target}. This method throws an
+ * exception if target blob's content type is {@code null}.
+ *
+ * @param sourceBucket name of the bucket containing the source blob
+ * @param sourceBlob name of the source blob
+ * @param target a {@code BlobInfo} object for the target blob
+ * @return a copy request.
+ * @throws IllegalArgumentException if {@code target.contentType} is {@code null}
+ */
+ public static CopyRequest of(String sourceBucket, String sourceBlob, BlobInfo target)
+ throws IllegalArgumentException {
+ checkContentType(target);
return builder().source(sourceBucket, sourceBlob).target(target).build();
}
- public static CopyRequest of(BlobId sourceBlobId, BlobInfo target) {
+ /**
+ * Creates a copy request. Copied blob metadata is set to {@code target}. This method throws an
+ * exception if target blob's content type is {@code null}.
+ *
+ * @param sourceBlobId a {@code BlobId} object for the source blob
+ * @param target a {@code BlobInfo} object for the target blob
+ * @return a copy request.
+ * @throws IllegalArgumentException if {@code target.contentType} is {@code null}
+ */
+ public static CopyRequest of(BlobId sourceBlobId, BlobInfo target)
+ throws IllegalArgumentException {
+ checkContentType(target);
return builder().source(sourceBlobId).target(target).build();
}
+ /**
+ * Creates a copy request.
+ *
+ * @param sourceBucket name of the bucket containing both the source and the target blob
+ * @param sourceBlob name of the source blob
+ * @param targetBlob name of the target blob
+ * @return a copy request.
+ */
public static CopyRequest of(String sourceBucket, String sourceBlob, String targetBlob) {
- return of(sourceBucket, sourceBlob,
- BlobInfo.builder(BlobId.of(sourceBucket, targetBlob)).build());
+ return CopyRequest.builder()
+ .source(sourceBucket, sourceBlob)
+ .target(BlobId.of(sourceBucket, targetBlob))
+ .build();
+ }
+
+ /**
+ * Creates a copy request.
+ *
+ * @param sourceBucket name of the bucket containing the source blob
+ * @param sourceBlob name of the source blob
+ * @param target a {@code BlobId} object for the target blob
+ * @return a copy request.
+ */
+ public static CopyRequest of(String sourceBucket, String sourceBlob, BlobId target) {
+ return builder().source(sourceBucket, sourceBlob).target(target).build();
}
+ /**
+ * Creates a copy request.
+ *
+ * @param sourceBlobId a {@code BlobId} object for the source blob
+ * @param targetBlob name of the target blob, in the same bucket of the source blob
+ * @return a copy request.
+ */
public static CopyRequest of(BlobId sourceBlobId, String targetBlob) {
- return of(sourceBlobId,
- BlobInfo.builder(BlobId.of(sourceBlobId.bucket(), targetBlob)).build());
+ return CopyRequest.builder()
+ .source(sourceBlobId)
+ .target(BlobId.of(sourceBlobId.bucket(), targetBlob))
+ .build();
+ }
+
+ /**
+ * Creates a copy request.
+ *
+ * @param sourceBlobId a {@code BlobId} object for the source blob
+ * @param targetBlobId a {@code BlobId} object for the target blob
+ * @return a copy request.
+ */
+ public static CopyRequest of(BlobId sourceBlobId, BlobId targetBlobId) {
+ return CopyRequest.builder()
+ .source(sourceBlobId)
+ .target(targetBlobId)
+ .build();
}
public static Builder builder() {
return new Builder();
}
+
+ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentException {
+ if (blobInfo.contentType() == null) {
+ throw new IllegalArgumentException("Blob content type can not be null");
+ }
+ }
}
/**
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyRequestTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyRequestTest.java
new file mode 100644
index 000000000000..febd74feb095
--- /dev/null
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyRequestTest.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2015 Google Inc. All Rights Reserved.
+ *
+ * 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.gcloud.storage;
+
+import static com.google.gcloud.storage.Storage.PredefinedAcl.PUBLIC_READ;
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.ImmutableList;
+import com.google.gcloud.storage.Storage.BlobSourceOption;
+import com.google.gcloud.storage.Storage.BlobTargetOption;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class CopyRequestTest {
+
+ private static final String SOURCE_BUCKET_NAME = "b0";
+ private static final String SOURCE_BLOB_NAME = "o0";
+ private static final String TARGET_BUCKET_NAME = "b1";
+ private static final String TARGET_BLOB_NAME = "o1";
+ private static final String TARGET_BLOB_CONTENT_TYPE = "contentType";
+ private static final BlobId SOURCE_BLOB_ID = BlobId.of(SOURCE_BUCKET_NAME, SOURCE_BLOB_NAME);
+ private static final BlobId TARGET_BLOB_ID = BlobId.of(TARGET_BUCKET_NAME, TARGET_BLOB_NAME);
+ private static final BlobInfo TARGET_BLOB_INFO = BlobInfo.builder(TARGET_BLOB_ID)
+ .contentType(TARGET_BLOB_CONTENT_TYPE).build();
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void testCopyRequest() {
+ Storage.CopyRequest copyRequest1 = Storage.CopyRequest.builder()
+ .source(SOURCE_BLOB_ID)
+ .sourceOptions(BlobSourceOption.generationMatch(1))
+ .target(TARGET_BLOB_INFO, BlobTargetOption.predefinedAcl(PUBLIC_READ))
+ .build();
+ assertEquals(SOURCE_BLOB_ID, copyRequest1.source());
+ assertEquals(1, copyRequest1.sourceOptions().size());
+ assertEquals(BlobSourceOption.generationMatch(1), copyRequest1.sourceOptions().get(0));
+ assertEquals(TARGET_BLOB_INFO, copyRequest1.target());
+ assertEquals(1, copyRequest1.targetOptions().size());
+ assertEquals(BlobTargetOption.predefinedAcl(PUBLIC_READ), copyRequest1.targetOptions().get(0));
+
+ Storage.CopyRequest copyRequest2 = Storage.CopyRequest.builder()
+ .source(SOURCE_BUCKET_NAME, SOURCE_BLOB_NAME)
+ .target(TARGET_BLOB_ID)
+ .build();
+ assertEquals(SOURCE_BLOB_ID, copyRequest2.source());
+ assertEquals(BlobInfo.builder(TARGET_BLOB_ID).build(), copyRequest2.target());
+
+ Storage.CopyRequest copyRequest3 = Storage.CopyRequest.builder()
+ .source(SOURCE_BLOB_ID)
+ .target(TARGET_BLOB_INFO, ImmutableList.of(BlobTargetOption.predefinedAcl(PUBLIC_READ)))
+ .build();
+ assertEquals(SOURCE_BLOB_ID, copyRequest3.source());
+ assertEquals(TARGET_BLOB_INFO, copyRequest3.target());
+ assertEquals(ImmutableList.of(BlobTargetOption.predefinedAcl(PUBLIC_READ)),
+ copyRequest3.targetOptions());
+ }
+
+ @Test
+ public void testCopyRequestOf() {
+ Storage.CopyRequest copyRequest1 = Storage.CopyRequest.of(SOURCE_BLOB_ID, TARGET_BLOB_INFO);
+ assertEquals(SOURCE_BLOB_ID, copyRequest1.source());
+ assertEquals(TARGET_BLOB_INFO, copyRequest1.target());
+
+ Storage.CopyRequest copyRequest2 = Storage.CopyRequest.of(SOURCE_BLOB_ID, TARGET_BLOB_NAME);
+ assertEquals(SOURCE_BLOB_ID, copyRequest2.source());
+ assertEquals(BlobInfo.builder(SOURCE_BUCKET_NAME, TARGET_BLOB_NAME).build(),
+ copyRequest2.target());
+
+ Storage.CopyRequest copyRequest3 =
+ Storage.CopyRequest.of(SOURCE_BUCKET_NAME, SOURCE_BLOB_NAME, TARGET_BLOB_INFO);
+ assertEquals(SOURCE_BLOB_ID, copyRequest3.source());
+ assertEquals(TARGET_BLOB_INFO, copyRequest3.target());
+
+ Storage.CopyRequest copyRequest4 =
+ Storage.CopyRequest.of(SOURCE_BUCKET_NAME, SOURCE_BLOB_NAME, TARGET_BLOB_NAME);
+ assertEquals(SOURCE_BLOB_ID, copyRequest4.source());
+ assertEquals(BlobInfo.builder(SOURCE_BUCKET_NAME, TARGET_BLOB_NAME).build(),
+ copyRequest4.target());
+
+ Storage.CopyRequest copyRequest5 = Storage.CopyRequest.of(SOURCE_BLOB_ID, TARGET_BLOB_ID);
+ assertEquals(SOURCE_BLOB_ID, copyRequest5.source());
+ assertEquals(BlobInfo.builder(TARGET_BLOB_ID).build(), copyRequest5.target());
+
+ Storage.CopyRequest copyRequest6 =
+ Storage.CopyRequest.of(SOURCE_BUCKET_NAME, SOURCE_BLOB_NAME, TARGET_BLOB_ID);
+ assertEquals(SOURCE_BLOB_ID, copyRequest6.source());
+ assertEquals(BlobInfo.builder(TARGET_BLOB_ID).build(), copyRequest6.target());
+ }
+
+ @Test
+ public void testCopyRequestFail() {
+ thrown.expect(IllegalArgumentException.class);
+ Storage.CopyRequest.builder()
+ .source(SOURCE_BLOB_ID)
+ .target(BlobInfo.builder(TARGET_BLOB_ID).build())
+ .build();
+ }
+
+ @Test
+ public void testCopyRequestOfBlobInfoFail() {
+ thrown.expect(IllegalArgumentException.class);
+ Storage.CopyRequest.of(SOURCE_BLOB_ID, BlobInfo.builder(TARGET_BLOB_ID).build());
+ }
+
+ @Test
+ public void testCopyRequestOfStringFail() {
+ thrown.expect(IllegalArgumentException.class);
+ Storage.CopyRequest.of(
+ SOURCE_BUCKET_NAME, SOURCE_BLOB_NAME, BlobInfo.builder(TARGET_BLOB_ID).build());
+ }
+}
\ No newline at end of file
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
index 8957ed2b8364..3aad7b712e48 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/ITStorageTest.java
@@ -325,8 +325,7 @@ public void testCopyBlob() {
.build();
assertNotNull(storage.create(blob, BLOB_BYTE_CONTENT));
String targetBlobName = "test-copy-blob-target";
- BlobInfo target = BlobInfo.builder(BUCKET, targetBlobName).build();
- Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
+ Storage.CopyRequest req = Storage.CopyRequest.of(source, BlobId.of(BUCKET, targetBlobName));
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.result().bucket());
assertEquals(targetBlobName, copyWriter.result().name());
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
index 910d614c64d7..bdac54bcef2d 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/StorageImplTest.java
@@ -591,7 +591,7 @@ public void testComposeWithOptions() {
@Test
public void testCopy() {
- CopyRequest request = Storage.CopyRequest.of(BLOB_INFO1.blobId(), BLOB_INFO2);
+ CopyRequest request = Storage.CopyRequest.of(BLOB_INFO1.blobId(), BLOB_INFO2.blobId());
StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
EMPTY_RPC_OPTIONS, request.target().toPb(), EMPTY_RPC_OPTIONS, null);
StorageRpc.RewriteResponse rpcResponse = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
@@ -610,8 +610,7 @@ public void testCopyWithOptions() {
CopyRequest request = Storage.CopyRequest.builder()
.source(BLOB_INFO2.blobId())
.sourceOptions(BLOB_SOURCE_GENERATION, BLOB_SOURCE_METAGENERATION)
- .target(BLOB_INFO1)
- .targetOptions(BLOB_TARGET_GENERATION, BLOB_TARGET_METAGENERATION)
+ .target(BLOB_INFO1, BLOB_TARGET_GENERATION, BLOB_TARGET_METAGENERATION)
.build();
StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
BLOB_SOURCE_OPTIONS_COPY, request.target().toPb(), BLOB_TARGET_OPTIONS_COMPOSE, null);
@@ -628,7 +627,7 @@ public void testCopyWithOptions() {
@Test
public void testCopyMultipleRequests() {
- CopyRequest request = Storage.CopyRequest.of(BLOB_INFO1.blobId(), BLOB_INFO2);
+ CopyRequest request = Storage.CopyRequest.of(BLOB_INFO1.blobId(), BLOB_INFO2.blobId());
StorageRpc.RewriteRequest rpcRequest = new StorageRpc.RewriteRequest(request.source().toPb(),
EMPTY_RPC_OPTIONS, request.target().toPb(), EMPTY_RPC_OPTIONS, null);
StorageRpc.RewriteResponse rpcResponse1 = new StorageRpc.RewriteResponse(rpcRequest, null, 42L,
From 68b0a3d12ee70b3b6dbd70d60d134518c6c8501a Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Fri, 30 Oct 2015 09:20:32 +0100
Subject: [PATCH 034/322] Use checkArgument instead of throw, better javadoc
---
.../com/google/gcloud/storage/Storage.java | 34 ++++++++++---------
.../gcloud/storage/CopyRequestTest.java | 2 +-
2 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
index b35abbea8a88..9bc971a09dba 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
+++ b/gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java
@@ -551,7 +551,7 @@ public Builder sourceOptions(Iterable options) {
}
/**
- * Sets the copy target.
+ * Sets the copy target. Target blob information is copied from source.
*
* @return the builder.
*/
@@ -561,8 +561,9 @@ public Builder target(BlobId target) {
}
/**
- * Sets the copy target and target options. Copied blob metadata is set to {@code target}.
- * This method throws an exception if target blob's content type is {@code null}.
+ * Sets the copy target and target options. {@code target} parameter is used to override
+ * source blob information (e.g. {@code contentType}, {@code contentLanguage}). {@code
+ * target.contentType} is a required field.
*
* @return the builder.
* @throws IllegalArgumentException if {@code target.contentType} is {@code null}
@@ -576,8 +577,9 @@ public Builder target(BlobInfo target, BlobTargetOption... options)
}
/**
- * Sets the copy target and target options. Copied blob metadata is set to {@code target}.
- * This method throws an exception if target blob's content type is {@code null}.
+ * Sets the copy target and target options. {@code target} parameter is used to override
+ * source blob information (e.g. {@code contentType}, {@code contentLanguage}). {@code
+ * target.contentType} is a required field.
*
* @return the builder.
* @throws IllegalArgumentException if {@code target.contentType} is {@code null}
@@ -658,8 +660,9 @@ public Long megabytesCopiedPerChunk() {
}
/**
- * Creates a copy request. Copied blob metadata is set to {@code target}. This method throws an
- * exception if target blob's content type is {@code null}.
+ * Creates a copy request. {@code target} parameter is used to override source blob information
+ * (e.g. {@code contentType}, {@code contentLanguage}). {@code target.contentType} is a required
+ * field.
*
* @param sourceBucket name of the bucket containing the source blob
* @param sourceBlob name of the source blob
@@ -674,8 +677,9 @@ public static CopyRequest of(String sourceBucket, String sourceBlob, BlobInfo ta
}
/**
- * Creates a copy request. Copied blob metadata is set to {@code target}. This method throws an
- * exception if target blob's content type is {@code null}.
+ * Creates a copy request. {@code target} parameter is used to override source blob information
+ * (e.g. {@code contentType}, {@code contentLanguage}). {@code target.contentType} is a required
+ * field.
*
* @param sourceBlobId a {@code BlobId} object for the source blob
* @param target a {@code BlobInfo} object for the target blob
@@ -689,7 +693,7 @@ public static CopyRequest of(BlobId sourceBlobId, BlobInfo target)
}
/**
- * Creates a copy request.
+ * Creates a copy request. Target blob information is copied from source.
*
* @param sourceBucket name of the bucket containing both the source and the target blob
* @param sourceBlob name of the source blob
@@ -704,7 +708,7 @@ public static CopyRequest of(String sourceBucket, String sourceBlob, String targ
}
/**
- * Creates a copy request.
+ * Creates a copy request. Target blob information is copied from source.
*
* @param sourceBucket name of the bucket containing the source blob
* @param sourceBlob name of the source blob
@@ -716,7 +720,7 @@ public static CopyRequest of(String sourceBucket, String sourceBlob, BlobId targ
}
/**
- * Creates a copy request.
+ * Creates a copy request. Target blob information is copied from source.
*
* @param sourceBlobId a {@code BlobId} object for the source blob
* @param targetBlob name of the target blob, in the same bucket of the source blob
@@ -730,7 +734,7 @@ public static CopyRequest of(BlobId sourceBlobId, String targetBlob) {
}
/**
- * Creates a copy request.
+ * Creates a copy request. Target blob information is copied from source.
*
* @param sourceBlobId a {@code BlobId} object for the source blob
* @param targetBlobId a {@code BlobId} object for the target blob
@@ -748,9 +752,7 @@ public static Builder builder() {
}
private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentException {
- if (blobInfo.contentType() == null) {
- throw new IllegalArgumentException("Blob content type can not be null");
- }
+ checkArgument(blobInfo.contentType() != null, "Blob content type can not be null");
}
}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyRequestTest.java b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyRequestTest.java
index febd74feb095..b7e8d14e53a1 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyRequestTest.java
+++ b/gcloud-java-storage/src/test/java/com/google/gcloud/storage/CopyRequestTest.java
@@ -126,4 +126,4 @@ public void testCopyRequestOfStringFail() {
Storage.CopyRequest.of(
SOURCE_BUCKET_NAME, SOURCE_BLOB_NAME, BlobInfo.builder(TARGET_BLOB_ID).build());
}
-}
\ No newline at end of file
+}
From ea36a9e62f6179c557f7f788c37189f9aa3c107d Mon Sep 17 00:00:00 2001
From: Marco Ziccardi
Date: Tue, 3 Nov 2015 18:06:36 +0100
Subject: [PATCH 035/322] Rename ListResult and move to core module
---
.../main/java/com/google/gcloud/BasePage.java | 16 +++----
.../src/main/java/com/google/gcloud/Page.java | 10 ++---
.../java/com/google/gcloud/BasePageTest.java | 17 ++++----
.../{BlobListResult.java => BlobPage.java} | 17 ++++----
.../com/google/gcloud/storage/Bucket.java | 5 ++-
.../com/google/gcloud/storage/Storage.java | 5 ++-
.../google/gcloud/storage/StorageImpl.java | 20 +++++----
...bListResultTest.java => BlobPageTest.java} | 30 +++++++------
.../com/google/gcloud/storage/BucketTest.java | 14 +++---
.../gcloud/storage/RemoteGcsHelperTest.java | 13 +++---
.../gcloud/storage/SerializationTest.java | 5 ++-
.../gcloud/storage/StorageImplTest.java | 43 +++++++++----------
12 files changed, 103 insertions(+), 92 deletions(-)
rename gcloud-java-storage/src/main/java/com/google/gcloud/storage/BaseListResult.java => gcloud-java-core/src/main/java/com/google/gcloud/BasePage.java (79%)
rename gcloud-java-storage/src/main/java/com/google/gcloud/storage/ListResult.java => gcloud-java-core/src/main/java/com/google/gcloud/Page.java (75%)
rename gcloud-java-storage/src/test/java/com/google/gcloud/storage/BaseListResultTest.java => gcloud-java-core/src/test/java/com/google/gcloud/BasePageTest.java (69%)
rename gcloud-java-storage/src/main/java/com/google/gcloud/storage/{BlobListResult.java => BlobPage.java} (79%)
rename gcloud-java-storage/src/test/java/com/google/gcloud/storage/{BlobListResultTest.java => BlobPageTest.java} (77%)
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BaseListResult.java b/gcloud-java-core/src/main/java/com/google/gcloud/BasePage.java
similarity index 79%
rename from gcloud-java-storage/src/main/java/com/google/gcloud/storage/BaseListResult.java
rename to gcloud-java-core/src/main/java/com/google/gcloud/BasePage.java
index fdcd84705555..ce62b334a785 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/BaseListResult.java
+++ b/gcloud-java-core/src/main/java/com/google/gcloud/BasePage.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.google.gcloud.storage;
+package com.google.gcloud;
import java.io.Serializable;
import java.util.Collections;
@@ -22,9 +22,9 @@
import java.util.Objects;
/**
- * Base implementation for Google Cloud storage list result.
+ * Base implementation for Google Cloud paginated results.
*/
-public class BaseListResult implements ListResult, Serializable {
+public class BasePage implements Page, Serializable {
private static final long serialVersionUID = -6937287874908527950L;
@@ -33,10 +33,10 @@ public class BaseListResult implements ListResult, Se
private final NextPageFetcher pageFetcher;
public interface NextPageFetcher extends Serializable {
- ListResult nextPage();
+ Page nextPage();
}
- public BaseListResult(NextPageFetcher pageFetcher, String cursor, Iterable results) {
+ public BasePage(NextPageFetcher pageFetcher, String cursor, Iterable results) {
this.pageFetcher = pageFetcher;
this.cursor = cursor;
this.results = results;
@@ -48,7 +48,7 @@ public String nextPageCursor() {
}
@Override
- public ListResult nextPage() {
+ public Page nextPage() {
if (cursor == null || pageFetcher == null) {
return null;
}
@@ -67,10 +67,10 @@ public int hashCode() {
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof BaseListResult)) {
+ if (!(obj instanceof BasePage)) {
return false;
}
- BaseListResult> other = (BaseListResult>) obj;
+ BasePage> other = (BasePage>) obj;
return Objects.equals(cursor, other.cursor)
&& Objects.equals(results, other.results);
}
diff --git a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/ListResult.java b/gcloud-java-core/src/main/java/com/google/gcloud/Page.java
similarity index 75%
rename from gcloud-java-storage/src/main/java/com/google/gcloud/storage/ListResult.java
rename to gcloud-java-core/src/main/java/com/google/gcloud/Page.java
index 62b1f442310c..21d465bb79f9 100644
--- a/gcloud-java-storage/src/main/java/com/google/gcloud/storage/ListResult.java
+++ b/gcloud-java-core/src/main/java/com/google/gcloud/Page.java
@@ -14,12 +14,12 @@
* limitations under the License.
*/
-package com.google.gcloud.storage;
+package com.google.gcloud;
/**
- * Interface for Google Cloud storage list result.
+ * Interface for Google Cloud paginated results.
*/
-public interface ListResult extends Iterable {
+public interface Page extends Iterable {
/**
* Returns the cursor for the nextPage or {@code null} if no more results.
@@ -27,8 +27,8 @@ public interface ListResult extends Iterable {
String nextPageCursor();
/**
- * Returns the results of the nextPage or {@code null} if no more result.
+ * Returns the next page of results or {@code null} if no more result.
*/
- ListResult nextPage();
+ Page nextPage();
}
diff --git a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BaseListResultTest.java b/gcloud-java-core/src/test/java/com/google/gcloud/BasePageTest.java
similarity index 69%
rename from gcloud-java-storage/src/test/java/com/google/gcloud/storage/BaseListResultTest.java
rename to gcloud-java-core/src/test/java/com/google/gcloud/BasePageTest.java
index 4c22edbc35c8..888d7ace7ab0 100644
--- a/gcloud-java-storage/src/test/java/com/google/gcloud/storage/BaseListResultTest.java
+++ b/gcloud-java-core/src/test/java/com/google/gcloud/BasePageTest.java
@@ -14,31 +14,32 @@
* limitations under the License.
*/
-package com.google.gcloud.storage;
+package com.google.gcloud;
import static org.junit.Assert.assertEquals;
import com.google.common.collect.ImmutableList;
+import com.google.gcloud.BasePage;
import org.junit.Test;
import java.util.Collections;
-public class BaseListResultTest {
+public class BasePageTest {
@Test
- public void testListResult() throws Exception {
+ public void testPage() throws Exception {
ImmutableList values = ImmutableList.of("1", "2");
- final BaseListResult