Skip to content

Commit

Permalink
Add initial test
Browse files Browse the repository at this point in the history
  • Loading branch information
JHawk0224 committed Dec 12, 2023
1 parent 11d7232 commit 7a304b7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,41 @@ async fn main() {
}
}
}

#[cfg(test)]
mod tests {
use std::thread;

use super::*;

fn run_kafka(lead_addr: ServerId) {
let partition_count: usize = 3;
let broker_count: usize = 3;
let broker_ids = (0..broker_count)
.map(|i| (8080 + i) as u16)
.collect::<Vec<_>>();
let broker_ids_clone = broker_ids.clone();
tokio::spawn(async move {
BrokerLead::new(lead_addr, broker_ids_clone, partition_count)
.listen()
.await;
});
for broker_id in broker_ids {
tokio::spawn(async move {
Broker::new(broker_id).listen().await;
});
}
}

#[tokio::test]
async fn test_producer() {
// WOULD BE SPUN UP IN BACKGROUND FOR RUNNING KAFKA, NOT BY CLIENT
let lead_addr: ServerId = 8000;
run_kafka(lead_addr);

// How a client would make a producer
let mut producer = Producer::new(lead_addr).await;
producer.add_topic("Best foods".to_string()).await.unwrap();
producer.send_message("Best foods".to_string(), "pizza is a good food".to_string()).await.unwrap();
}
}

0 comments on commit 7a304b7

Please sign in to comment.