Exemplo n.º 1
0
    def __init__(self,
                 inbox,
                 config,
                 http_client,
                 diagnostic_accumulator=None):
        self._inbox = inbox
        self._config = config
        self._http = _http_factory(config).create_pool_manager(
            1, config.events_uri) if http_client is None else http_client
        self._close_http = (http_client is None
                            )  # so we know whether to close it later
        self._disabled = False
        self._outbox = EventBuffer(config.events_max_pending)
        self._user_keys = SimpleLRUCache(config.user_keys_capacity)
        self._formatter = EventOutputFormatter(config)
        self._last_known_past_time = 0
        self._deduplicated_users = 0
        self._diagnostic_accumulator = None if config.diagnostic_opt_out else diagnostic_accumulator

        self._flush_workers = FixedThreadPool(__MAX_FLUSH_THREADS__,
                                              "ldclient.flush")
        self._diagnostic_flush_workers = None if self._diagnostic_accumulator is None else FixedThreadPool(
            1, "ldclient.diag_flush")
        if self._diagnostic_accumulator is not None:
            init_event = create_diagnostic_init(
                self._diagnostic_accumulator.data_since_date,
                self._diagnostic_accumulator.diagnostic_id, config)
            task = DiagnosticEventSendTask(self._http, self._config,
                                           init_event)
            self._diagnostic_flush_workers.execute(task.run)

        self._main_thread = Thread(target=self._run_main_loop)
        self._main_thread.daemon = True
        self._main_thread.start()
Exemplo n.º 2
0
def test_retains_values_up_to_capacity():
    lru = SimpleLRUCache(3)
    assert lru.put("a", True) == False
    assert lru.put("b", True) == False
    assert lru.put("c", True) == False
    assert lru.put("a", True) == True
    assert lru.put("b", True) == True
    assert lru.put("c", True) == True
Exemplo n.º 3
0
def test_discards_oldest_value_on_overflow():
    lru = SimpleLRUCache(2)
    assert lru.put("a", True) == False
    assert lru.put("b", True) == False
    assert lru.put("c", True) == False
    assert lru.get("a") is None
    assert lru.get("b") == True
    assert lru.get("c") == True
Exemplo n.º 4
0
def test_value_becomes_new_on_replace():
    lru = SimpleLRUCache(2)
    assert lru.put("a", True) == False
    assert lru.put("b", True) == False
    assert lru.put("a", True) == True  # b is now oldest
    assert lru.put("c", True) == False  # b is discarded as oldest
    assert lru.get("a") is True
    assert lru.get("b") is None
    assert lru.get("c") is True
Exemplo n.º 5
0
    def __init__(self, queue, config, http_client):
        self._queue = queue
        self._config = config
        self._http = create_http_pool_manager(num_pools=1, verify_ssl=config.verify_ssl) if http_client is None else http_client
        self._close_http = (http_client is None)  # so we know whether to close it later
        self._disabled = False
        self._buffer = EventBuffer(config.events_max_pending)
        self._user_keys = SimpleLRUCache(config.user_keys_capacity)
        self._formatter = EventOutputFormatter(config)
        self._last_known_past_time = 0

        self._flush_workers = FixedThreadPool(__MAX_FLUSH_THREADS__, "ldclient.flush")

        self._main_thread = Thread(target=self._run_main_loop)
        self._main_thread.daemon = True
        self._main_thread.start()