MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / test_executionPlanCache

Function test_executionPlanCache

tests/unit/test_cache.c:46–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46void test_executionPlanCache() {
47 // build a cache of strings in this case for simplicity
48 Cache *cache = Cache_New(3, (CacheEntryFreeFunc)CacheObj_Free,
49 (CacheEntryCopyFunc)CacheObj_Dup);
50
51 CacheObj *item1 = CacheObj_New("1");
52 CacheObj *item2 = CacheObj_New("2");
53 CacheObj *item3 = CacheObj_New("3");
54 CacheObj *item4 = CacheObj_New("4");
55
56 const char *key1 = "MATCH (a) RETURN a";
57 const char *key2 = "MATCH (b) RETURN b";
58 const char *key3 = "MATCH (c) RETURN c";
59 const char *key4 = "MATCH (d) RETURN d";
60
61 //--------------------------------------------------------------------------
62 // Check for not existing key.
63 //--------------------------------------------------------------------------
64
65 TEST_ASSERT(!Cache_GetValue(cache, "None existing"));
66
67 //--------------------------------------------------------------------------
68 // Set Get single item
69 //--------------------------------------------------------------------------
70
71 CacheObj *from_cache = NULL;
72 Cache_SetValue(cache, key1, item1);
73 from_cache = (CacheObj*)Cache_GetValue(cache, key1);
74 TEST_ASSERT(CacheObj_EQ(item1, from_cache));
75 CacheObj_Free(from_cache);
76
77 //--------------------------------------------------------------------------
78 // Set multiple items
79 //--------------------------------------------------------------------------
80
81 CacheObj* to_cache = (CacheObj*)Cache_SetGetValue(cache, key2, item2);
82 from_cache = (CacheObj*)Cache_GetValue(cache, key2);
83 TEST_ASSERT(CacheObj_EQ(item2, from_cache));
84 CacheObj_Free(to_cache);
85 CacheObj_Free(from_cache);
86
87 // Fill up cache
88 to_cache = (CacheObj*)Cache_SetGetValue(cache, key3, item3);
89 CacheObj_Free(to_cache);
90 to_cache = (CacheObj*)Cache_SetGetValue(cache, key4, item4);
91 CacheObj_Free(to_cache);
92
93 // Verify that oldest entry do not exists - queue is [ 4 | 3 | 2 ].
94 TEST_ASSERT(Cache_GetValue(cache, key1) == NULL);
95
96 Cache_Free(cache);
97
98 // Expecting CacheObjFree to be called 9 times.
99 TEST_ASSERT(free_count == 9);
100}
101
102TEST_LIST = {
103 {"executionPlanCache", test_executionPlanCache},

Callers

nothing calls this directly

Calls 8

Cache_NewFunction · 0.85
CacheObj_NewFunction · 0.85
Cache_GetValueFunction · 0.85
Cache_SetValueFunction · 0.85
CacheObj_EQFunction · 0.85
CacheObj_FreeFunction · 0.85
Cache_SetGetValueFunction · 0.85
Cache_FreeFunction · 0.85

Tested by

no test coverage detected