Coverage Report

Created: 2025-12-17 22:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/build/source/nativelink-store/src/noop_store.rs
Line
Count
Source
1
// Copyright 2024 The NativeLink Authors. All rights reserved.
2
//
3
// Licensed under the Functional Source License, Version 1.1, Apache 2.0 Future License (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
//    See LICENSE file for details
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 core::pin::Pin;
16
use std::sync::Arc;
17
18
use async_trait::async_trait;
19
use nativelink_error::{Code, Error, ResultExt, make_err};
20
use nativelink_metric::{
21
    MetricFieldData, MetricKind, MetricPublishKnownKindData, MetricsComponent,
22
};
23
use nativelink_util::buf_channel::{DropCloserReadHalf, DropCloserWriteHalf};
24
use nativelink_util::health_utils::{HealthStatusIndicator, default_health_status_indicator};
25
use nativelink_util::store_trait::{
26
    RemoveItemCallback, StoreDriver, StoreKey, StoreOptimizations, UploadSizeInfo,
27
};
28
29
#[derive(Debug, Default, Clone, Copy)]
30
pub struct NoopStore;
31
32
impl MetricsComponent for NoopStore {
33
0
    fn publish(
34
0
        &self,
35
0
        _kind: MetricKind,
36
0
        _field_metadata: MetricFieldData,
37
0
    ) -> Result<MetricPublishKnownKindData, nativelink_metric::Error> {
38
0
        Ok(MetricPublishKnownKindData::Component)
39
0
    }
40
}
41
42
impl NoopStore {
43
1
    pub fn new() -> Arc<Self> {
44
1
        Arc::new(Self {})
45
1
    }
46
}
47
48
#[async_trait]
49
impl StoreDriver for NoopStore {
50
    async fn has_with_results(
51
        self: Pin<&Self>,
52
        _keys: &[StoreKey<'_>],
53
        results: &mut [Option<u64>],
54
0
    ) -> Result<(), Error> {
55
        for result in results.iter_mut() {
56
            *result = None;
57
        }
58
        Ok(())
59
0
    }
60
61
    async fn update(
62
        self: Pin<&Self>,
63
        _key: StoreKey<'_>,
64
        mut reader: DropCloserReadHalf,
65
        _size_info: UploadSizeInfo,
66
0
    ) -> Result<(), Error> {
67
        // We need to drain the reader to avoid the writer complaining that we dropped
68
        // the connection prematurely.
69
        reader.drain().await.err_tip(|| "In NoopStore::update")?;
70
        Ok(())
71
0
    }
72
73
2
    fn optimized_for(&self, optimization: StoreOptimizations) -> bool {
74
2
        optimization == StoreOptimizations::NoopUpdates
  Branch (74:9): [True: 0, False: 2]
  Branch (74:9): [Folded - Ignored]
75
2
            || optimization == StoreOptimizations::NoopDownloads
76
2
    }
77
78
    async fn get_part(
79
        self: Pin<&Self>,
80
        _key: StoreKey<'_>,
81
        _writer: &mut DropCloserWriteHalf,
82
        _offset: u64,
83
        _length: Option<u64>,
84
0
    ) -> Result<(), Error> {
85
        Err(make_err!(Code::NotFound, "Not found in noop store"))
86
0
    }
87
88
2
    fn inner_store(&self, _key: Option<StoreKey>) -> &dyn StoreDriver {
89
2
        self
90
2
    }
91
92
0
    fn as_any<'a>(&'a self) -> &'a (dyn core::any::Any + Sync + Send + 'static) {
93
0
        self
94
0
    }
95
96
0
    fn as_any_arc(self: Arc<Self>) -> Arc<dyn core::any::Any + Sync + Send + 'static> {
97
0
        self
98
0
    }
99
100
0
    fn register_remove_callback(
101
0
        self: Arc<Self>,
102
0
        _callback: Arc<dyn RemoveItemCallback>,
103
0
    ) -> Result<(), Error> {
104
        // does nothing, so drop
105
0
        Ok(())
106
0
    }
107
}
108
109
default_health_status_indicator!(NoopStore);