-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathmulti.test.py
71 lines (61 loc) · 2.06 KB
/
multi.test.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
import os
import time
import yaml
from lib.tarantool_server import TarantoolServer
sys.path.append('../tarantool')
from mesh_connection import MeshConnection
from tarantool.const import (
SOCKET_TIMEOUT,
RECONNECT_DELAY,
)
from tarantool.error import NetworkError
from tarantool.utils import ENCODING_DEFAULT
INSTANCE_N = 2
def check_connection(con):
try:
s = con.space('test')
print(s.select())
except NetworkError:
print('NetworkError !')
except Exception as e:
print(e)
# Start instances
master = server
cluster = [master]
for i in range(INSTANCE_N):
server = TarantoolServer(server.ini)
server.script = 'cluster-py/instance%d.lua' % (i+1)
server.vardir = os.path.join(server.vardir, 'instance', str(i))
server.deploy()
server.admin("box.schema.user.grant('guest', 'read,write,execute', 'universe')")
server.admin("_ = box.schema.space.create('test')")
server.admin("_ = box.space.test:create_index('primary')")
server.admin("box.space.test:insert{%d, %s}" % (1, i), silent = True)
cluster.append(server)
# Make a list of servers
sources = []
for server in cluster[1:]:
sources.append(yaml.safe_load(server.admin('box.cfg.listen', silent=True))[0])
addrs = []
for addr in sources:
addrs.append({'host': None, 'port': addr})
con = MeshConnection(addrs=addrs,
user=None,
password=None,
socket_timeout=SOCKET_TIMEOUT,
reconnect_max_attempts=0,
reconnect_delay=RECONNECT_DELAY,
connect_now=True,
encoding=ENCODING_DEFAULT)
cluster[0].stop() # stop server - no effect
check_connection(con) # instance#1
cluster[1].stop() # stop instance#1
check_connection(con) # instance#2
cluster[1].start() # start instance#1
cluster[2].stop() # stop instance#2
check_connection(con) # instance#1 again
cluster[1].stop() # stop instance#1
check_connection(con) # both stopped: NetworkError !
master.cleanup()
master.deploy()