Skip to content

Commit d27d567

Browse files
author
Ajay Kannan
committed
Fix ServiceOptions merge bug, remove unnecessary protected modifier from DateTime, set cursorAfter to endCursor where appropriate, and fix error codes for retries.
1 parent fbe5a1d commit d27d567

6 files changed

Lines changed: 16 additions & 19 deletions

File tree

gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import static com.google.common.base.MoreObjects.firstNonNull;
2020
import static com.google.common.base.Preconditions.checkArgument;
21-
import static com.google.common.base.Preconditions.checkNotNull;
2221
import static java.nio.charset.StandardCharsets.UTF_8;
2322

2423
import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
@@ -229,8 +228,7 @@ public B clock(Clock clock) {
229228
* @return the builder
230229
*/
231230
public B projectId(String projectId) {
232-
this.projectId =
233-
checkNotNull(projectId, "Project ID cannot be set to null. Leave unset for default.");
231+
this.projectId = projectId;
234232
return self();
235233
}
236234

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreException.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public class DatastoreException extends BaseServiceException {
3434

3535
// see https://cloud.google.com/datastore/docs/concepts/errors#Error_Codes"
3636
private static final Set<Error> RETRYABLE_ERRORS = ImmutableSet.of(
37-
new Error(409, "ABORTED"),
38-
new Error(403, "DEADLINE_EXCEEDED"),
39-
new Error(503, "UNAVAILABLE"));
37+
new Error(10, "ABORTED"), new Error(4, "DEADLINE_EXCEEDED"), new Error(14, "UNAVAILABLE"));
4038
private static final long serialVersionUID = 2663750991205874435L;
4139

4240
public DatastoreException(int code, String message, String reason, Throwable cause) {

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DateTime.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
106106
com.google.protobuf.Timestamp.parseFrom(bytesPb)));
107107
}
108108

109-
protected static long timestampPbToMicroseconds(com.google.protobuf.Timestamp timestampPb) {
109+
static long timestampPbToMicroseconds(com.google.protobuf.Timestamp timestampPb) {
110110
return timestampPb.getSeconds() * 1000000 + timestampPb.getNanos() / 1000;
111111
}
112112

113-
protected static com.google.protobuf.Timestamp microsecondsToTimestampPb(long microseconds) {
113+
static com.google.protobuf.Timestamp microsecondsToTimestampPb(long microseconds) {
114114
long seconds = microseconds / 1000000;
115115
int nanos = (int) (microseconds % 1000000) * 1000;
116116
return com.google.protobuf.Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/QueryResultsImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected T computeNext() {
9393
sendRequest();
9494
}
9595
if (!entityResultPbIter.hasNext()) {
96+
cursor = runQueryResponsePb.getBatch().getEndCursor();
9697
return endOfData();
9798
}
9899
com.google.datastore.v1beta3.EntityResult entityResultPb = entityResultPbIter.next();

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,29 @@ public class DatastoreExceptionTest {
3838

3939
@Test
4040
public void testDatastoreException() throws Exception {
41-
DatastoreException exception = new DatastoreException(409, "message", "ABORTED");
42-
assertEquals(409, exception.code());
41+
DatastoreException exception = new DatastoreException(10, "message", "ABORTED");
42+
assertEquals(10, exception.code());
4343
assertEquals("ABORTED", exception.reason());
4444
assertEquals("message", exception.getMessage());
4545
assertTrue(exception.retryable());
4646
assertTrue(exception.idempotent());
4747

48-
exception = new DatastoreException(403, "message", "DEADLINE_EXCEEDED");
49-
assertEquals(403, exception.code());
48+
exception = new DatastoreException(4, "message", "DEADLINE_EXCEEDED");
49+
assertEquals(4, exception.code());
5050
assertEquals("DEADLINE_EXCEEDED", exception.reason());
5151
assertEquals("message", exception.getMessage());
5252
assertTrue(exception.retryable());
5353
assertTrue(exception.idempotent());
5454

55-
exception = new DatastoreException(503, "message", "UNAVAILABLE");
56-
assertEquals(503, exception.code());
55+
exception = new DatastoreException(14, "message", "UNAVAILABLE");
56+
assertEquals(14, exception.code());
5757
assertEquals("UNAVAILABLE", exception.reason());
5858
assertEquals("message", exception.getMessage());
5959
assertTrue(exception.retryable());
6060
assertTrue(exception.idempotent());
6161

62-
exception = new DatastoreException(500, "message", "INTERNAL");
63-
assertEquals(500, exception.code());
62+
exception = new DatastoreException(2, "message", "INTERNAL");
63+
assertEquals(2, exception.code());
6464
assertEquals("INTERNAL", exception.reason());
6565
assertEquals("message", exception.getMessage());
6666
assertFalse(exception.retryable());
@@ -77,14 +77,14 @@ public void testDatastoreException() throws Exception {
7777

7878
@Test
7979
public void testTranslateAndThrow() throws Exception {
80-
DatastoreException cause = new DatastoreException(503, "message", "UNAVAILABLE");
80+
DatastoreException cause = new DatastoreException(14, "message", "UNAVAILABLE");
8181
RetryHelper.RetryHelperException exceptionMock = createMock(RetryHelper.RetryHelperException.class);
8282
expect(exceptionMock.getCause()).andReturn(cause).times(2);
8383
replay(exceptionMock);
8484
try {
8585
DatastoreException.translateAndThrow(exceptionMock);
8686
} catch (BaseServiceException ex) {
87-
assertEquals(503, ex.code());
87+
assertEquals(14, ex.code());
8888
assertEquals("message", ex.getMessage());
8989
assertTrue(ex.retryable());
9090
assertTrue(ex.idempotent());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ public void testRetryableException() throws Exception {
986986
EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(DatastoreOptions.class)))
987987
.andReturn(rpcMock);
988988
EasyMock.expect(rpcMock.lookup(requestPb))
989-
.andThrow(new DatastoreException(503, "UNAVAILABLE", "UNAVAILABLE", null))
989+
.andThrow(new DatastoreException(14, "UNAVAILABLE", "UNAVAILABLE", null))
990990
.andReturn(responsePb);
991991
EasyMock.replay(rpcFactoryMock, rpcMock);
992992
DatastoreOptions options = this.options.toBuilder()

0 commit comments

Comments
 (0)