• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

getdozer / dozer / 4075835066

pending completion
4075835066

Pull #790

github

GitHub
Merge 39f3c7143 into 3223082a5
Pull Request #790: refactor: Use `daggy` for the underlying data structure of `Dag`

396 of 396 new or added lines in 11 files covered. (100.0%)

24551 of 36528 relevant lines covered (67.21%)

54898.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.54
/dozer-sql/src/pipeline/tests/builder_test.rs
1
use dozer_core::dag::app::App;
2
use dozer_core::dag::appsource::{AppSource, AppSourceManager};
3
use dozer_core::dag::channels::SourceChannelForwarder;
4
use dozer_core::dag::dag::DEFAULT_PORT_HANDLE;
5
use dozer_core::dag::errors::ExecutionError;
6
use dozer_core::dag::executor::{DagExecutor, ExecutorOptions};
7
use dozer_core::dag::node::{
8
    OutputPortDef, OutputPortType, PortHandle, Sink, SinkFactory, Source, SourceFactory,
9
};
10
use dozer_core::dag::record_store::RecordReader;
11
use dozer_core::storage::lmdb_storage::{LmdbEnvironmentManager, SharedTransaction};
12
use dozer_types::log::debug;
13
use dozer_types::ordered_float::OrderedFloat;
14
use dozer_types::types::{
15
    Field, FieldDefinition, FieldType, Operation, Record, Schema, SourceDefinition,
16
};
17

18
use dozer_core::dag::epoch::Epoch;
19

20
use std::collections::HashMap;
21
use std::fs;
22

23
use std::sync::atomic::AtomicBool;
24
use std::sync::Arc;
25
use tempdir::TempDir;
26

27
use crate::pipeline::builder::{statement_to_pipeline, SchemaSQLContext};
28

29
/// Test Source
30
#[derive(Debug)]
×
31
pub struct TestSourceFactory {
32
    output_ports: Vec<PortHandle>,
33
}
34

35
impl TestSourceFactory {
36
    pub fn new(output_ports: Vec<PortHandle>) -> Self {
1✔
37
        Self { output_ports }
1✔
38
    }
1✔
39
}
40

41
impl SourceFactory<SchemaSQLContext> for TestSourceFactory {
42
    fn get_output_ports(&self) -> Result<Vec<OutputPortDef>, ExecutionError> {
3✔
43
        Ok(self
3✔
44
            .output_ports
3✔
45
            .iter()
3✔
46
            .map(|e| OutputPortDef::new(*e, OutputPortType::Stateless))
3✔
47
            .collect())
3✔
48
    }
3✔
49

50
    fn get_output_schema(
1✔
51
        &self,
1✔
52
        _port: &PortHandle,
1✔
53
    ) -> Result<(Schema, SchemaSQLContext), ExecutionError> {
1✔
54
        Ok((
1✔
55
            Schema::empty()
1✔
56
                .field(
1✔
57
                    FieldDefinition::new(
1✔
58
                        String::from("CustomerID"),
1✔
59
                        FieldType::Int,
1✔
60
                        false,
1✔
61
                        SourceDefinition::Dynamic,
1✔
62
                    ),
1✔
63
                    false,
1✔
64
                )
1✔
65
                .field(
1✔
66
                    FieldDefinition::new(
1✔
67
                        String::from("Country"),
1✔
68
                        FieldType::String,
1✔
69
                        false,
1✔
70
                        SourceDefinition::Dynamic,
1✔
71
                    ),
1✔
72
                    false,
1✔
73
                )
1✔
74
                .field(
1✔
75
                    FieldDefinition::new(
1✔
76
                        String::from("Spending"),
1✔
77
                        FieldType::Float,
1✔
78
                        false,
1✔
79
                        SourceDefinition::Dynamic,
1✔
80
                    ),
1✔
81
                    false,
1✔
82
                )
1✔
83
                .clone(),
1✔
84
            SchemaSQLContext::default(),
1✔
85
        ))
1✔
86
    }
1✔
87

88
    fn build(
1✔
89
        &self,
1✔
90
        _output_schemas: HashMap<PortHandle, Schema>,
1✔
91
    ) -> Result<Box<dyn Source>, ExecutionError> {
1✔
92
        Ok(Box::new(TestSource {}))
1✔
93
    }
1✔
94

95
    fn prepare(
×
96
        &self,
×
97
        _output_schemas: HashMap<PortHandle, (Schema, SchemaSQLContext)>,
×
98
    ) -> Result<(), ExecutionError> {
×
99
        Ok(())
×
100
    }
×
101
}
102

103
#[derive(Debug)]
×
104
pub struct TestSource {}
105

106
impl Source for TestSource {
107
    fn start(
1✔
108
        &self,
1✔
109
        fw: &mut dyn SourceChannelForwarder,
1✔
110
        _from_seq: Option<(u64, u64)>,
1✔
111
    ) -> Result<(), ExecutionError> {
1✔
112
        for n in 0..10000 {
10,001✔
113
            fw.send(
10,000✔
114
                n,
10,000✔
115
                0,
10,000✔
116
                Operation::Insert {
10,000✔
117
                    new: Record::new(
10,000✔
118
                        None,
10,000✔
119
                        vec![
10,000✔
120
                            Field::Int(0),
10,000✔
121
                            Field::String("Italy".to_string()),
10,000✔
122
                            Field::Float(OrderedFloat(5.5)),
10,000✔
123
                        ],
10,000✔
124
                        None,
10,000✔
125
                    ),
10,000✔
126
                },
10,000✔
127
                DEFAULT_PORT_HANDLE,
10,000✔
128
            )
10,000✔
129
            .unwrap();
10,000✔
130
        }
10,000✔
131
        Ok(())
1✔
132
    }
1✔
133
}
134

135
#[derive(Debug)]
×
136
pub struct TestSinkFactory {
137
    input_ports: Vec<PortHandle>,
138
}
139

140
impl TestSinkFactory {
141
    pub fn new(input_ports: Vec<PortHandle>) -> Self {
1✔
142
        Self { input_ports }
1✔
143
    }
1✔
144
}
145

146
impl SinkFactory<SchemaSQLContext> for TestSinkFactory {
147
    fn get_input_ports(&self) -> Vec<PortHandle> {
2✔
148
        self.input_ports.clone()
2✔
149
    }
2✔
150

151
    fn build(
1✔
152
        &self,
1✔
153
        _input_schemas: HashMap<PortHandle, Schema>,
1✔
154
    ) -> Result<Box<dyn Sink>, ExecutionError> {
1✔
155
        Ok(Box::new(TestSink {}))
1✔
156
    }
1✔
157

158
    fn prepare(
×
159
        &self,
×
160
        _input_schemas: HashMap<PortHandle, (Schema, SchemaSQLContext)>,
×
161
    ) -> Result<(), ExecutionError> {
×
162
        Ok(())
×
163
    }
×
164
}
165

×
166
#[derive(Debug)]
×
167
pub struct TestSink {}
×
168

×
169
impl Sink for TestSink {
×
170
    fn init(&mut self, _env: &mut LmdbEnvironmentManager) -> Result<(), ExecutionError> {
1✔
171
        debug!("SINK: Initialising TestSink");
1✔
172
        Ok(())
1✔
173
    }
1✔
174

175
    fn process(
1✔
176
        &mut self,
1✔
177
        _from_port: PortHandle,
1✔
178
        _op: Operation,
1✔
179
        _state: &SharedTransaction,
1✔
180
        _reader: &HashMap<PortHandle, Box<dyn RecordReader>>,
1✔
181
    ) -> Result<(), ExecutionError> {
1✔
182
        Ok(())
1✔
183
    }
1✔
184

×
185
    fn commit(&mut self, _epoch: &Epoch, _tx: &SharedTransaction) -> Result<(), ExecutionError> {
1✔
186
        Ok(())
1✔
187
    }
1✔
188
}
×
189

×
190
#[test]
1✔
191
fn test_pipeline_builder() {
1✔
192
    let (mut pipeline, (node, node_port)) = statement_to_pipeline(
1✔
193
        "SELECT COUNT(Spending), users.Country \
1✔
194
    FROM users \
1✔
195
    WHERE Spending >= 1",
1✔
196
    )
1✔
197
    .unwrap();
1✔
198

1✔
199
    let mut asm = AppSourceManager::new();
1✔
200
    asm.add(AppSource::new(
1✔
201
        "mem".to_string(),
1✔
202
        Arc::new(TestSourceFactory::new(vec![DEFAULT_PORT_HANDLE])),
1✔
203
        vec![("users".to_string(), DEFAULT_PORT_HANDLE)]
1✔
204
            .into_iter()
1✔
205
            .collect(),
1✔
206
    ))
1✔
207
    .unwrap();
1✔
208

1✔
209
    pipeline.add_sink(
1✔
210
        Arc::new(TestSinkFactory::new(vec![DEFAULT_PORT_HANDLE])),
1✔
211
        "sink",
1✔
212
    );
1✔
213
    pipeline
1✔
214
        .connect_nodes(&node, Some(node_port), "sink", Some(DEFAULT_PORT_HANDLE))
1✔
215
        .unwrap();
1✔
216

1✔
217
    let mut app = App::new(asm);
1✔
218
    app.add_pipeline(pipeline);
1✔
219

1✔
220
    let dag = app.get_dag().unwrap();
1✔
221

1✔
222
    let tmp_dir = TempDir::new("example").unwrap_or_else(|_e| panic!("Unable to create temp dir"));
1✔
223
    if tmp_dir.path().exists() {
1✔
224
        fs::remove_dir_all(tmp_dir.path()).unwrap_or_else(|_e| panic!("Unable to remove old dir"));
1✔
225
    }
1✔
226
    fs::create_dir(tmp_dir.path()).unwrap_or_else(|_e| panic!("Unable to create temp dir"));
1✔
227

1✔
228
    use std::time::Instant;
1✔
229
    let now = Instant::now();
1✔
230

1✔
231
    let tmp_dir = TempDir::new("test").unwrap();
1✔
232
    let mut executor = DagExecutor::new(
1✔
233
        &dag,
1✔
234
        tmp_dir.path(),
1✔
235
        ExecutorOptions::default(),
1✔
236
        Arc::new(AtomicBool::new(true)),
1✔
237
    )
1✔
238
    .unwrap();
1✔
239

1✔
240
    executor
1✔
241
        .start()
1✔
242
        .unwrap_or_else(|e| panic!("Unable to start the Executor: {e}"));
1✔
243
    assert!(executor.join().is_ok());
1✔
244

×
245
    let elapsed = now.elapsed();
1✔
246
    debug!("Elapsed: {:.2?}", elapsed);
1✔
247
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc