Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1145,4 +1145,31 @@ public void testInQuerySorted() {
// [END datastore_in_query_sorted]
assertValidQueryRealBackend(query);
}

@Test
public void testStaleReads() {
setUpQueryTestsRealBackend();
Datastore datastoreClient = datastoreRealBackend;
// [START datastore_stale_read]
Key taskKey =
datastoreClient
.newKeyFactory()
.setKind("Task")
.addAncestors(PathElement.of("TaskList", "default"))
.newKey("someTask");

Timestamp fifteenSecondsAgo =
Timestamp.ofTimeSecondsAndNanos(Timestamp.now().getSeconds() - 15L, 0);
// Create a readOption with read time fifteenSecondsAgo
ReadOption readOption = ReadOption.readTime(fifteenSecondsAgo);
// Use the readOption to Fetch entity
Entity entity = datastoreClient.get(taskKey, readOption);

// Use the readOption to Query kind Task
Query<Entity> query = Query.newEntityQueryBuilder().setKind("Task").setLimit(10).build();
QueryResults<Entity> results = datastoreClient.run(query, readOption);
Entity result = results.next();
// [END datastore_stale_read]
assertValidQueryRealBackend(query);
}
}