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
81
82
83
84
85
86
87
use re_log_types::DataTable;

use crate::{DataStore, DataStoreConfig, WriteError};

// ---

#[doc(hidden)]
#[macro_export]
macro_rules! test_row {
    ($entity:ident => [$c0:expr $(,)*]) => {{
        ::re_log_types::DataRow::from_cells1_sized(
            ::re_log_types::RowId::new(),
            $entity.clone(),
            ::re_log_types::TimePoint::default(),
            $c0,
        )
        .unwrap()
    }};
    ($entity:ident @ $frames:tt => [$c0:expr $(,)*]) => {{
        ::re_log_types::DataRow::from_cells1_sized(
            ::re_log_types::RowId::new(),
            $entity.clone(),
            $frames,
            $c0,
        )
        .unwrap()
    }};
    ($entity:ident @ $frames:tt => [$c0:expr, $c1:expr $(,)*]) => {{
        ::re_log_types::DataRow::from_cells2_sized(
            ::re_log_types::RowId::new(),
            $entity.clone(),
            $frames,
            ($c0, $c1),
        )
        .unwrap()
    }};
}

pub fn all_configs() -> impl Iterator<Item = DataStoreConfig> {
    const INDEX_CONFIGS: &[DataStoreConfig] = &[
        DataStoreConfig::DEFAULT,
        DataStoreConfig {
            indexed_bucket_num_rows: 0,
            ..DataStoreConfig::DEFAULT
        },
        DataStoreConfig {
            indexed_bucket_num_rows: 1,
            ..DataStoreConfig::DEFAULT
        },
        DataStoreConfig {
            indexed_bucket_num_rows: 2,
            ..DataStoreConfig::DEFAULT
        },
        DataStoreConfig {
            indexed_bucket_num_rows: 3,
            ..DataStoreConfig::DEFAULT
        },
    ];
    INDEX_CONFIGS.iter().map(|idx| DataStoreConfig {
        indexed_bucket_num_rows: idx.indexed_bucket_num_rows,
        store_insert_ids: idx.store_insert_ids,
    })
}

pub fn sanity_unwrap(store: &DataStore) {
    if let err @ Err(_) = store.sanity_check() {
        store.sort_indices_if_needed();
        eprintln!("{store}");
        err.unwrap();
    }
}

// We very often re-use RowIds when generating test data.
pub fn insert_table_with_retries(store: &mut DataStore, table: &DataTable) {
    for row in table.to_rows() {
        let mut row = row.unwrap();
        loop {
            match store.insert_row(&row) {
                Ok(_) => break,
                Err(WriteError::ReusedRowId(_)) => {
                    row.row_id = row.row_id.next();
                }
                err @ Err(_) => err.map(|_| ()).unwrap(),
            }
        }
    }
}