File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
samples/snippets/src/test/java/com/google/datastore/snippets Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -1145,4 +1145,31 @@ public void testInQuerySorted() {
11451145 // [END datastore_in_query_sorted]
11461146 assertValidQueryRealBackend (query );
11471147 }
1148+
1149+ @ Test
1150+ public void testStaleReads () {
1151+ setUpQueryTestsRealBackend ();
1152+ Datastore datastoreClient = datastoreRealBackend ;
1153+ // [START datastore_stale_read]
1154+ Key taskKey =
1155+ datastoreClient
1156+ .newKeyFactory ()
1157+ .setKind ("Task" )
1158+ .addAncestors (PathElement .of ("TaskList" , "default" ))
1159+ .newKey ("someTask" );
1160+
1161+ Timestamp fifteenSecondsAgo =
1162+ Timestamp .ofTimeSecondsAndNanos (Timestamp .now ().getSeconds () - 15L , 0 );
1163+ // Create a readOption with read time fifteenSecondsAgo
1164+ ReadOption readOption = ReadOption .readTime (fifteenSecondsAgo );
1165+ // Use the readOption to Fetch entity
1166+ Entity entity = datastoreClient .get (taskKey , readOption );
1167+
1168+ // Use the readOption to Query kind Task
1169+ Query <Entity > query = Query .newEntityQueryBuilder ().setKind ("Task" ).setLimit (10 ).build ();
1170+ QueryResults <Entity > results = datastoreClient .run (query , readOption );
1171+ Entity result = results .next ();
1172+ // [END datastore_stale_read]
1173+ assertValidQueryRealBackend (query );
1174+ }
11481175}
You can’t perform that action at this time.
0 commit comments