Example #1
0
 def set_up(self):
     requests.get = requests_get
     helpers.zookeeper.KazooClient = MockKazooClient
     self.zk = ZooKeeper(
         'foo', {
             'exhibitor': {
                 'hosts': ['localhost', 'exhibitor'],
                 'port': 8181
             },
             'scope': 'test'
         })
Example #2
0
    def get_dcs(name, config):
        if 'etcd' in config:
            assert config['etcd']['ttl'] > 2 * config['loop_wait']

            return Etcd(name, config['etcd'])
        if 'zookeeper' in config:
            return ZooKeeper(name, config['zookeeper'])
        raise Exception('Can not find sutable configuration of distributed configuration store')
Example #3
0
 def set_up(self):
     requests.get = requests_get
     helpers.zookeeper.KazooClient = MockKazooClient
     self.zk = ZooKeeper('foo', {'exhibitor': {'hosts': ['localhost', 'exhibitor'], 'port': 8181}, 'scope': 'test'})
Example #4
0
class TestZooKeeper(unittest.TestCase):

    def __init__(self, method_name='runTest'):
        self.setUp = self.set_up
        super(TestZooKeeper, self).__init__(method_name)

    def set_up(self):
        requests.get = requests_get
        helpers.zookeeper.KazooClient = MockKazooClient
        self.zk = ZooKeeper('foo', {'exhibitor': {'hosts': ['localhost', 'exhibitor'], 'port': 8181}, 'scope': 'test'})

    def test_session_listener(self):
        self.zk.session_listener(KazooState.SUSPENDED)

    def test_get_node(self):
        self.assertIsNone(self.zk.get_node('/no_node'))
        self.assertIsNone(self.zk.get_node('/other_exception'))

    def test__inner_load_cluster(self):
        self.zk._base_path = self.zk._base_path.replace('test', 'bla')
        self.zk._inner_load_cluster()

    def test_get_cluster(self):
        self.assertRaises(ZooKeeperError, self.zk.get_cluster)
        self.zk.exhibitor.poll = lambda: True
        self.zk.get_cluster()
        self.zk.touch_member('foo')
        self.zk.delete_leader()

    def test_race(self):
        self.assertFalse(self.zk.race('/initialize'))

    def test_touch_member(self):
        self.zk.touch_member('new')
        self.zk.touch_member('exists')
        self.zk.touch_member('retry')

    def test_take_leader(self):
        self.zk.take_leader()

    def test_update_leader(self):
        self.zk.last_leader_operation = -1
        self.assertTrue(self.zk.update_leader(MockPostgresql()))
        self.zk._base_path = self.zk._base_path.replace('test', 'bla')
        self.zk.last_leader_operation = -1
        self.assertTrue(self.zk.update_leader(MockPostgresql()))

    def test_sleep(self):
        self.zk.sleep(0)
Example #5
0
class TestZooKeeper(unittest.TestCase):
    def __init__(self, method_name='runTest'):
        self.setUp = self.set_up
        super(TestZooKeeper, self).__init__(method_name)

    def set_up(self):
        requests.get = requests_get
        helpers.zookeeper.KazooClient = MockKazooClient
        self.zk = ZooKeeper(
            'foo', {
                'exhibitor': {
                    'hosts': ['localhost', 'exhibitor'],
                    'port': 8181
                },
                'scope': 'test'
            })

    def test_session_listener(self):
        self.zk.session_listener(KazooState.SUSPENDED)

    def test_get_node(self):
        self.assertIsNone(self.zk.get_node('/no_node'))
        self.assertIsNone(self.zk.get_node('/other_exception'))

    def test__inner_load_cluster(self):
        self.zk._base_path = self.zk._base_path.replace('test', 'bla')
        self.zk._inner_load_cluster()

    def test_get_cluster(self):
        self.assertRaises(ZooKeeperError, self.zk.get_cluster)
        self.zk.exhibitor.poll = lambda: True
        self.zk.get_cluster()
        self.zk.touch_member('foo')
        self.zk.delete_leader()

    def test_race(self):
        self.assertFalse(self.zk.race('/initialize'))

    def test_touch_member(self):
        self.zk.touch_member('new')
        self.zk.touch_member('exists')
        self.zk.touch_member('retry')

    def test_take_leader(self):
        self.zk.take_leader()

    def test_update_leader(self):
        self.zk.last_leader_operation = -1
        self.assertTrue(self.zk.update_leader(MockPostgresql()))
        self.zk._base_path = self.zk._base_path.replace('test', 'bla')
        self.zk.last_leader_operation = -1
        self.assertTrue(self.zk.update_leader(MockPostgresql()))

    def test_sleep(self):
        self.zk.sleep(0)