def setUp(self): super(TestSlave, self).setUp() utdocker.create_network() utdocker.start_container('redis-0', redis_tag, '192.168.52.40', '') dd('started redis in docker') redisutil.wait_serve(('192.168.52.40', redis_port)) self.redis_cli = redisutil.get_client(('192.168.52.40', redis_port)) self.journal_id_path = "tx/journal_id_set" self.storage = zktx.RedisStorage(self.redis_cli, self.journal_id_path) self.zk.create('tx', 'tx') self.zk.create('tx/journal_id_set', '{}') self.zk.create('tx/alive', '{}') self.zk.create('tx/txid_maker', '{}') self.zk.create('tx/journal', '{}') for d in ('lock', 'record'): self.zk.create(d, '{}') for d1 in ('leader', 'meta', 'job'): self.zk.create('/'.join([d, d1]), '{}') for d2 in ('block_group', 'global', 'region', 'server'): self.zk.create('/'.join([d, d1, d2]), '{}') self.zke, _ = zkutil.kazoo_client_ext(self.zk) self.slave = zktx.Slave(self.zke, self.storage)
def test_separated_connection_after_fork(self): hname = 'foo' pid = os.fork() dd('my pid:', os.getpid()) n = 10240 if pid == 0: # child self.rcl = redisutil.get_client((self.ip, redis_port)) # for both parent and child process for i in range(n): self.rcl.hset(hname, 'x' + str(i), 'foobarjfkdslafjdasklfdjsaklfdsa' + str(i)) self.rcl.hget(hname, 'x' + str(i - 1)) if i % 1024 == 0: dd('pid:', os.getpid(), ' finished ', i, ' set/get') if pid == 0: # child self.is_child = True child_exit() else: # parent os.waitpid(pid, 0) dd('child pid quit: ' + repr(pid))
def test_recreate_client(self): hname = 'foo' pid = os.fork() dd('my pid:', os.getpid()) if pid == 0: # child self.is_child = True rcl = redisutil.get_client((self.ip, redis_port)) rcl.hset(hname, 'a', '5') child_exit() else: # parent os.waitpid(pid, 0) dd('child pid quit: ' + repr(pid)) rst = self.rcl.hget(hname, 'a') dd('redis hget rst:', rst) self.assertEqual('5', rst)
def setUp(self): utdocker.create_network() utdocker.start_container('redis-0', redis_tag, '192.168.52.40', '') dd('started redis in docker') redisutil.wait_serve(('192.168.52.40', redis_port)) self.redis_cli = redisutil.get_client(('192.168.52.40', redis_port)) self.txid_path = "tx/txidset" self.storage = zktx.RedisStorage(self.redis_cli, self.txid_path)
def setUp(self): utdocker.create_network() utdocker.start_container('redis-0', redis_tag, '192.168.52.40', '') dd('started redis in docker') redisutil.wait_serve(('192.168.52.40', redis_port)) self.redis_cli = redisutil.get_client(('192.168.52.40', redis_port)) self.journal_id_set_path = "tx/journal_id_set" self.storage = zktx.RedisStorage(self.redis_cli, self.journal_id_set_path)
def test_2_ip_port(self): rcl = [] for name, tag, ip in self.containers: rcl.append(redisutil.get_client((ip, redis_port))) rcl[0].hset('foo', 'foo', '100') rcl[1].hset('foo', 'foo', '101') rst = rcl[0].hget('foo', 'foo') dd('rst got from first redis:', rst) self.assertEqual('100', rst)
def setUp(self): self.containers = [ ('redis-0', redis_tag, '192.168.52.40'), ('redis-1', redis_tag, '192.168.52.41'), ] # for single redis cases: self.docker_name = 'redis-0' self.ip = '192.168.52.40' self.is_child = False utdocker.create_network() for args in self.containers: utdocker.start_container(*(args + ('', ))) dd('started redis in docker: ' + repr(args)) redisutil.wait_serve((args[2], redis_port)) self.rcl = redisutil.get_client((self.ip, redis_port))