-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_multiple_cache.lua
More file actions
46 lines (38 loc) · 1.08 KB
/
Copy pathtest_multiple_cache.lua
File metadata and controls
46 lines (38 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local MULTIPLE_CACHE = require "multiple_cache"
local function table_length(t)
local length = 0
for _ in pairs(t) do
length = length + 1
end
return length
end
local function check_result(multiple_cache, func)
local t = {}
for key, obj in multiple_cache:selectall() do
t[key] = obj
end
func(t)
end
do
local mc = MULTIPLE_CACHE:new({"c1", "c2", "c3"}, "id", "type")
mc:set {id = 1, type = "type_1", x = 128, y = 129, name = "obj_1"}
mc:set {id = 2, type = "type_1", x = 128, y = 130, name = "obj_2"}
mc:commit("c3", "c2")
mc:commit("c2", "c1")
assert(mc:selectkey(1) ~= nil)
mc:remove(1)
check_result(mc, function(t)
assert(table_length(t) == 1)
assert(t[2])
assert(t[2].name == "obj_2")
end)
mc:commit("c3", "c2")
mc:commit("c2", "c1")
mc:set {id = 1, type = "type_1", x = 128, y = 129, name = "obj_1"}
mc:revert({"c3"})
check_result(mc, function(t)
assert(table_length(t) == 1)
assert(t[2].name == "obj_2")
end)
mc:cleanup()
end