Skip to content

Commit 92a8e72

Browse files
committed
---
yaml --- r: 2691 b: refs/heads/update-datastore c: e737516 h: refs/heads/master i: 2689: 140b1ed 2687: 6a172f8
1 parent 1a1151c commit 92a8e72

8 files changed

Lines changed: 67 additions & 13 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
66
refs/heads/pubsub-alpha: 1a0e970f265af871e02274085b9662b3fe29058b
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
8-
refs/heads/update-datastore: b0d4c57e2b44b97b79c0dc50f54655849199d8e7
8+
refs/heads/update-datastore: e7375169fde04db0613cb88dd843f5b45d19395a
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
1010
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd
1111
refs/tags/v0.0.11: ffbfba48a6426ff63c08ff2117e58681f251fbf2

branches/update-datastore/CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ End-to-end tests should ensure that gcloud-java works when running on the
3030

3131
When changes are made to authentication and project ID-related code, authentication and project ID inference should be tested using all relevant methods detailed in the [authentication docs](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) and [project ID docs](https://github.com/GoogleCloudPlatform/gcloud-java#specifying-a-project-id).
3232

33+
Known issue: If you have installed the Google Cloud SDK, be sure to log in (using `gcloud auth login`) before running tests. Though the Datastore tests use a local Datastore emulator that doesn't require authentication, they will not run if you have the Google Cloud SDK installed but aren't authenticated.
34+
3335
Adding Features
3436
---------------
3537
In order to add a feature to gcloud-java:

branches/update-datastore/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DatastoreRpc.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ public int httpStatus() {
7979
private final int httpStatus;
8080
private final boolean retryable;
8181

82-
public DatastoreRpcException(Reason reason) {
83-
this(reason.name(), reason.httpStatus, reason.retryable, reason.description);
82+
public DatastoreRpcException(Reason reason, Throwable cause) {
83+
this(reason.name(), reason.httpStatus, reason.retryable, reason.description, cause);
8484
}
8585

86-
public DatastoreRpcException(String reason, int httpStatus, boolean retryable, String message) {
87-
super(message);
86+
public DatastoreRpcException(String reason, int httpStatus, boolean retryable, String message, Throwable cause) {
87+
super(message, cause);
8888
this.reason = reason;
8989
this.httpStatus = httpStatus;
9090
this.retryable = retryable;

branches/update-datastore/gcloud-java-datastore/src/main/java/com/google/gcloud/spi/DefaultDatastoreRpc.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ private static DatastoreRpcException translate(DatastoreException exception) {
124124
reason = HTTP_STATUS_TO_REASON.get(exception.getCode());
125125
}
126126
if (reason != null) {
127-
return new DatastoreRpcException(reason);
127+
return new DatastoreRpcException(reason, exception);
128128
} else {
129129
boolean retryable = false;
130130
reasonStr = "Unknown";
131131
if (exception.getCause() instanceof SocketTimeoutException) {
132132
retryable = true;
133133
reasonStr = "Request timeout";
134134
}
135-
return new DatastoreRpcException(reasonStr, exception.getCode(), retryable, message);
135+
return new DatastoreRpcException(reasonStr, exception.getCode(), retryable, message, exception);
136136
}
137137
}
138138

branches/update-datastore/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreExceptionTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ public void testDatastoreError() throws Exception {
4242

4343
@Test
4444
public void testTranslateAndThrow() throws Exception {
45+
DatastoreRpcException toTranslate = null; // should be preserved as a cause
4546
for (Reason reason : Reason.values()) {
4647
try {
47-
DatastoreException.translateAndThrow(new DatastoreRpcException(reason));
48+
toTranslate = new DatastoreRpcException(reason, null);
49+
DatastoreException.translateAndThrow(toTranslate);
4850
fail("Exception expected");
4951
} catch (DatastoreException ex) {
5052
assertEquals(reason.name(), ex.datastoreError().name());
53+
assertEquals(toTranslate, ex.getCause());
5154
}
5255
}
5356
}

branches/update-datastore/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ public void testRetryableException() throws Exception {
735735
EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(DatastoreOptions.class)))
736736
.andReturn(rpcMock);
737737
EasyMock.expect(rpcMock.lookup(requestPb))
738-
.andThrow(new DatastoreRpc.DatastoreRpcException(Reason.UNAVAILABLE))
738+
.andThrow(new DatastoreRpc.DatastoreRpcException(Reason.UNAVAILABLE, null))
739739
.andReturn(responsePb);
740740
EasyMock.replay(rpcFactoryMock, rpcMock);
741741
DatastoreOptions options = this.options.toBuilder()
@@ -757,7 +757,7 @@ public void testNonRetryableException() throws Exception {
757757
EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(DatastoreOptions.class)))
758758
.andReturn(rpcMock);
759759
EasyMock.expect(rpcMock.lookup(requestPb))
760-
.andThrow(new DatastoreRpc.DatastoreRpcException(Reason.PERMISSION_DENIED))
760+
.andThrow(new DatastoreRpc.DatastoreRpcException(Reason.PERMISSION_DENIED, null))
761761
.times(1);
762762
EasyMock.replay(rpcFactoryMock, rpcMock);
763763
RetryParams retryParams = RetryParams.builder().retryMinAttempts(2).build();

branches/update-datastore/gcloud-java-storage/src/main/java/com/google/gcloud/storage/testing/RemoteGcsHelper.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ public StorageOptions options() {
6565

6666
/**
6767
* Deletes a bucket, even if non-empty. Objects in the bucket are listed and deleted until bucket
68-
* deletion succeeds or {@code timeout} expires.
68+
* deletion succeeds or {@code timeout} expires. To allow for the timeout, this method uses a
69+
* separate thread to send the delete requests. Use
70+
* {@link #forceDelete(Storage storage, String bucket)} if spawning an additional thread is
71+
* undesirable, such as in the App Engine production runtime.
6972
*
7073
* @param storage the storage service to be used to issue requests
7174
* @param bucket the bucket to be deleted
@@ -88,6 +91,17 @@ public static Boolean forceDelete(Storage storage, String bucket, long timeout,
8891
}
8992
}
9093

94+
/**
95+
* Deletes a bucket, even if non-empty. This method blocks until the deletion completes or fails.
96+
*
97+
* @param storage the storage service to be used to issue requests
98+
* @param bucket the bucket to be deleted
99+
* @throws StorageException if an exception is encountered during bucket deletion
100+
*/
101+
public static void forceDelete(Storage storage, String bucket) {
102+
new DeleteBucketTask(storage, bucket).call();
103+
}
104+
91105
/**
92106
* Returns a bucket name generated using a random UUID.
93107
*/
@@ -157,7 +171,7 @@ public DeleteBucketTask(Storage storage, String bucket) {
157171
}
158172

159173
@Override
160-
public Boolean call() throws Exception {
174+
public Boolean call() {
161175
while (true) {
162176
for (BlobInfo info : storage.list(bucket).values()) {
163177
storage.delete(bucket, info.name());
@@ -167,7 +181,12 @@ public Boolean call() throws Exception {
167181
return true;
168182
} catch (StorageException e) {
169183
if (e.code() == 409) {
170-
Thread.sleep(500);
184+
try {
185+
Thread.sleep(500);
186+
} catch (InterruptedException interruptedException) {
187+
Thread.currentThread().interrupt();
188+
throw e;
189+
}
171190
} else {
172191
throw e;
173192
}

branches/update-datastore/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,36 @@ public void testForceDeleteFail() throws InterruptedException, ExecutionExceptio
140140
}
141141
}
142142

143+
@Test
144+
public void testForceDeleteNoTimeout() {
145+
Storage storageMock = EasyMock.createMock(Storage.class);
146+
EasyMock.expect(storageMock.list(BUCKET_NAME)).andReturn(BLOB_PAGE);
147+
for (BlobInfo info : BLOB_LIST) {
148+
EasyMock.expect(storageMock.delete(BUCKET_NAME, info.name())).andReturn(true);
149+
}
150+
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andReturn(true);
151+
EasyMock.replay(storageMock);
152+
RemoteGcsHelper.forceDelete(storageMock, BUCKET_NAME);
153+
EasyMock.verify(storageMock);
154+
}
155+
156+
@Test
157+
public void testForceDeleteNoTimeoutFail() {
158+
Storage storageMock = EasyMock.createMock(Storage.class);
159+
EasyMock.expect(storageMock.list(BUCKET_NAME)).andReturn(BLOB_PAGE);
160+
for (BlobInfo info : BLOB_LIST) {
161+
EasyMock.expect(storageMock.delete(BUCKET_NAME, info.name())).andReturn(true);
162+
}
163+
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION);
164+
EasyMock.replay(storageMock);
165+
thrown.expect(StorageException.class);
166+
try {
167+
RemoteGcsHelper.forceDelete(storageMock, BUCKET_NAME);
168+
} finally {
169+
EasyMock.verify(storageMock);
170+
}
171+
}
172+
143173
@Test
144174
public void testCreateFromStream() {
145175
RemoteGcsHelper helper = RemoteGcsHelper.create(PROJECT_ID, JSON_KEY_STREAM);

0 commit comments

Comments
 (0)