clicktype-batch 0.2.0

Async batching system for ClickType with backpressure and metrics
Documentation
//! Example demonstrating the use of MockClient for testing

#[cfg(feature = "mock")]
mod mock_test {
    use clicktype_batch::{GenericBatcher, BatchConfig};
    use clicktype_transport::MockClient;
    use clicktype_macros::ClickTable;
    use std::time::Duration;

    #[derive(ClickTable, Clone)]
    #[click_table(name = "test_events")]
    pub struct TestEvent {
        #[click_column(primary_key)]
        pub id: u64,
        pub info: String,
    }

    #[tokio::test]
    async fn test_mock_ingestion() {
        // 1. Create a MockClient instead of a real Client
        let mock_client = MockClient::new();

        // 2. Configure batcher with the mock client
        // Note: We use GenericBatcher explicitly to use the mock
        let config = BatchConfig {
            max_rows: 10,
            max_wait: Duration::from_millis(100),
            ..Default::default()
        };

        let batcher = GenericBatcher::<TestEvent, MockClient>::new(mock_client.clone(), config);
        let (handle, worker) = batcher.spawn();

        // 3. Insert data normally
        for i in 0..15 {
            handle.insert(TestEvent {
                id: i,
                info: format!("Event {}", i),
            }).await.unwrap();
        }

        // 4. Close and wait
        handle.close().await.unwrap();
        worker.await.unwrap();

        // 5. Verify results using the mock
        assert!(mock_client.was_schema_validated("test_events"));
        
        // We expect 2 batches: one with 10 rows (max_rows), one with 5 rows (flush on close)
        assert_eq!(mock_client.inserted_count(), 2);
        
        println!("✓ Mock test passed: 15 rows inserted in 2 batches verified.");
    }
}