tglman / persy
Showing 1 of 1 files from the diff.

@@ -33,7 +33,9 @@
Loading
33 33
34 34
    fn put(&mut self, key: u64, value: ReadPage) {
35 35
        self.size += 1 << value.get_size_exp();
36 -
        self.cache.insert(key, value);
36 +
        if let Some(pre) = self.cache.insert(key, value) {
37 +
            self.size -= 1 << pre.get_size_exp();
38 +
        }
37 39
        while self.size > self.limit {
38 40
            if let Some(en) = self.cache.pop_front() {
39 41
                self.size -= 1 << en.1.get_size_exp();
@@ -42,8 +44,11 @@
Loading
42 44
            }
43 45
        }
44 46
    }
47 +
45 48
    fn remove(&mut self, key: u64) {
46 -
        self.cache.remove(&key);
49 +
        if let Some(removed) = self.cache.remove(&key) {
50 +
            self.size -= 1 << removed.get_size_exp();
51 +
        }
47 52
    }
48 53
}
49 54
@@ -550,4 +555,30 @@
Loading
550 555
        let read_list = FreeList::read_free_list(&buf);
551 556
        assert_eq!(list, read_list);
552 557
    }
558 +
559 +
    #[test]
560 +
    fn test_cache_limit_remove() {
561 +
        let mut cache = Cache::new(1050 as u64);
562 +
        cache.put(10, ReadPage::new(Arc::new(Vec::new()), 0, 10, 9));
563 +
        cache.put(20, ReadPage::new(Arc::new(Vec::new()), 0, 10, 9));
564 +
        cache.put(30, ReadPage::new(Arc::new(Vec::new()), 0, 10, 9));
565 +
        assert!(cache.size < 1050);
566 +
        assert_eq!(cache.cache.len(), 2);
567 +
        cache.remove(20);
568 +
        cache.remove(30);
569 +
        assert_eq!(cache.size, 0);
570 +
    }
571 +
572 +
    #[test]
573 +
    fn test_cache_replace_limit_stay() {
574 +
        let mut cache = Cache::new(100000 as u64);
575 +
        cache.put(10, ReadPage::new(Arc::new(Vec::new()), 0, 10, 9));
576 +
        cache.put(20, ReadPage::new(Arc::new(Vec::new()), 0, 10, 9));
577 +
        cache.put(30, ReadPage::new(Arc::new(Vec::new()), 0, 10, 9));
578 +
        let pre = cache.size;
579 +
        cache.put(20, ReadPage::new(Arc::new(Vec::new()), 0, 10, 9));
580 +
        assert_eq!(cache.size, pre);
581 +
        cache.put(20, ReadPage::new(Arc::new(Vec::new()), 0, 10, 10));
582 +
        assert_eq!(cache.size, pre - (1 << 9) + (1 << 10));
583 +
    }
553 584
}
Files Coverage
src 91.81%
tests 98.91%
Project Totals (37 files) 93.11%
Notifications are pending CI completion. Waiting for GitLab's status webhook to queue notifications. Push notifications now.
1
coverage:
2
  status:
3
    project:
4
      default:
5
        target: 80%
6
        threshold: 1.0%
7
    patch: off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading