Skip to content

Commit

Permalink
Fix ServiceOptions merge bug, remove unnecessary protected modifier f…
Browse files Browse the repository at this point in the history
…rom DateTime, set cursorAfter to endCursor where appropriate, and fix error codes for retries.
  • Loading branch information
Ajay Kannan committed Feb 2, 2016
1 parent fbe5a1d commit d9590ea
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
Expand Down Expand Up @@ -229,8 +228,7 @@ public B clock(Clock clock) {
* @return the builder
*/
public B projectId(String projectId) {
this.projectId =
checkNotNull(projectId, "Project ID cannot be set to null. Leave unset for default.");
this.projectId = projectId;
return self();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public class DatastoreException extends BaseServiceException {

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

public DatastoreException(int code, String message, String reason, Throwable cause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
com.google.protobuf.Timestamp.parseFrom(bytesPb)));
}

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

protected static com.google.protobuf.Timestamp microsecondsToTimestampPb(long microseconds) {
static com.google.protobuf.Timestamp microsecondsToTimestampPb(long microseconds) {
long seconds = microseconds / 1000000;
int nanos = (int) (microseconds % 1000000) * 1000;
return com.google.protobuf.Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ protected T computeNext() {
sendRequest();
}
if (!entityResultPbIter.hasNext()) {
cursor = runQueryResponsePb.getBatch().getEndCursor();
return endOfData();
}
com.google.datastore.v1beta3.EntityResult entityResultPb = entityResultPbIter.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ public void testRetryableException() throws Exception {
EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(DatastoreOptions.class)))
.andReturn(rpcMock);
EasyMock.expect(rpcMock.lookup(requestPb))
.andThrow(new DatastoreException(503, "UNAVAILABLE", "UNAVAILABLE", null))
.andThrow(new DatastoreException(14, "UNAVAILABLE", "UNAVAILABLE", null))
.andReturn(responsePb);
EasyMock.replay(rpcFactoryMock, rpcMock);
DatastoreOptions options = this.options.toBuilder()
Expand Down

0 comments on commit d9590ea

Please sign in to comment.