LCOV - code coverage report
Current view: top level - source/extensions/config_subscription/grpc - pausable_ack_queue.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 41 45 91.1 %
Date: 2024-01-05 06:35:25 Functions: 9 9 100.0 %

          Line data    Source code
       1             : #include "source/extensions/config_subscription/grpc/pausable_ack_queue.h"
       2             : 
       3             : #include <list>
       4             : 
       5             : #include "source/common/common/assert.h"
       6             : 
       7             : namespace Envoy {
       8             : namespace Config {
       9             : 
      10         134 : void PausableAckQueue::push(UpdateAck x) { storage_.push_back(std::move(x)); }
      11             : 
      12         535 : size_t PausableAckQueue::size() const { return storage_.size(); }
      13             : 
      14         975 : bool PausableAckQueue::empty() {
      15         975 :   for (const auto& entry : storage_) {
      16         268 :     if (pauses_[entry.type_url_] == 0) {
      17         268 :       return false;
      18         268 :     }
      19         268 :   }
      20         707 :   return true;
      21         975 : }
      22             : 
      23             : // In the event of a reconnection, clear all the cached nonces.
      24          18 : void PausableAckQueue::clear() { storage_.clear(); }
      25             : 
      26         134 : const UpdateAck& PausableAckQueue::front() {
      27         134 :   for (const auto& entry : storage_) {
      28         134 :     if (pauses_[entry.type_url_] == 0) {
      29         134 :       return entry;
      30         134 :     }
      31         134 :   }
      32           0 :   PANIC("front() on an empty queue is undefined behavior!");
      33           0 : }
      34             : 
      35         134 : UpdateAck PausableAckQueue::popFront() {
      36         134 :   for (auto it = storage_.begin(); it != storage_.end(); ++it) {
      37         134 :     if (pauses_[it->type_url_] == 0) {
      38         134 :       UpdateAck ret = *it;
      39         134 :       storage_.erase(it);
      40         134 :       return ret;
      41         134 :     }
      42         134 :   }
      43           0 :   PANIC("popFront() on an empty queue is undefined behavior!");
      44           0 : }
      45             : 
      46         297 : void PausableAckQueue::pause(const std::string& type_url) {
      47             :   // It's ok to pause a subscription that doesn't exist yet.
      48         297 :   auto& pause_entry = pauses_[type_url];
      49         297 :   ++pause_entry;
      50         297 : }
      51             : 
      52         297 : void PausableAckQueue::resume(const std::string& type_url) {
      53         297 :   auto& pause_entry = pauses_[type_url];
      54         297 :   ASSERT(pause_entry > 0);
      55         297 :   --pause_entry;
      56         297 : }
      57             : 
      58         409 : bool PausableAckQueue::paused(const std::string& type_url) const {
      59         409 :   auto entry = pauses_.find(type_url);
      60         409 :   if (entry == pauses_.end()) {
      61          72 :     return false;
      62          72 :   }
      63         337 :   return entry->second > 0;
      64         409 : }
      65             : 
      66             : } // namespace Config
      67             : } // namespace Envoy

Generated by: LCOV version 1.15