Example #1
0
def test_metrics():
  with ZookeeperServer() as server:
    event = threading.Event()
    def state_change(state):
      event.set()
      return True

    zk = TwitterKazooClient('localhost:%d' % server.zookeeper_port)
    zk.start()
    zk.live.wait(timeout=MAX_EVENT_WAIT_SECS)
    zk.add_listener(state_change)
    sample = zk.metrics.sample()
    assert sample['session_id'] == zk._session_id
    assert sample['session_expirations'] == 0
    assert sample['connection_losses'] == 0
    old_session_id = zk._session_id

    server.expire(zk._session_id)
    event.wait(timeout=MAX_EVENT_WAIT_SECS)

    zk.live.wait(timeout=MAX_EVENT_WAIT_SECS)

    sample = zk.metrics.sample()
    assert sample['session_id'] == zk._session_id
    assert old_session_id != zk._session_id
    assert sample['session_expirations'] == 1
    assert sample['connection_losses'] > 0
 def get_scheduler_serverset(cls, cluster, port=2181, verbose=False, **kw):
   if cluster.zk is None:
     raise ValueError('Cluster has no associated zookeeper ensemble!')
   if cluster.scheduler_zk_path is None:
     raise ValueError('Cluster has no defined scheduler path, must specify scheduler_zk_path '
                      'in your cluster config!')
   zk = TwitterKazooClient.make(str('%s:%s' % (cluster.zk, port)), verbose=verbose)
   return zk, ServerSet(zk, cluster.scheduler_zk_path, **kw)
Example #3
0
 def get_scheduler_serverset(cls, cluster, port=2181, verbose=False, **kw):
   if cluster.zk is None:
     raise ValueError('Cluster has no associated zookeeper ensemble!')
   if cluster.scheduler_zk_path is None:
     raise ValueError('Cluster has no defined scheduler path, must specify scheduler_zk_path '
                      'in your cluster config!')
   hosts = [h + ':{p}' for h in cluster.zk.split(',')]
   zk = TwitterKazooClient.make(str(','.join(hosts).format(p=port)), verbose=verbose)
   return zk, ServerSet(zk, cluster.scheduler_zk_path, **kw)
Example #4
0
 def get_scheduler_serverset(cls, cluster, port=2181, verbose=False, **kw):
   if cluster.zk is None:
     raise ValueError('Cluster has no associated zookeeper ensemble!')
   if cluster.scheduler_zk_path is None:
     raise ValueError('Cluster has no defined scheduler path, must specify scheduler_zk_path '
                      'in your cluster config!')
   hosts = [h + ':{p}' for h in cluster.zk.split(',')]
   zk = TwitterKazooClient.make(str(','.join(hosts).format(p=port)), verbose=verbose)
   return zk, ServerSet(zk, cluster.scheduler_zk_path, **kw)
 def get_scheduler_serverset(cls, cluster, port=2181, verbose=False, **kw):
     if cluster.zk is None:
         raise ValueError('Cluster has no associated zookeeper ensemble!')
     if cluster.scheduler_zk_path is None:
         raise ValueError(
             'Cluster has no defined scheduler path, must specify scheduler_zk_path '
             'in your cluster config!')
     zk = TwitterKazooClient.make(str('%s:%s' % (cluster.zk, port)),
                                  verbose=verbose)
     return zk, ServerSet(zk, cluster.scheduler_zk_path, **kw)
def test_metrics():
    with ZookeeperServer() as server:
        event = threading.Event()

        def state_change(state):
            event.set()
            return True

        zk = TwitterKazooClient('localhost:%d' % server.zookeeper_port)
        zk.start()
        zk.live.wait(timeout=MAX_EVENT_WAIT_SECS)
        zk.add_listener(state_change)
        sample = zk.metrics.sample()
        assert sample['session_id'] == zk._session_id
        assert sample['session_expirations'] == 0
        assert sample['connection_losses'] == 0
        old_session_id = zk._session_id

        server.expire(zk._session_id)
        event.wait(timeout=MAX_EVENT_WAIT_SECS)

        zk.live.wait(timeout=MAX_EVENT_WAIT_SECS)

        sample = zk.metrics.sample()
        assert sample['session_id'] == zk._session_id
        assert old_session_id != zk._session_id
        assert sample['session_expirations'] == 1
        assert sample['connection_losses'] > 0
Example #7
0
 def make_zk(cls, ensemble, **kw):
   if 'authentication' in kw:
     kw.update(auth_data = [kw.pop('authentication')])
   tzk = TwitterKazooClient.make(
       ensemble + ('/%08d' % GroupTestBase.CHROOT_PREFIX),
       timeout=cls.CONNECT_TIMEOUT_SECS,
       max_retries=cls.CONNECT_RETRIES, **kw)
   started = threading.Event()
   def listen(state):
     if state == KazooState.CONNECTED:
       started.set()
     return True
   tzk.add_listener(listen)
   started.wait()
   tzk.ensure_path('/')
   return tzk
Example #8
0
    def make_zk(cls, ensemble, **kw):
        if 'authentication' in kw:
            kw.update(auth_data=[kw.pop('authentication')])
        tzk = TwitterKazooClient.make(ensemble +
                                      ('/%08d' % GroupTestBase.CHROOT_PREFIX),
                                      timeout=cls.CONNECT_TIMEOUT_SECS,
                                      max_retries=cls.CONNECT_RETRIES,
                                      **kw)
        started = threading.Event()

        def listen(state):
            if state == KazooState.CONNECTED:
                started.set()
            return True

        tzk.add_listener(listen)
        started.wait()
        tzk.ensure_path('/')
        return tzk
Example #9
0
 def make_zk(cls, ensemble):
     return TwitterKazooClient.make(ensemble)
 def make_zk(cls, ensemble):
   return TwitterKazooClient.make(ensemble)
Example #11
0
 def sdzk(self):
   if self._sdzk is None:
     self._sdzk = TwitterKazooClient.make(hosts='%s:2181' % self.zookeeper_ensemble_url, verbose=True)
     log.debug('Connected to %s' % self._sdzk)
   return self._sdzk