reifydb_sub_flow/operator/stateful/
test_utils.rs1pub mod test {
5 use reifydb_core::{
6 encoded::{key::EncodedKey, row::EncodedRow, shape::RowShape},
7 interface::{catalog::flow::FlowNodeId, change::Change},
8 value::column::columns::Columns,
9 };
10 use reifydb_engine::test_harness::TestEngine;
11 use reifydb_transaction::transaction::admin::AdminTransaction;
12 use reifydb_type::{
13 Result,
14 util::cowvec::CowVec,
15 value::{identity::IdentityId, row_number::RowNumber, r#type::Type},
16 };
17
18 use crate::{operator::Operator, transaction::FlowTransaction};
19
20 pub struct TestOperator {
22 pub id: FlowNodeId,
23 pub layout: RowShape,
24 pub key_types: Vec<Type>,
25 }
26
27 impl TestOperator {
28 pub fn new(id: FlowNodeId) -> Self {
30 Self {
31 id,
32 layout: RowShape::testing(&[Type::Int8, Type::Float8, Type::Utf8]),
33 key_types: vec![Type::Utf8, Type::Int4],
34 }
35 }
36
37 pub fn simple(id: FlowNodeId) -> Self {
39 Self {
40 id,
41 layout: RowShape::testing(&[Type::Int8]),
42 key_types: vec![],
43 }
44 }
45
46 pub fn with_key_types(id: FlowNodeId, key_types: Vec<Type>) -> Self {
48 Self {
49 id,
50 layout: RowShape::testing(&[Type::Blob, Type::Int4]),
51 key_types,
52 }
53 }
54 }
55
56 impl Operator for TestOperator {
57 fn id(&self) -> FlowNodeId {
58 self.id
59 }
60
61 fn apply(&self, _txn: &mut FlowTransaction, _change: Change) -> Result<Change> {
62 todo!()
63 }
64
65 fn pull(&self, _txn: &mut FlowTransaction, _rows: &[RowNumber]) -> Result<Columns> {
66 unimplemented!()
67 }
68 }
69
70 pub fn test_row() -> EncodedRow {
72 EncodedRow(CowVec::new(vec![1, 2, 3, 4, 5]))
73 }
74
75 pub fn test_key(suffix: &str) -> EncodedKey {
77 EncodedKey::new(format!("test_{}", suffix).into_bytes())
78 }
79
80 pub fn assert_row_eq(actual: &EncodedRow, expected: &EncodedRow) {
82 assert_eq!(actual.to_vec(), expected.to_vec(), "Rows do not match");
83 }
84
85 pub fn create_test_transaction() -> AdminTransaction {
87 let t = TestEngine::new();
88 t.begin_admin(IdentityId::system()).unwrap()
89 }
90}