Coverage Report

Created: 2024-10-22 12:33

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