44from mybatis import Cache , CacheKey
55
66def test_basic ():
7- cache = Cache (memory_limit = 555 , max_live_ms = 10 * 1000 ) # 50MB, 10sec
7+ cache = Cache (memory_limit = 400 , max_live_ms = 10 * 1000 ) # 50MB, 10sec
88 cache .put (CacheKey ("a" , [1 , 'a' , None ]), [{"a1" : 1 }, {"a2" : 2 }])
99 cache .put (CacheKey ("b" , [2 , 'b' , None ]), "2" )
1010 cache .put (CacheKey ("c" , [3 , 'c' , None ]), "3" )
1111 cache .put (CacheKey ("d" , [4 , 'd' , None ]), None )
1212
13+ print ("============> memory_used:" , cache .memory_used )
14+
1315 assert cache .get (CacheKey ('a' , [1 , 'a' , None ])) == None
1416 assert cache .get (CacheKey ('b' , [2 , 'b' , None ])) == '2'
1517
@@ -18,13 +20,13 @@ def test_basic():
1820 l .append ((key , value , memory_usage , type (value )))
1921
2022 assert len (l ) == 3
21- assert l [0 ][0 ] == '{"sql": "b", "param_list": [2, "b", null]}'
23+ assert l [0 ][0 ] == b '{"sql":"b","param_list":[2,"b",null]}'
2224 assert l [0 ][1 ] == '2'
2325
24- assert l [1 ][0 ] == '{"sql": "d", "param_list": [4, "d", null]}'
26+ assert l [1 ][0 ] == b '{"sql":"d","param_list":[4,"d",null]}'
2527 assert l [1 ][1 ] == None
2628
27- assert l [2 ][0 ] == '{"sql": "c", "param_list": [3, "c", null]}'
29+ assert l [2 ][0 ] == b '{"sql":"c","param_list":[3,"c",null]}'
2830 assert l [2 ][1 ] == '3'
2931
3032 cache .put (CacheKey ("e" , [5 , 'e' , None ]), "5" )
@@ -36,17 +38,17 @@ def test_basic():
3638
3739 assert len (l ) == 3
3840
39- assert l [0 ][0 ] == '{"sql": "e", "param_list": [5, "e", null]}'
41+ assert l [0 ][0 ] == b '{"sql":"e","param_list":[5,"e",null]}'
4042 assert l [0 ][1 ] == '5'
4143
42- assert l [1 ][0 ] == '{"sql": "b", "param_list": [2, "b", null]}'
44+ assert l [1 ][0 ] == b '{"sql":"b","param_list":[2,"b",null]}'
4345 assert l [1 ][1 ] == '2'
4446
45- assert l [2 ][0 ] == '{"sql": "d", "param_list": [4, "d", null]}'
47+ assert l [2 ][0 ] == b '{"sql":"d","param_list":[4,"d",null]}'
4648 assert l [2 ][1 ] == None
4749
4850def test_timeout ():
49- cache = Cache (memory_limit = 555 , max_live_ms = 1 * 1000 ) # 50MB, 10sec
51+ cache = Cache (memory_limit = 400 , max_live_ms = 1 * 1000 ) # 50MB, 10sec
5052 cache .put (CacheKey ("a" , [1 , 'a' , None ]), [{"a1" : 1 }, {"a2" : 2 }])
5153 cache .put (CacheKey ("b" , [2 , 'b' , None ]), "2" )
5254 cache .put (CacheKey ("c" , [3 , 'c' , None ]), "3" )
@@ -61,7 +63,7 @@ def test_timeout():
6163 assert cache .memory_used == 0
6264
6365def test_overwrite ():
64- cache = Cache (memory_limit = 180 , max_live_ms = 10 * 1000 ) # 50MB, 10sec
66+ cache = Cache (memory_limit = 120 , max_live_ms = 10 * 1000 ) # 50MB, 10sec
6567 cache .put (CacheKey ("a" , [1 , 'a' , None ]), [{"a1" : 1 }, {"a2" : 2 }])
6668 #print ("++++>cache.memory_used:", cache.memory_used)
6769 cache .put (CacheKey ("a" , [1 , 'a' , None ]), [{"a1" : 1 }, {"a2" : 2 }, {"a3" :3 }])
0 commit comments