1
- /**
1
+ /*
2
2
* Copyright 2015 Google Inc. All Rights Reserved.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
+
16
17
package com .google .appengine .samples ;
17
18
18
19
// [START LocalCustomPolicyHighRepDatastoreTest]
19
20
20
- import com .google .appengine .api .datastore .*;
21
+ import static com .google .appengine .api .datastore .FetchOptions .Builder .withLimit ;
22
+ import static org .junit .Assert .assertEquals ;
23
+
24
+ import com .google .appengine .api .datastore .DatastoreService ;
25
+ import com .google .appengine .api .datastore .DatastoreServiceFactory ;
26
+ import com .google .appengine .api .datastore .Entity ;
27
+ import com .google .appengine .api .datastore .Key ;
28
+ import com .google .appengine .api .datastore .Query ;
21
29
import com .google .appengine .api .datastore .dev .HighRepJobPolicy ;
22
30
import com .google .appengine .tools .development .testing .LocalDatastoreServiceTestConfig ;
23
31
import com .google .appengine .tools .development .testing .LocalServiceTestHelper ;
32
+
24
33
import org .junit .After ;
25
34
import org .junit .Before ;
26
35
import org .junit .Test ;
27
36
28
- import static com .google .appengine .api .datastore .FetchOptions .Builder .withLimit ;
29
- import static org .junit .Assert .assertEquals ;
30
-
31
37
public class LocalCustomPolicyHighRepDatastoreTest {
32
38
private static final class CustomHighRepJobPolicy implements HighRepJobPolicy {
33
39
static int newJobCounter = 0 ;
34
40
static int existingJobCounter = 0 ;
35
41
36
42
@ Override
37
43
public boolean shouldApplyNewJob (Key entityGroup ) {
38
- // every other new job fails to apply
44
+ // Every other new job fails to apply.
39
45
return newJobCounter ++ % 2 == 0 ;
40
46
}
41
47
42
48
@ Override
43
49
public boolean shouldRollForwardExistingJob (Key entityGroup ) {
44
- // every other existing job fails to apply
50
+ // Every other existing job fails to apply.
45
51
return existingJobCounter ++ % 2 == 0 ;
46
52
}
47
53
}
@@ -65,10 +71,10 @@ public void testEventuallyConsistentGlobalQueryResult() {
65
71
DatastoreService ds = DatastoreServiceFactory .getDatastoreService ();
66
72
ds .put (new Entity ("yam" )); // applies
67
73
ds .put (new Entity ("yam" )); // does not apply
68
- // first global query only sees the first Entity
74
+ // First global query only sees the first Entity.
69
75
assertEquals (1 , ds .prepare (new Query ("yam" )).countEntities (withLimit (10 )));
70
- // second global query sees both Entities because we "groom" (attempt to
71
- // apply unapplied jobs) after every query
76
+ // Second global query sees both Entities because we "groom" (attempt to
77
+ // apply unapplied jobs) after every query.
72
78
assertEquals (2 , ds .prepare (new Query ("yam" )).countEntities (withLimit (10 )));
73
79
}
74
80
}
0 commit comments