@@ -228,5 +228,75 @@ def test_query_timeout(self):
228
228
# Expecting an error.
229
229
pass
230
230
231
+ def test_cache_sync (self ):
232
+ # This test verifies that client internal graph schema cache stays
233
+ # in sync with the graph schema
234
+ #
235
+ # Client B will try to get Client A out of sync by:
236
+ # 1. deleting the graph
237
+ # 2. reconstructing the graph in a different order, this will casuse
238
+ # a differance in the current mapping between string IDs and the
239
+ # mapping Client A is aware of
240
+ #
241
+ # Client A should pick up on the changes by comparing graph versions
242
+ # and resyncing its cache.
243
+
244
+ A = Graph ('cache-sync' , self .r )
245
+ B = Graph ('cache-sync' , self .r )
246
+
247
+ # Build order:
248
+ # 1. introduce label 'L' and 'K'
249
+ # 2. introduce attribute 'x' and 'q'
250
+ # 3. introduce relationship-type 'R' and 'S'
251
+
252
+ A .query ("CREATE (:L)" )
253
+ B .query ("CREATE (:K)" )
254
+ A .query ("MATCH (n) SET n.x = 1" )
255
+ B .query ("MATCH (n) SET n.q = 1" )
256
+ A .query ("MATCH (n) CREATE (n)-[:R]->()" )
257
+ B .query ("MATCH (n) CREATE (n)-[:S]->()" )
258
+
259
+ # Cause client A to populate its cache
260
+ A .query ("MATCH (n)-[e]->() RETURN n, e" )
261
+
262
+ assert (len (A ._labels ) == 2 )
263
+ assert (len (A ._properties ) == 2 )
264
+ assert (len (A ._relationshipTypes ) == 2 )
265
+ assert (A ._labels [0 ] == 'L' )
266
+ assert (A ._labels [1 ] == 'K' )
267
+ assert (A ._properties [0 ] == 'x' )
268
+ assert (A ._properties [1 ] == 'q' )
269
+ assert (A ._relationshipTypes [0 ] == 'R' )
270
+ assert (A ._relationshipTypes [1 ] == 'S' )
271
+
272
+ # Have client B reconstruct the graph in a different order.
273
+ B .delete ()
274
+
275
+ # Build order:
276
+ # 1. introduce relationship-type 'R'
277
+ # 2. introduce label 'L'
278
+ # 3. introduce attribute 'x'
279
+ B .query ("CREATE ()-[:S]->()" )
280
+ B .query ("CREATE ()-[:R]->()" )
281
+ B .query ("CREATE (:K)" )
282
+ B .query ("CREATE (:L)" )
283
+ B .query ("MATCH (n) SET n.q = 1" )
284
+ B .query ("MATCH (n) SET n.x = 1" )
285
+
286
+ # A's internal cached mapping is now out of sync
287
+ # issue a query and make sure A's cache is synced.
288
+ A .query ("MATCH (n)-[e]->() RETURN n, e" )
289
+
290
+ assert (len (A ._labels ) == 2 )
291
+ assert (len (A ._properties ) == 2 )
292
+ assert (len (A ._relationshipTypes ) == 2 )
293
+ assert (A ._labels [0 ] == 'K' )
294
+ assert (A ._labels [1 ] == 'L' )
295
+ assert (A ._properties [0 ] == 'q' )
296
+ assert (A ._properties [1 ] == 'x' )
297
+ assert (A ._relationshipTypes [0 ] == 'S' )
298
+ assert (A ._relationshipTypes [1 ] == 'R' )
299
+
231
300
if __name__ == '__main__' :
232
301
unittest .main ()
302
+
0 commit comments