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

getdozer / dozer / 4370280743

pending completion
4370280743

push

github

GitHub
Bump async-trait from 0.1.65 to 0.1.66 (#1179)

27808 of 38702 relevant lines covered (71.85%)

25323.55 hits per line

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

77.59
/dozer-cache/src/cache/lmdb/cache/query/tests.rs
1
use crate::cache::{
2
    expression::{FilterExpression, Operator, QueryExpression},
3
    lmdb::{
4
        cache::LmdbRwCache,
5
        tests::utils::{create_cache, insert_rec_1},
6
    },
7
    test_utils::{query_from_filter, schema_1, schema_full_text, schema_multi_indices},
8
    RecordWithId, RoCache, RwCache,
9
};
10
use dozer_types::{
11
    serde_json::{from_value, json, Value},
12
    types::{Field, Record, Schema},
13
};
14

15
#[test]
1✔
16
fn query_secondary_sorted_inverted() {
1✔
17
    let (schema, secondary_indexes) = schema_1();
1✔
18
    let cache = LmdbRwCache::create(
1✔
19
        schema.clone(),
1✔
20
        secondary_indexes,
1✔
21
        Default::default(),
1✔
22
        Default::default(),
1✔
23
    )
1✔
24
    .unwrap();
1✔
25

1✔
26
    let mut record = Record::new(
1✔
27
        schema.identifier,
1✔
28
        vec![
1✔
29
            Field::Int(1),
1✔
30
            Field::String("test".to_string()),
1✔
31
            Field::Int(2),
1✔
32
        ],
1✔
33
        None,
1✔
34
    );
1✔
35

1✔
36
    cache.insert(&mut record).unwrap();
1✔
37
    assert!(record.version.is_some());
1✔
38

×
39
    let filter = FilterExpression::And(vec![
1✔
40
        FilterExpression::Simple("a".to_string(), Operator::EQ, Value::from(1)),
1✔
41
        FilterExpression::Simple(
1✔
42
            "b".to_string(),
1✔
43
            Operator::EQ,
1✔
44
            Value::from("test".to_string()),
1✔
45
        ),
1✔
46
    ]);
1✔
47

1✔
48
    // Query with an expression
1✔
49
    let query = query_from_filter(filter);
1✔
50

1✔
51
    let records = cache.query(&query).unwrap();
1✔
52
    assert_eq!(cache.count(&query).unwrap(), 1);
1✔
53
    assert_eq!(records.len(), 1, "must be equal");
1✔
54
    assert_eq!(records[0].record, record, "must be equal");
1✔
55
}
1✔
56

×
57
#[test]
1✔
58
fn query_secondary_full_text() {
1✔
59
    let (schema, secondary_indexes) = schema_full_text();
1✔
60
    let cache = LmdbRwCache::create(
1✔
61
        schema.clone(),
1✔
62
        secondary_indexes,
1✔
63
        Default::default(),
1✔
64
        Default::default(),
1✔
65
    )
1✔
66
    .unwrap();
1✔
67

1✔
68
    let mut record = Record::new(
1✔
69
        schema.identifier,
1✔
70
        vec![
1✔
71
            Field::String("today is a good day".into()),
1✔
72
            Field::Text("marry has a little lamb".into()),
1✔
73
        ],
1✔
74
        None,
1✔
75
    );
1✔
76

1✔
77
    cache.insert(&mut record).unwrap();
1✔
78
    assert!(record.version.is_some());
1✔
79

×
80
    let filter = FilterExpression::Simple("foo".into(), Operator::Contains, "good".into());
1✔
81

1✔
82
    let query = query_from_filter(filter);
1✔
83

1✔
84
    let records = cache.query(&query).unwrap();
1✔
85
    assert_eq!(cache.count(&query).unwrap(), 1);
1✔
86
    assert_eq!(records.len(), 1);
1✔
87
    assert_eq!(records[0].record, record);
1✔
88

×
89
    let filter = FilterExpression::Simple("bar".into(), Operator::Contains, "lamb".into());
1✔
90
    let query = query_from_filter(filter);
1✔
91
    let records = cache.query(&query).unwrap();
1✔
92
    assert_eq!(cache.count(&query).unwrap(), 1);
1✔
93
    assert_eq!(records.len(), 1);
1✔
94
    assert_eq!(records[0].record, record);
1✔
95
}
1✔
96

×
97
#[test]
1✔
98
fn query_secondary_vars() {
1✔
99
    let (cache, schema, _) = create_cache(schema_1);
1✔
100

1✔
101
    let items = vec![
1✔
102
        (1, Some("yuri".to_string()), Some(521)),
1✔
103
        (2, Some("mega".to_string()), Some(521)),
1✔
104
        (3, Some("james".to_string()), Some(523)),
1✔
105
        (4, Some("james".to_string()), Some(524)),
1✔
106
        (5, Some("steff".to_string()), Some(526)),
1✔
107
        (6, Some("mega".to_string()), Some(527)),
1✔
108
        (7, Some("james".to_string()), Some(528)),
1✔
109
        (8, Some("ava".to_string()), None),
1✔
110
    ];
1✔
111
    // 26 alphabets
112
    for val in items {
9✔
113
        insert_rec_1(&cache, &schema, val);
8✔
114
    }
8✔
115

116
    test_query(json!({}), 8, &cache);
1✔
117

1✔
118
    test_query(
1✔
119
        json!({
1✔
120
            "$order_by": { "c": "desc" }
1✔
121
        }),
1✔
122
        8,
1✔
123
        &cache,
1✔
124
    );
1✔
125

1✔
126
    test_query(json!({"$filter":{ "a": {"$eq": 1}}}), 1, &cache);
1✔
127

1✔
128
    test_query(json!({"$filter":{ "a": {"$eq": null}}}), 0, &cache);
1✔
129

1✔
130
    test_query(json!({"$filter":{ "c": {"$eq": 521}}}), 2, &cache);
1✔
131

1✔
132
    test_query(json!({"$filter":{ "c": {"$eq": null}}}), 1, &cache);
1✔
133

1✔
134
    test_query(
1✔
135
        json!({"$filter":{ "a": 1, "b": "yuri".to_string()}}),
1✔
136
        1,
1✔
137
        &cache,
1✔
138
    );
1✔
139

1✔
140
    // No compound index for a,c
1✔
141
    test_query_err(json!({"$filter":{ "a": 1, "c": 521}}), &cache);
1✔
142

1✔
143
    test_query(
1✔
144
        json!({
1✔
145
            "$filter":{ "c": {"$eq": 521}},
1✔
146
            "$order_by": { "c": "asc" }
1✔
147
        }),
1✔
148
        2,
1✔
149
        &cache,
1✔
150
    );
1✔
151

1✔
152
    test_query_record(
1✔
153
        json!({
1✔
154
            "$filter":{ "a": {"$eq": 1}},
1✔
155
            "$order_by": { "b": "asc" }
1✔
156
        }),
1✔
157
        vec![(0, 1, "yuri".to_string(), 521)],
1✔
158
        &schema,
1✔
159
        &cache,
1✔
160
    );
1✔
161

1✔
162
    // Range tests
1✔
163
    test_query(json!({"$filter":{ "c": {"$lte": null}}}), 0, &cache);
1✔
164

1✔
165
    test_query(json!({"$filter":{ "c": {"$lte": 521}}}), 2, &cache);
1✔
166

1✔
167
    test_query(json!({"$filter":{ "c": {"$gte": 521}}}), 7, &cache);
1✔
168

1✔
169
    test_query(json!({"$filter":{ "c": {"$gt": 521}}}), 5, &cache);
1✔
170

1✔
171
    test_query(json!({"$filter":{ "c": {"$lte": 524}}}), 4, &cache);
1✔
172

1✔
173
    test_query(json!({"$filter":{ "c": {"$lt": 524}}}), 3, &cache);
1✔
174

1✔
175
    test_query(json!({"$filter":{ "c": {"$lt": 600}}}), 7, &cache);
1✔
176

1✔
177
    test_query(json!({"$filter":{ "c": {"$gt": 200}}}), 7, &cache);
1✔
178

1✔
179
    test_query_record(
1✔
180
        json!({
1✔
181
            "$filter":{ "c": {"$gt": 526}},
1✔
182
            "$order_by": { "c": "asc" }
1✔
183
        }),
1✔
184
        vec![
1✔
185
            (5, 6, "mega".to_string(), 527),
1✔
186
            (6, 7, "james".to_string(), 528),
1✔
187
        ],
1✔
188
        &schema,
1✔
189
        &cache,
1✔
190
    );
1✔
191

1✔
192
    test_query_record(
1✔
193
        json!({
1✔
194
            "$filter":{ "c": {"$gt": 526}},
1✔
195
            "$order_by": { "c": "desc" }
1✔
196
        }),
1✔
197
        vec![
1✔
198
            (6, 7, "james".to_string(), 528),
1✔
199
            (5, 6, "mega".to_string(), 527),
1✔
200
        ],
1✔
201
        &schema,
1✔
202
        &cache,
1✔
203
    );
1✔
204
}
1✔
205

×
206
#[test]
1✔
207
fn query_secondary_multi_indices() {
1✔
208
    let (cache, schema, _) = create_cache(schema_multi_indices);
1✔
209

×
210
    for (id, text) in [
7✔
211
        (1, "apple ball cake dance"),
1✔
212
        (2, "ball cake dance egg"),
1✔
213
        (3, "cake dance egg fish"),
1✔
214
        (4, "dance egg fish glove"),
1✔
215
        (5, "egg fish glove heart"),
1✔
216
        (6, "fish glove heart igloo"),
1✔
217
        (7, "glove heart igloo jump"),
1✔
218
    ] {
×
219
        let mut record = Record {
7✔
220
            schema_id: schema.identifier,
7✔
221
            values: vec![Field::Int(id), Field::String(text.into())],
7✔
222
            version: None,
7✔
223
        };
7✔
224
        cache.insert(&mut record).unwrap();
7✔
225
        assert!(record.version.is_some());
7✔
226
    }
×
227

×
228
    let query = query_from_filter(FilterExpression::And(vec![
1✔
229
        FilterExpression::Simple("id".into(), Operator::GT, Value::from(2)),
1✔
230
        FilterExpression::Simple("text".into(), Operator::Contains, Value::from("dance")),
1✔
231
    ]));
1✔
232

1✔
233
    let records = cache.query(&query).unwrap();
1✔
234
    assert_eq!(cache.count(&query).unwrap(), 2);
1✔
235
    assert_eq!(
1✔
236
        records,
1✔
237
        vec![
1✔
238
            RecordWithId::new(
1✔
239
                2,
1✔
240
                Record {
1✔
241
                    schema_id: schema.identifier,
1✔
242
                    values: vec![Field::Int(3), Field::String("cake dance egg fish".into())],
1✔
243
                    version: Some(1)
1✔
244
                }
1✔
245
            ),
1✔
246
            RecordWithId::new(
1✔
247
                3,
1✔
248
                Record {
1✔
249
                    schema_id: schema.identifier,
1✔
250
                    values: vec![Field::Int(4), Field::String("dance egg fish glove".into())],
1✔
251
                    version: Some(1)
1✔
252
                }
1✔
253
            ),
1✔
254
        ]
1✔
255
    );
1✔
256
}
1✔
257

×
258
fn test_query_err(query: Value, cache: &dyn RwCache) {
1✔
259
    let query = from_value::<QueryExpression>(query).unwrap();
1✔
260
    let count_result = cache.count(&query);
1✔
261
    let result = cache.query(&query);
1✔
262

×
263
    assert!(matches!(
1✔
264
        count_result.unwrap_err(),
1✔
265
        crate::errors::CacheError::Plan(_)
×
266
    ),);
×
267
    assert!(matches!(
1✔
268
        result.unwrap_err(),
1✔
269
        crate::errors::CacheError::Plan(_)
×
270
    ),);
×
271
}
1✔
272
fn test_query(query: Value, count: usize, cache: &dyn RwCache) {
16✔
273
    let query = from_value::<QueryExpression>(query).unwrap();
16✔
274
    assert_eq!(cache.count(&query).unwrap(), count);
16✔
275
    let records = cache.query(&query).unwrap();
16✔
276

16✔
277
    assert_eq!(records.len(), count, "Count must be equal : {query:?}");
16✔
278
}
16✔
279

×
280
fn test_query_record(
3✔
281
    query: Value,
3✔
282
    expected: Vec<(u64, i64, String, i64)>,
3✔
283
    schema: &Schema,
3✔
284
    cache: &dyn RwCache,
3✔
285
) {
3✔
286
    let query = from_value::<QueryExpression>(query).unwrap();
3✔
287
    assert_eq!(cache.count(&query).unwrap(), expected.len());
3✔
288
    let records = cache.query(&query).unwrap();
3✔
289
    let expected = expected
3✔
290
        .into_iter()
3✔
291
        .map(|(id, a, b, c)| {
5✔
292
            RecordWithId::new(
5✔
293
                id,
5✔
294
                Record::new(
5✔
295
                    schema.identifier,
5✔
296
                    vec![Field::Int(a), Field::String(b), Field::Int(c)],
5✔
297
                    Some(1),
5✔
298
                ),
5✔
299
            )
5✔
300
        })
5✔
301
        .collect::<Vec<_>>();
3✔
302
    assert_eq!(records, expected);
3✔
303
}
3✔
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

© 2026 Coveralls, Inc