|
@@ -18,152 +18,163 @@ |
18 |
18 |
|
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig; |
19 |
19 |
|
import com.google.appengine.tools.development.testing.LocalServiceTestHelper; |
20 |
20 |
|
|
21 |
|
- |
public class DatastoreServiceTest extends TestCase { |
22 |
|
- |
private final LocalServiceTestHelper mHelper = new LocalServiceTestHelper( |
23 |
|
- |
new LocalDatastoreServiceTestConfig()); |
|
21 |
+ |
public class DatastoreServiceTest extends TestCase |
|
22 |
+ |
{ |
|
23 |
+ |
private final LocalServiceTestHelper mHelper = new LocalServiceTestHelper( new LocalDatastoreServiceTestConfig() ); |
24 |
24 |
|
|
25 |
|
- |
public static TestSuite suite() { |
26 |
|
- |
return new TestSuite(DatastoreServiceTest.class); |
|
25 |
+ |
public static TestSuite suite() |
|
26 |
+ |
{ |
|
27 |
+ |
return new TestSuite( DatastoreServiceTest.class ); |
27 |
28 |
|
} |
28 |
29 |
|
|
29 |
|
- |
public DatastoreServiceTest(String name) { |
30 |
|
- |
super(name); |
|
30 |
+ |
public DatastoreServiceTest( String name ) |
|
31 |
+ |
{ |
|
32 |
+ |
super( name ); |
31 |
33 |
|
} |
32 |
34 |
|
|
33 |
|
- |
public static void main(String[] args) { |
34 |
|
- |
junit.textui.TestRunner.run(suite()); |
|
35 |
+ |
public static void main( String[] args ) |
|
36 |
+ |
{ |
|
37 |
+ |
junit.textui.TestRunner.run( suite() ); |
35 |
38 |
|
} |
36 |
39 |
|
|
37 |
40 |
|
@Override |
38 |
|
- |
protected void setUp() throws Exception { |
|
41 |
+ |
protected void setUp() throws Exception |
|
42 |
+ |
{ |
39 |
43 |
|
super.setUp(); |
40 |
44 |
|
mHelper.setUp(); |
41 |
45 |
|
mConfig = DatastoreServiceConfig.Builder.withDefaults() // Deadline=null, |
42 |
|
- |
// ImplicitTransactionManagementPolicy=NONE, |
43 |
|
- |
// ReadPolicy.Consistency=STRONG |
44 |
|
- |
.deadline(5); // Deadline=5 secs |
45 |
|
- |
mDatastoreService = DatastoreServiceFactory |
46 |
|
- |
.getDatastoreService(mConfig); |
47 |
|
- |
mGOD_Apollo = KeyFactory.createKey("GODS", "Apollo"); |
48 |
|
- |
mGOD_Venus = KeyFactory.createKey("GODS", "Venus"); |
|
46 |
+ |
// ImplicitTransactionManagementPolicy=NONE, |
|
47 |
+ |
// ReadPolicy.Consistency=STRONG |
|
48 |
+ |
.deadline( 5 ); // Deadline=5 secs |
|
49 |
+ |
mDatastoreService = DatastoreServiceFactory.getDatastoreService( mConfig ); |
|
50 |
+ |
mGOD_Apollo = KeyFactory.createKey( "GODS", "Apollo" ); |
|
51 |
+ |
mGOD_Venus = KeyFactory.createKey( "GODS", "Venus" ); |
49 |
52 |
|
|
50 |
53 |
|
} |
51 |
54 |
|
|
52 |
55 |
|
@Override |
53 |
|
- |
public void tearDown() { |
|
56 |
+ |
public void tearDown() |
|
57 |
+ |
{ |
54 |
58 |
|
mHelper.tearDown(); |
55 |
59 |
|
} |
56 |
60 |
|
|
57 |
61 |
|
private DatastoreServiceConfig mConfig; |
|
62 |
+ |
|
58 |
63 |
|
private DatastoreService mDatastoreService; |
|
64 |
+ |
|
59 |
65 |
|
private Key mGOD_Apollo, mGOD_Venus; |
60 |
66 |
|
|
61 |
|
- |
private Entity createEntity(Key pGOD, String pName) { |
62 |
|
- |
Entity zEntity = new Entity("TheFlintstones", pName, pGOD); |
63 |
|
- |
zEntity.setUnindexedProperty("Version", 1L); |
|
67 |
+ |
private Entity createEntity( Key pGOD, String pName ) |
|
68 |
+ |
{ |
|
69 |
+ |
Entity zEntity = new Entity( "TheFlintstones", pName, pGOD ); |
|
70 |
+ |
zEntity.setUnindexedProperty( "Version", 1L ); |
64 |
71 |
|
|
65 |
|
- |
zEntity.setProperty("Name", pName); |
66 |
|
- |
zEntity.setUnindexedProperty("Children", 0L); |
|
72 |
+ |
zEntity.setProperty( "Name", pName ); |
|
73 |
+ |
zEntity.setUnindexedProperty( "Children", 0L ); |
67 |
74 |
|
return zEntity; |
68 |
75 |
|
} |
69 |
76 |
|
|
70 |
|
- |
private void inc(Entity pEntity, String pProperty) { |
71 |
|
- |
Long zLong = (Long) pEntity.getProperty(pProperty); |
72 |
|
- |
pEntity.setUnindexedProperty(pProperty, zLong + 1); |
|
77 |
+ |
private void inc( Entity pEntity, String pProperty ) |
|
78 |
+ |
{ |
|
79 |
+ |
Long zLong = (Long) pEntity.getProperty( pProperty ); |
|
80 |
+ |
pEntity.setUnindexedProperty( pProperty, zLong + 1 ); |
73 |
81 |
|
} |
74 |
82 |
|
|
75 |
|
- |
private Entity updateChildren(Entity pEntity) { |
76 |
|
- |
inc(pEntity, "Version"); |
77 |
|
- |
inc(pEntity, "Children"); |
|
83 |
+ |
private Entity updateChildren( Entity pEntity ) |
|
84 |
+ |
{ |
|
85 |
+ |
inc( pEntity, "Version" ); |
|
86 |
+ |
inc( pEntity, "Children" ); |
78 |
87 |
|
return pEntity; |
79 |
88 |
|
} |
80 |
89 |
|
|
81 |
|
- |
public void test_DataStoreConfig() throws Exception { |
82 |
|
- |
assertEquals(5.0d, mConfig.getDeadline(), 0.0001); |
83 |
|
- |
assertEquals(ImplicitTransactionManagementPolicy.NONE, mConfig |
84 |
|
- |
.getImplicitTransactionManagementPolicy()); |
85 |
|
- |
assertEquals(Consistency.STRONG, mConfig.getReadPolicy() |
86 |
|
- |
.getConsistency()); |
|
90 |
+ |
public void test_DataStoreConfig() throws Exception |
|
91 |
+ |
{ |
|
92 |
+ |
assertEquals( 5.0d, mConfig.getDeadline(), 0.0001 ); |
|
93 |
+ |
assertEquals( ImplicitTransactionManagementPolicy.NONE, mConfig.getImplicitTransactionManagementPolicy() ); |
|
94 |
+ |
assertEquals( Consistency.STRONG, mConfig.getReadPolicy().getConsistency() ); |
87 |
95 |
|
} |
88 |
96 |
|
|
89 |
|
- |
public void test_NonConflictingOverlapingTransactionsNew() throws Exception { |
|
97 |
+ |
public void test_NonConflictingOverlapingTransactionsNew() throws Exception |
|
98 |
+ |
{ |
90 |
99 |
|
Transaction zApolloTransaction = mDatastoreService.beginTransaction(); |
91 |
100 |
|
Transaction zVenusTransaction = mDatastoreService.beginTransaction(); |
92 |
101 |
|
|
93 |
|
- |
Entity zEntityFred = createEntity(mGOD_Apollo, "Fred"); |
94 |
|
- |
mDatastoreService.put(zApolloTransaction, zEntityFred); |
95 |
|
- |
Entity zEntityWilma = createEntity(mGOD_Venus, "Wilma"); |
96 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityWilma); |
97 |
|
- |
|
98 |
|
- |
Entity zEntityBarney = createEntity(mGOD_Apollo, "Barney"); |
99 |
|
- |
mDatastoreService.put(zApolloTransaction, zEntityBarney); |
100 |
|
- |
Entity zEntityBetty = createEntity(mGOD_Venus, "Betty"); |
101 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityBetty); |
|
102 |
+ |
Entity zEntityFred = createEntity( mGOD_Apollo, "Fred" ); |
|
103 |
+ |
mDatastoreService.put( zApolloTransaction, zEntityFred ); |
|
104 |
+ |
Entity zEntityWilma = createEntity( mGOD_Venus, "Wilma" ); |
|
105 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityWilma ); |
|
106 |
+ |
|
|
107 |
+ |
Entity zEntityBarney = createEntity( mGOD_Apollo, "Barney" ); |
|
108 |
+ |
mDatastoreService.put( zApolloTransaction, zEntityBarney ); |
|
109 |
+ |
Entity zEntityBetty = createEntity( mGOD_Venus, "Betty" ); |
|
110 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityBetty ); |
102 |
111 |
|
|
103 |
112 |
|
zApolloTransaction.commit(); |
104 |
113 |
|
zVenusTransaction.commit(); |
105 |
114 |
|
|
106 |
|
- |
readAndValidate(null, zEntityFred, "Fred", 1, 0); |
107 |
|
- |
readAndValidate(null, zEntityWilma, "Wilma", 1, 0); |
|
115 |
+ |
readAndValidate( null, zEntityFred, "Fred", 1, 0 ); |
|
116 |
+ |
readAndValidate( null, zEntityWilma, "Wilma", 1, 0 ); |
108 |
117 |
|
|
109 |
|
- |
readAndValidate(null, zEntityBarney, "Barney", 1, 0); |
110 |
|
- |
readAndValidate(null, zEntityBetty, "Betty", 1, 0); |
|
118 |
+ |
readAndValidate( null, zEntityBarney, "Barney", 1, 0 ); |
|
119 |
+ |
readAndValidate( null, zEntityBetty, "Betty", 1, 0 ); |
111 |
120 |
|
} |
112 |
121 |
|
|
113 |
|
- |
public void test_TransactionReadMultiGOD() throws Exception { |
|
122 |
+ |
public void test_TransactionReadMultiGOD() throws Exception |
|
123 |
+ |
{ |
114 |
124 |
|
Transaction zApolloTransaction = mDatastoreService.beginTransaction(); |
115 |
125 |
|
Transaction zVenusTransaction = mDatastoreService.beginTransaction(); |
116 |
126 |
|
|
117 |
|
- |
Entity zEntityFred = createEntity(mGOD_Apollo, "Fred"); |
118 |
|
- |
mDatastoreService.put(zApolloTransaction, zEntityFred); |
119 |
|
- |
Entity zEntityWilma = createEntity(mGOD_Venus, "Wilma"); |
120 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityWilma); |
|
127 |
+ |
Entity zEntityFred = createEntity( mGOD_Apollo, "Fred" ); |
|
128 |
+ |
mDatastoreService.put( zApolloTransaction, zEntityFred ); |
|
129 |
+ |
Entity zEntityWilma = createEntity( mGOD_Venus, "Wilma" ); |
|
130 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityWilma ); |
121 |
131 |
|
|
122 |
132 |
|
zApolloTransaction.commit(); |
123 |
133 |
|
zVenusTransaction.commit(); |
124 |
134 |
|
|
125 |
135 |
|
Transaction zTransaction = mDatastoreService.beginTransaction(); |
126 |
|
- |
mDatastoreService.get(zTransaction, zEntityFred.getKey()); // will |
|
136 |
+ |
mDatastoreService.get( zTransaction, zEntityFred.getKey() ); // will |
127 |
137 |
|
// succeed! |
128 |
|
- |
try { |
129 |
|
- |
mDatastoreService.get(zTransaction, zEntityWilma.getKey()); // will |
|
138 |
+ |
try |
|
139 |
+ |
{ |
|
140 |
+ |
mDatastoreService.get( zTransaction, zEntityWilma.getKey() ); // will |
130 |
141 |
|
// Fail! |
131 |
|
- |
fail("Fred & Wilma - Did NOT Fail with different GODS (Entity Groups)"); |
132 |
|
- |
} catch (IllegalArgumentException expected) { |
|
142 |
+ |
fail( "Fred & Wilma - Did NOT Fail with different GODS (Entity Groups)" ); |
|
143 |
+ |
} |
|
144 |
+ |
catch ( IllegalArgumentException expected ) |
|
145 |
+ |
{ |
133 |
146 |
|
String zMessage = expected.getMessage(); |
134 |
|
- |
assertTrue( |
135 |
|
- |
zMessage, |
136 |
|
- |
zMessage |
137 |
|
- |
.startsWith("can't operate on multiple entity groups in a single transaction.")); |
|
147 |
+ |
assertTrue( zMessage, zMessage |
|
148 |
+ |
.startsWith( "can't operate on multiple entity groups in a single transaction." ) ); |
138 |
149 |
|
} |
139 |
150 |
|
zTransaction.rollback(); |
140 |
151 |
|
} |
141 |
152 |
|
|
142 |
|
- |
public void test_TransactionUpdate() throws Exception { |
|
153 |
+ |
public void test_TransactionUpdate() throws Exception |
|
154 |
+ |
{ |
143 |
155 |
|
Transaction zApolloTransaction = mDatastoreService.beginTransaction(); |
144 |
156 |
|
Transaction zVenusTransaction = mDatastoreService.beginTransaction(); |
145 |
157 |
|
|
146 |
|
- |
Entity zEntityFred = createEntity(mGOD_Apollo, "Fred"); |
147 |
|
- |
mDatastoreService.put(zApolloTransaction, zEntityFred); |
148 |
|
- |
Entity zEntityWilma = createEntity(mGOD_Venus, "Wilma"); |
149 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityWilma); |
150 |
|
- |
|
151 |
|
- |
Entity zEntityBarney = createEntity(mGOD_Apollo, "Barney"); |
152 |
|
- |
mDatastoreService.put(zApolloTransaction, zEntityBarney); |
153 |
|
- |
Entity zEntityBetty = createEntity(mGOD_Venus, "Betty"); |
154 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityBetty); |
|
158 |
+ |
Entity zEntityFred = createEntity( mGOD_Apollo, "Fred" ); |
|
159 |
+ |
mDatastoreService.put( zApolloTransaction, zEntityFred ); |
|
160 |
+ |
Entity zEntityWilma = createEntity( mGOD_Venus, "Wilma" ); |
|
161 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityWilma ); |
|
162 |
+ |
|
|
163 |
+ |
Entity zEntityBarney = createEntity( mGOD_Apollo, "Barney" ); |
|
164 |
+ |
mDatastoreService.put( zApolloTransaction, zEntityBarney ); |
|
165 |
+ |
Entity zEntityBetty = createEntity( mGOD_Venus, "Betty" ); |
|
166 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityBetty ); |
155 |
167 |
|
|
156 |
168 |
|
zApolloTransaction.commit(); |
157 |
169 |
|
zVenusTransaction.commit(); |
158 |
170 |
|
|
159 |
171 |
|
zVenusTransaction = mDatastoreService.beginTransaction(); |
160 |
172 |
|
|
161 |
|
- |
zEntityWilma = updateChildren(readAndValidate(zVenusTransaction, |
162 |
|
- |
zEntityWilma, "Wilma", 1, 0)); |
163 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityWilma); |
|
173 |
+ |
zEntityWilma = updateChildren( readAndValidate( zVenusTransaction, zEntityWilma, "Wilma", 1, 0 ) ); |
|
174 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityWilma ); |
164 |
175 |
|
|
165 |
|
- |
Entity zEntityPebbles = createEntity(mGOD_Venus, "Pebbles"); |
166 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityPebbles); |
|
176 |
+ |
Entity zEntityPebbles = createEntity( mGOD_Venus, "Pebbles" ); |
|
177 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityPebbles ); |
167 |
178 |
|
|
168 |
179 |
|
// Can't Update Fred! |
169 |
180 |
|
|
|
@@ -171,35 +182,34 @@ |
171 |
182 |
|
|
172 |
183 |
|
zApolloTransaction = mDatastoreService.beginTransaction(); |
173 |
184 |
|
|
174 |
|
- |
zEntityBarney = updateChildren(readAndValidate(zApolloTransaction, |
175 |
|
- |
zEntityBarney, "Barney", 1, 0)); |
176 |
|
- |
mDatastoreService.put(zApolloTransaction, zEntityBarney); |
|
185 |
+ |
zEntityBarney = updateChildren( readAndValidate( zApolloTransaction, zEntityBarney, "Barney", 1, 0 ) ); |
|
186 |
+ |
mDatastoreService.put( zApolloTransaction, zEntityBarney ); |
177 |
187 |
|
|
178 |
|
- |
Entity zEntityBammBamm = createEntity(mGOD_Apollo, "BammBamm"); |
179 |
|
- |
mDatastoreService.put(zApolloTransaction, zEntityBammBamm); |
|
188 |
+ |
Entity zEntityBammBamm = createEntity( mGOD_Apollo, "BammBamm" ); |
|
189 |
+ |
mDatastoreService.put( zApolloTransaction, zEntityBammBamm ); |
180 |
190 |
|
|
181 |
191 |
|
// Can't Update Betty! |
182 |
192 |
|
|
183 |
193 |
|
zApolloTransaction.commit(); |
184 |
194 |
|
|
185 |
|
- |
readAndValidate(null, zEntityFred, "Fred", 1, 0); |
186 |
|
- |
readAndValidate(null, zEntityWilma, "Wilma", 2, 1); |
187 |
|
- |
readAndValidate(null, zEntityPebbles, "Pebbles", 1, 0); |
|
195 |
+ |
readAndValidate( null, zEntityFred, "Fred", 1, 0 ); |
|
196 |
+ |
readAndValidate( null, zEntityWilma, "Wilma", 2, 1 ); |
|
197 |
+ |
readAndValidate( null, zEntityPebbles, "Pebbles", 1, 0 ); |
188 |
198 |
|
|
189 |
|
- |
readAndValidate(null, zEntityBarney, "Barney", 2, 1); |
190 |
|
- |
readAndValidate(null, zEntityBetty, "Betty", 1, 0); |
191 |
|
- |
readAndValidate(null, zEntityBammBamm, "BammBamm", 1, 0); |
|
199 |
+ |
readAndValidate( null, zEntityBarney, "Barney", 2, 1 ); |
|
200 |
+ |
readAndValidate( null, zEntityBetty, "Betty", 1, 0 ); |
|
201 |
+ |
readAndValidate( null, zEntityBammBamm, "BammBamm", 1, 0 ); |
192 |
202 |
|
} |
193 |
203 |
|
|
194 |
|
- |
public void test_NonConflictingOverlapingTransactionsUpdate() |
195 |
|
- |
throws Exception { |
|
204 |
+ |
public void test_NonConflictingOverlapingTransactionsUpdate() throws Exception |
|
205 |
+ |
{ |
196 |
206 |
|
Transaction zApolloTransaction = mDatastoreService.beginTransaction(); |
197 |
207 |
|
Transaction zVenusTransaction = mDatastoreService.beginTransaction(); |
198 |
208 |
|
|
199 |
|
- |
Entity zEntityFred = createEntity(mGOD_Apollo, "Fred"); |
200 |
|
- |
mDatastoreService.put(zApolloTransaction, zEntityFred); |
201 |
|
- |
Entity zEntityWilma = createEntity(mGOD_Venus, "Wilma"); |
202 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityWilma); |
|
209 |
+ |
Entity zEntityFred = createEntity( mGOD_Apollo, "Fred" ); |
|
210 |
+ |
mDatastoreService.put( zApolloTransaction, zEntityFred ); |
|
211 |
+ |
Entity zEntityWilma = createEntity( mGOD_Venus, "Wilma" ); |
|
212 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityWilma ); |
203 |
213 |
|
|
204 |
214 |
|
zApolloTransaction.commit(); |
205 |
215 |
|
zVenusTransaction.commit(); |
|
@@ -207,98 +217,93 @@ |
207 |
217 |
|
zApolloTransaction = mDatastoreService.beginTransaction(); |
208 |
218 |
|
zVenusTransaction = mDatastoreService.beginTransaction(); |
209 |
219 |
|
|
210 |
|
- |
zEntityWilma = updateChildren(readAndValidate(zVenusTransaction, |
211 |
|
- |
zEntityWilma, "Wilma", 1, 0)); |
212 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityWilma); |
213 |
|
- |
|
214 |
|
- |
Entity zEntityPebbles = createEntity(mGOD_Venus, "Pebbles"); |
215 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityPebbles); |
216 |
|
- |
|
217 |
|
- |
zEntityFred = updateChildren(readAndValidate(zApolloTransaction, |
218 |
|
- |
zEntityFred, "Fred", 1, 0)); |
219 |
|
- |
mDatastoreService.put(zApolloTransaction, zEntityFred); |
|
220 |
+ |
zEntityWilma = updateChildren( readAndValidate( zVenusTransaction, zEntityWilma, "Wilma", 1, 0 ) ); |
|
221 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityWilma ); |
|
222 |
+ |
|
|
223 |
+ |
Entity zEntityPebbles = createEntity( mGOD_Venus, "Pebbles" ); |
|
224 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityPebbles ); |
|
225 |
+ |
|
|
226 |
+ |
zEntityFred = updateChildren( readAndValidate( zApolloTransaction, zEntityFred, "Fred", 1, 0 ) ); |
|
227 |
+ |
mDatastoreService.put( zApolloTransaction, zEntityFred ); |
220 |
228 |
|
|
221 |
229 |
|
zApolloTransaction.commit(); |
222 |
230 |
|
zVenusTransaction.commit(); |
223 |
231 |
|
|
224 |
|
- |
readAndValidate(null, zEntityFred, "Fred", 2, 1); |
225 |
|
- |
readAndValidate(null, zEntityWilma, "Wilma", 2, 1); |
|
232 |
+ |
readAndValidate( null, zEntityFred, "Fred", 2, 1 ); |
|
233 |
+ |
readAndValidate( null, zEntityWilma, "Wilma", 2, 1 ); |
226 |
234 |
|
|
227 |
|
- |
readAndValidate(null, zEntityPebbles, "Pebbles", 1, 0); |
|
235 |
+ |
readAndValidate( null, zEntityPebbles, "Pebbles", 1, 0 ); |
228 |
236 |
|
} |
229 |
237 |
|
|
230 |
|
- |
public void test_ConflictingOverlapingTransactionsUpdate() throws Exception { |
|
238 |
+ |
public void test_ConflictingOverlapingTransactionsUpdate() throws Exception |
|
239 |
+ |
{ |
231 |
240 |
|
Transaction zVenusTransaction = mDatastoreService.beginTransaction(); |
232 |
241 |
|
|
233 |
|
- |
Entity zEntityWilma = createEntity(mGOD_Venus, "Wilma"); |
234 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityWilma); |
|
242 |
+ |
Entity zEntityWilma = createEntity( mGOD_Venus, "Wilma" ); |
|
243 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityWilma ); |
235 |
244 |
|
|
236 |
245 |
|
zVenusTransaction.commit(); |
237 |
246 |
|
|
238 |
247 |
|
zVenusTransaction = mDatastoreService.beginTransaction(); |
239 |
248 |
|
|
240 |
|
- |
zEntityWilma = updateChildren(readAndValidate(zVenusTransaction, |
241 |
|
- |
zEntityWilma, "Wilma", 1, 0)); |
242 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityWilma); |
|
249 |
+ |
zEntityWilma = updateChildren( readAndValidate( zVenusTransaction, zEntityWilma, "Wilma", 1, 0 ) ); |
|
250 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityWilma ); |
243 |
251 |
|
|
244 |
|
- |
Entity zEntityPebbles = createEntity(mGOD_Venus, "Pebbles"); |
245 |
|
- |
mDatastoreService.put(zVenusTransaction, zEntityPebbles); |
|
252 |
+ |
Entity zEntityPebbles = createEntity( mGOD_Venus, "Pebbles" ); |
|
253 |
+ |
mDatastoreService.put( zVenusTransaction, zEntityPebbles ); |
246 |
254 |
|
|
247 |
255 |
|
Transaction zVenus2Transaction = mDatastoreService.beginTransaction(); |
248 |
256 |
|
|
249 |
|
- |
Entity zEntityWilma2 = updateChildren(readAndValidate2( |
250 |
|
- |
zVenus2Transaction, zEntityWilma, "Wilma", 1, 0)); |
251 |
|
- |
mDatastoreService.put(zVenus2Transaction, zEntityWilma2); |
|
257 |
+ |
Entity zEntityWilma2 = updateChildren( readAndValidate2( zVenus2Transaction, zEntityWilma, "Wilma", 1, 0 ) ); |
|
258 |
+ |
mDatastoreService.put( zVenus2Transaction, zEntityWilma2 ); |
252 |
259 |
|
|
253 |
260 |
|
zVenusTransaction.commit(); |
254 |
261 |
|
|
255 |
|
- |
try { |
|
262 |
+ |
try |
|
263 |
+ |
{ |
256 |
264 |
|
zVenus2Transaction.commit(); |
257 |
|
- |
fail("Two Transaction Wilma Update - Did NOT Fail"); |
258 |
|
- |
} catch (ConcurrentModificationException expected) { |
|
265 |
+ |
fail( "Two Transaction Wilma Update - Did NOT Fail" ); |
|
266 |
+ |
} |
|
267 |
+ |
catch ( ConcurrentModificationException expected ) |
|
268 |
+ |
{ |
259 |
269 |
|
String zMessage = expected.getMessage(); |
260 |
|
- |
assertTrue( |
261 |
|
- |
zMessage, |
262 |
|
- |
zMessage |
263 |
|
- |
.startsWith("too much contention on these datastore entities. please try again.")); |
|
270 |
+ |
assertTrue( zMessage, zMessage |
|
271 |
+ |
.startsWith( "too much contention on these datastore entities. please try again." ) ); |
264 |
272 |
|
} |
265 |
273 |
|
} |
266 |
274 |
|
|
267 |
|
- |
private Entity readAndValidate(Transaction pTransaction, Entity pEntity, |
268 |
|
- |
String pName, long pCurrentVersion, long pCurrentChildren) |
269 |
|
- |
throws EntityNotFoundException { |
270 |
|
- |
assertEquals("Current Entity Version", pCurrentVersion, pEntity |
271 |
|
- |
.getProperty("Version")); |
272 |
|
- |
assertEquals("Current Entity Name", pName, pEntity.getProperty("Name")); |
273 |
|
- |
assertEquals("Current Entity Children", pCurrentChildren, pEntity |
274 |
|
- |
.getProperty("Children")); |
275 |
|
- |
|
276 |
|
- |
return readAndValidate2(pTransaction, pEntity, pName, pCurrentVersion, |
277 |
|
- |
pCurrentChildren); |
278 |
|
- |
} |
279 |
|
- |
|
280 |
|
- |
private Entity readAndValidate2(Transaction pTransaction, Entity pEntity, |
281 |
|
- |
String pName, long pCurrentVersion, long pCurrentChildren) |
282 |
|
- |
throws EntityNotFoundException { |
|
275 |
+ |
private Entity readAndValidate( Transaction pTransaction, Entity pEntity, String pName, long pCurrentVersion, |
|
276 |
+ |
long pCurrentChildren ) throws EntityNotFoundException |
|
277 |
+ |
{ |
|
278 |
+ |
assertEquals( "Current Entity Version", pCurrentVersion, pEntity.getProperty( "Version" ) ); |
|
279 |
+ |
assertEquals( "Current Entity Name", pName, pEntity.getProperty( "Name" ) ); |
|
280 |
+ |
assertEquals( "Current Entity Children", pCurrentChildren, pEntity.getProperty( "Children" ) ); |
|
281 |
+ |
|
|
282 |
+ |
return readAndValidate2( pTransaction, pEntity, pName, pCurrentVersion, pCurrentChildren ); |
|
283 |
+ |
} |
|
284 |
+ |
|
|
285 |
+ |
private Entity readAndValidate2( Transaction pTransaction, Entity pEntity, String pName, long pCurrentVersion, |
|
286 |
+ |
long pCurrentChildren ) throws EntityNotFoundException |
|
287 |
+ |
{ |
283 |
288 |
|
Key zKey = pEntity.getKey(); |
284 |
|
- |
Entity zEntity = mDatastoreService.get(pTransaction, zKey); |
|
289 |
+ |
Entity zEntity = mDatastoreService.get( pTransaction, zKey ); |
285 |
290 |
|
|
286 |
|
- |
if (pTransaction == null) { |
287 |
|
- |
Object zVersion = zEntity.getProperty("Version"); |
288 |
|
- |
assertNotNull("Read Entity Version", zVersion); |
289 |
|
- |
if (!zVersion.equals(pCurrentVersion)) { |
|
291 |
+ |
if ( pTransaction == null ) |
|
292 |
+ |
{ |
|
293 |
+ |
Object zVersion = zEntity.getProperty( "Version" ); |
|
294 |
+ |
assertNotNull( "Read Entity Version", zVersion ); |
|
295 |
+ |
if ( !zVersion.equals( pCurrentVersion ) ) |
|
296 |
+ |
{ |
290 |
297 |
|
Transaction zTransaction = mDatastoreService.beginTransaction(); |
291 |
|
- |
zEntity = mDatastoreService.get(zTransaction, zKey); |
|
298 |
+ |
zEntity = mDatastoreService.get( zTransaction, zKey ); |
292 |
299 |
|
zTransaction.rollback(); |
293 |
300 |
|
} |
294 |
301 |
|
} |
295 |
302 |
|
|
296 |
|
- |
assertEquals("Read Entity Version", pCurrentVersion, zEntity |
297 |
|
- |
.getProperty("Version")); |
298 |
|
- |
assertEquals("Read Entity Name", pName, zEntity.getProperty("Name")); |
299 |
|
- |
assertEquals("Read Entity Children", pCurrentChildren, zEntity |
300 |
|
- |
.getProperty("Children")); |
|
303 |
+ |
assertEquals( "Read Entity Version", pCurrentVersion, zEntity.getProperty( "Version" ) ); |
|
304 |
+ |
assertEquals( "Read Entity Name", pName, zEntity.getProperty( "Name" ) ); |
|
305 |
+ |
assertEquals( "Read Entity Children", pCurrentChildren, zEntity.getProperty( "Children" ) ); |
301 |
306 |
|
|
302 |
307 |
|
return zEntity; |
303 |
308 |
|
} |
304 |
|
- |
} |
|
309 |
+ |
} |