-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_ketama.py
44 lines (25 loc) · 951 Bytes
/
test_ketama.py
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
# -*- coding: utf-8 -*-
from ketama import Continuum
def test_init():
data = ['127.0.0.1:11211', '127.0.0.1:12212']
cont = Continuum(data)
assert cont["test"] == '127.0.0.1:11211'
def test_init_weight():
data = [('127.0.0.1:11211', 100), ('127.0.0.1:12212', 800)]
cont = Continuum(data)
assert cont["test"] == '127.0.0.1:12212'
def test_init_value():
data = [('tom', {'a': "dict"}, 500), ('jerry', [123], 800),
("goffy", None, 500)]
cont = Continuum(data)
assert cont['yellow'] == {'a': "dict"}
def test_setitem():
cont = Continuum()
cont['127.0.0.1:11211'] = '127.0.0.1:11211'
cont['127.0.0.1:11212'] = '127.0.0.1:11212'
assert cont['test'] == '127.0.0.1:11211'
def test_setitem_weight():
cont = Continuum()
cont[('127.0.0.1:11211', 100)] = '127.0.0.1:11211'
cont[('127.0.0.1:11212', 800)] = '127.0.0.1:11212'
assert cont['test'] == '127.0.0.1:11212'