1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
pub mod epoch;
pub mod core;
pub mod store;
#[cfg(feature = "k8")]
pub use k8_types;
#[cfg(test)]
pub(crate) mod test_fixture {
use crate::core::{Spec, Status, MetadataItem, MetadataContext, MetadataRevExtension};
use crate::store::MetadataStoreObject;
use crate::epoch::DualEpochMap;
#[derive(Debug, Default, Clone, PartialEq)]
pub struct TestSpec {
pub replica: u16,
}
impl Spec for TestSpec {
const LABEL: &'static str = "Test";
type IndexKey = String;
type Owner = Self;
type Status = TestStatus;
}
#[derive(Debug, Default, Clone, PartialEq)]
pub struct TestStatus {
pub up: bool,
}
impl Status for TestStatus {}
pub type DefaultTest = MetadataStoreObject<TestSpec, TestMeta>;
pub type TestEpochMap = DualEpochMap<String, DefaultTest>;
#[derive(Debug, Default, PartialEq, Clone)]
pub struct TestMeta {
pub rev: u32,
pub comment: String,
}
impl MetadataItem for TestMeta {
type UId = u32;
fn uid(&self) -> &Self::UId {
&self.rev
}
fn is_newer(&self, another: &Self) -> bool {
self.rev >= another.rev
}
}
impl MetadataRevExtension for TestMeta {
fn next_rev(&self) -> Self {
Self {
rev: self.rev + 1,
comment: self.comment.clone(),
}
}
}
impl TestMeta {
pub fn new(rev: u32) -> Self {
Self {
rev,
comment: "new".to_owned(),
}
}
}
impl From<u32> for MetadataContext<TestMeta> {
fn from(val: u32) -> MetadataContext<TestMeta> {
TestMeta::new(val).into()
}
}
}