def __init__(self, felix_sck): # Wrap the socket with our protocol reader/writer objects. self._msg_reader = MessageReader(felix_sck) self._msg_writer = MessageWriter(felix_sck) # Global stop event used to signal to all threads to stop. self._stop_event = Event() # Threads to own the connection from/to Felix. The resync thread # is responsible for doing resyncs and merging updates from the # watcher thread (which it manages). self._reader_thread = Thread(target=self._read_from_socket, name="reader-thread") self._reader_thread.daemon = True self._resync_thread = Thread(target=self._resync_and_merge, name="resync-thread") self._resync_thread.daemon = True self._watcher_thread = None # Created on demand self._watcher_stop_event = None self._watcher_start_index = None # High-water mark cache. Owned by resync thread. self._hwms = HighWaterTracker() self._first_resync = True self._resync_http_pool = None self._cluster_id = None # Resync thread stats. self._snap_keys_processed = RateStat("snapshot keys processed") self._event_keys_processed = RateStat("event keys processed") self._felix_updates_sent = RateStat("felix updates sent") self._resync_stats = [ self._snap_keys_processed, self._event_keys_processed, self._felix_updates_sent, ] self._last_resync_stat_log_time = monotonic_time() # Set by the reader thread once the init message has been received # from Felix. self._init_received = Event() # Initial config, received in the init message. self._etcd_base_url = None self._etcd_other_urls = [] # Lock for the etcd url fields: this is the only lock, and no thread # ever recursively acquires it, so it cannot deadlock. Must be locked # to access the _etcd_base_url and _etcd_other_urls fields (after they # are initialized). self._etcd_url_lock = Lock() self._hostname = None # Set by the reader thread once the logging config has been received # from Felix. Triggers the first resync. self._config_received = Event() # Flag to request a resync. Set by the reader thread, polled by the # resync and merge thread. self._resync_requested = False
def setUp(self): super(TestRateStat, self).setUp() self.stat = RateStat("foo")