Coverage Report

Created: 2025-06-24 08:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/build/source/nativelink-store/src/store_manager.rs
Line
Count
Source
1
// Copyright 2024 The NativeLink Authors. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//    http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
use std::collections::HashMap;
16
17
use nativelink_metric::{MetricsComponent, RootMetricsComponent};
18
use nativelink_util::store_trait::Store;
19
use parking_lot::RwLock;
20
21
#[derive(Debug, Default, MetricsComponent)]
22
pub struct StoreManager {
23
    #[metric]
24
    stores: RwLock<HashMap<String, Store>>,
25
}
26
27
impl StoreManager {
28
36
    pub fn new() -> Self {
29
36
        Self {
30
36
            stores: RwLock::new(HashMap::new()),
31
36
        }
32
36
    }
33
34
45
    pub fn add_store(&self, name: &str, store: Store) {
35
45
        let mut stores = self.stores.write();
36
45
        stores.insert(name.to_string(), store);
37
45
    }
38
39
59
    pub fn get_store(&self, name: &str) -> Option<Store> {
40
59
        let stores = self.stores.read();
41
59
        if let Some(store) = stores.get(name) {
  Branch (41:16): [True: 59, False: 0]
  Branch (41:16): [Folded - Ignored]
42
59
            return Some(store.clone());
43
0
        }
44
0
        None
45
59
    }
46
}
47
48
impl RootMetricsComponent for StoreManager {}