noop/
lib.rs

1use foundationdb_simulation::{
2    register_factory, Metric, Metrics, RustWorkload, RustWorkloadFactory, Severity, SimDatabase,
3    WorkloadContext, WrappedWorkload,
4};
5
6struct NoopWorkload {
7    name: String,
8    client_id: i32,
9    context: WorkloadContext,
10}
11
12impl RustWorkload for NoopWorkload {
13    async fn setup(&mut self, _db: SimDatabase) {
14        println!("rust_setup({}_{})", self.name, self.client_id);
15        self.context.trace(
16            Severity::Debug,
17            "Test",
18            &[("Layer", "Rust"), ("Stage", "Setup")],
19        );
20    }
21    async fn start(&mut self, _db: SimDatabase) {
22        println!("rust_start({}_{})", self.name, self.client_id);
23        self.context.trace(
24            Severity::Debug,
25            "Test",
26            &[("Layer", "Rust"), ("Stage", "Start")],
27        );
28    }
29    async fn check(&mut self, _db: SimDatabase) {
30        println!("rust_check({}_{})", self.name, self.client_id);
31        self.context.trace(
32            Severity::Debug,
33            "Test",
34            &[("Layer", "Rust"), ("Stage", "Check")],
35        );
36    }
37    fn get_metrics(&self, mut out: Metrics) {
38        println!("rust_get_metrics({}_{})", self.name, self.client_id);
39        out.reserve(8);
40        out.push(Metric::val("test", 42));
41    }
42    fn get_check_timeout(&self) -> f64 {
43        println!("rust_get_check_timeout({}_{})", self.name, self.client_id);
44        3000.
45    }
46}
47impl NoopWorkload {
48    fn new(name: String, client_id: i32, context: WorkloadContext) -> Self {
49        Self {
50            name,
51            client_id,
52            context,
53        }
54    }
55}
56impl Drop for NoopWorkload {
57    fn drop(&mut self) {
58        println!("rust_free({}_{})", self.name, self.client_id);
59    }
60}
61
62struct NoopFactory;
63impl RustWorkloadFactory for NoopFactory {
64    fn create(name: String, context: WorkloadContext) -> WrappedWorkload {
65        let client_id = context.client_id();
66        let client_count = context.client_count();
67        println!("RustWorkloadFactory::create({name})[{client_id}/{client_count}]");
68        println!(
69            "my_c_option: {:?}",
70            context.get_option::<String>("my_c_option")
71        );
72        println!(
73            "my_c_option: {:?}",
74            context.get_option::<String>("my_c_option")
75        );
76        match name.as_str() {
77            "NoopWorkload" => WrappedWorkload::new(NoopWorkload::new(name, client_id, context)),
78            _ => panic!("Unknown workload name: {name}"),
79        }
80    }
81}
82
83register_factory!(NoopFactory);