def test_double_lock(self, patch_exit): # TODO (DATAPIPE-2122|abrar): this test is aqcuiring # lock on actual zookeeper instance, needs to be fixed. with ZKLock(self.fake_name, self.fake_namespace): assert patch_exit.call_count == 0 with ZKLock(self.fake_name, self.fake_namespace): pass assert patch_exit.call_count == 1
def _setup_components(self): with ZKLock( "replication_handler", config.env_config.namespace) as self.zk, self._setup_producer( ) as self.producer, self._setup_counters( ) as self.counters, self._register_signal_handlers(): yield
def test_lock_exception(self, locked_zk_client, locked_patch_zk, patch_exit): with ZKLock(self.fake_name, self.fake_namespace): pass assert patch_exit.call_count == 1 assert locked_zk_client.start.call_count == 1 # Since sys.exit is mocked, it calls close twice assert locked_zk_client.stop.call_count >= 1 assert locked_zk_client.close.call_count >= 1
def run(self): with ZKLock(name="refresh_manager", namespace=self.namespace): try: while True: self.step() if self._stopping: break self.log.debug("State of active_refresh_jobs: {}".format( self.active_refresh_jobs)) time.sleep(SCHEMATIZER_POLL_FREQUENCY_SECONDS) finally: self.pause_all_running_jobs()
def run(self): with ZKLock(name="refresh_manager", namespace=self.namespace): try: while True: self.set_zombie_refresh_to_fail() next_refresh = self.get_next_refresh() if next_refresh and self._should_run_next_refresh( next_refresh): self.setup_new_refresh(next_refresh) if self._stopping: break time.sleep(SCHEMATIZER_POLL_FREQUENCY_SECONDS) finally: if self.active_refresh['pid'] is not None: # When the manager goes down, the active refresh is paused. os.kill(self.active_refresh['pid'], signal.SIGTERM)
def test_setup_lock_and_close(self, zk_client, patch_zk): with ZKLock(self.fake_name, self.fake_namespace): self._check_mid_lock(zk_client) self._check_zk_lock(zk_client)
def test_double_lock(self, patch_exit): with ZKLock(self.fake_name, self.fake_namespace): assert patch_exit.call_count == 0 with ZKLock(self.fake_name, self.fake_namespace): pass assert patch_exit.call_count == 1