-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support readTime in Datastore query splitter. (#763)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](/~https://github.com/googleapis/java-datastore/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( /~https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
- Loading branch information
1 parent
7358aa3
commit 61758e0
Showing
8 changed files
with
568 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- see http://mojo.codehaus.org/clirr-maven-plugin/examples/ignored-differences.html --> | ||
<differences> | ||
<difference> | ||
<className>com/google/datastore/v1/client/QuerySplitter</className> | ||
<method>java.util.List getSplits(com.google.datastore.v1.Query, com.google.datastore.v1.PartitionId, int, com.google.datastore.v1.client.Datastore, com.google.protobuf.Timestamp)</method> | ||
<differenceType>7012</differenceType> | ||
</difference> | ||
</differences> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...-v1-proto-client/src/main/java/com/google/datastore/v1/client/testing/MockCredential.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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.datastore.v1.client.testing; | ||
|
||
import com.google.api.client.auth.oauth2.Credential; | ||
import com.google.api.client.http.HttpRequest; | ||
import java.io.IOException; | ||
|
||
/** Fake credential used for testing purpose. */ | ||
public class MockCredential extends Credential { | ||
public MockCredential() { | ||
super( | ||
new AccessMethod() { | ||
@Override | ||
public void intercept(HttpRequest request, String accessToken) throws IOException {} | ||
|
||
@Override | ||
public String getAccessTokenFromRequest(HttpRequest request) { | ||
return "MockAccessToken"; | ||
} | ||
}); | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
...oto-client/src/main/java/com/google/datastore/v1/client/testing/MockDatastoreFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* 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.datastore.v1.client.testing; | ||
|
||
import static com.google.common.base.Preconditions.checkState; | ||
|
||
import com.google.api.client.auth.oauth2.Credential; | ||
import com.google.api.client.http.GenericUrl; | ||
import com.google.api.client.http.HttpRequestFactory; | ||
import com.google.api.client.http.HttpStatusCodes; | ||
import com.google.api.client.http.HttpTransport; | ||
import com.google.api.client.http.LowLevelHttpRequest; | ||
import com.google.api.client.http.LowLevelHttpResponse; | ||
import com.google.api.client.testing.http.MockHttpTransport; | ||
import com.google.api.client.testing.http.MockLowLevelHttpRequest; | ||
import com.google.api.client.testing.http.MockLowLevelHttpResponse; | ||
import com.google.api.client.testing.util.TestableByteArrayInputStream; | ||
import com.google.common.collect.Iterables; | ||
import com.google.datastore.v1.client.DatastoreFactory; | ||
import com.google.datastore.v1.client.DatastoreOptions; | ||
import com.google.protobuf.Message; | ||
import com.google.rpc.Code; | ||
import com.google.rpc.Status; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** Fake Datastore factory used for testing purposes when a true Datastore service is not needed. */ | ||
public class MockDatastoreFactory extends DatastoreFactory { | ||
private int nextStatus; | ||
private Message nextResponse; | ||
private Status nextError; | ||
private IOException nextException; | ||
|
||
private String lastPath; | ||
private String lastMimeType; | ||
private byte[] lastBody; | ||
private List<String> lastCookies; | ||
private String lastApiFormatHeaderValue; | ||
|
||
public void setNextResponse(Message response) { | ||
nextStatus = HttpStatusCodes.STATUS_CODE_OK; | ||
nextResponse = response; | ||
nextError = null; | ||
nextException = null; | ||
} | ||
|
||
public void setNextError(int status, Code code, String message) { | ||
nextStatus = status; | ||
nextResponse = null; | ||
nextError = makeErrorContent(message, code); | ||
nextException = null; | ||
} | ||
|
||
public void setNextException(IOException exception) { | ||
nextStatus = 0; | ||
nextResponse = null; | ||
nextError = null; | ||
nextException = exception; | ||
} | ||
|
||
@Override | ||
public HttpRequestFactory makeClient(DatastoreOptions options) { | ||
HttpTransport transport = | ||
new MockHttpTransport() { | ||
@Override | ||
public LowLevelHttpRequest buildRequest(String method, String url) { | ||
return new MockLowLevelHttpRequest(url) { | ||
@Override | ||
public LowLevelHttpResponse execute() throws IOException { | ||
lastPath = new GenericUrl(getUrl()).getRawPath(); | ||
lastMimeType = getContentType(); | ||
lastCookies = getHeaderValues("Cookie"); | ||
lastApiFormatHeaderValue = | ||
Iterables.getOnlyElement(getHeaderValues("X-Goog-Api-Format-Version")); | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
getStreamingContent().writeTo(out); | ||
lastBody = out.toByteArray(); | ||
if (nextException != null) { | ||
throw nextException; | ||
} | ||
MockLowLevelHttpResponse response = | ||
new MockLowLevelHttpResponse() | ||
.setStatusCode(nextStatus) | ||
.setContentType("application/x-protobuf"); | ||
if (nextError != null) { | ||
checkState(nextResponse == null); | ||
response.setContent(new TestableByteArrayInputStream(nextError.toByteArray())); | ||
} else { | ||
response.setContent(new TestableByteArrayInputStream(nextResponse.toByteArray())); | ||
} | ||
return response; | ||
} | ||
}; | ||
} | ||
}; | ||
Credential credential = options.getCredential(); | ||
return transport.createRequestFactory(credential); | ||
} | ||
|
||
public String getLastPath() { | ||
return lastPath; | ||
} | ||
|
||
public String getLastMimeType() { | ||
return lastMimeType; | ||
} | ||
|
||
public String getLastApiFormatHeaderValue() { | ||
return lastApiFormatHeaderValue; | ||
} | ||
|
||
public byte[] getLastBody() { | ||
return lastBody; | ||
} | ||
|
||
public List<String> getLastCookies() { | ||
return lastCookies; | ||
} | ||
|
||
private static Status makeErrorContent(String message, Code code) { | ||
return Status.newBuilder().setCode(code.getNumber()).setMessage(message).build(); | ||
} | ||
} |
Oops, something went wrong.