Skip to content

Commit

Permalink
Add option to message send command to send messages from file (#1240)
Browse files Browse the repository at this point in the history
Add option for message send command which reads messages from binary
format in given file. This will allow to replay the messages stored
on the server using message poll and message send commands.
Adapt integration tests to new change. Add test scenario to verify
message replay from one topic to another using binary file.

This fixes #647
  • Loading branch information
BartoszCiesla authored Sep 12, 2024
1 parent 15de5d9 commit 228afc3
Show file tree
Hide file tree
Showing 10 changed files with 428 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iggy-cli"
version = "0.7.0"
version = "0.8.0"
edition = "2021"
authors = ["bartosz.ciesla@gmail.com"]
repository = "https://github.com/iggy-rs/iggy"
Expand All @@ -20,7 +20,7 @@ anyhow = "1.0.86"
clap = { version = "4.5.17", features = ["derive"] }
clap_complete = "4.5.25"
figlet-rs = "0.1.5"
iggy = { path = "../sdk", features = ["iggy-cli"], version = "0.6.17" }
iggy = { path = "../sdk", features = ["iggy-cli"], version = "0.6.19" }
keyring = { version = "3.2.0", features = ["sync-secret-service", "vendored"], optional = true }
passterm = "2.0.1"
thiserror = "1.0.61"
Expand Down
13 changes: 12 additions & 1 deletion cli/src/args/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ pub(crate) struct SendMessagesArgs {
/// spaces, it should be enclosed in quotes. Limit of the messages and size
/// of each message is defined by the used shell.
#[clap(verbatim_doc_comment)]
#[clap(group = "input_messages")]
pub(crate) messages: Option<Vec<String>>,

/// Comma separated list of key:kind:value, sent as header with the message
///
/// Headers are comma seperated key-value pairs that can be sent with the message.
Expand All @@ -90,6 +90,17 @@ pub(crate) struct SendMessagesArgs {
#[clap(verbatim_doc_comment)]
#[clap(short = 'H', long, value_parser = parse_key_val, value_delimiter = ',')]
pub(crate) headers: Vec<(HeaderKey, HeaderValue)>,
/// Input file with messages to be sent
///
/// File should contain messages stored in binary format. If the file does
/// not exist, the command will fail. If the file is not specified, the command
/// will read the messages from the standard input and each line will
/// be sent as a separate message. If the file is specified, the messages
/// will be read from the file and sent as is. Option cannot be used
/// with the messages option (messages given as command line arguments).
#[clap(verbatim_doc_comment)]
#[clap(long, value_parser = NonEmptyStringValueParser::new(), group = "input_messages")]
pub(crate) input_file: Option<String>,
}

/// Parse Header Key, Kind and Value from the string separated by a ':'
Expand Down
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ fn get_command(
send_args.message_key.clone(),
send_args.messages.clone(),
send_args.headers.clone(),
send_args.input_file.clone(),
)),
MessageAction::Poll(poll_args) => Box::new(PollMessagesCmd::new(
poll_args.stream_id.clone(),
Expand Down
2 changes: 2 additions & 0 deletions integration/tests/cli/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ mod test_message_flush_command;
mod test_message_help_command;
mod test_message_poll_command;
mod test_message_poll_to_file_command;
mod test_message_reply_via_file;
mod test_message_send_command;
mod test_message_send_from_file_command;
76 changes: 76 additions & 0 deletions integration/tests/cli/message/test_message_reply_via_file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use crate::cli::common::IggyCmdTest;
use crate::cli::message::test_message_poll_to_file_command::TestMessagePollToFileCmd;
use crate::cli::message::test_message_send_from_file_command::TestMessageSendFromFileCmd;
use iggy::messages::poll_messages::PollingStrategy;
use iggy::models::header::{HeaderKey, HeaderValue};
use serial_test::parallel;
use std::collections::HashMap;
use std::str::FromStr;

#[tokio::test]
#[parallel]
pub async fn should_be_successful() {
let mut iggy_cmd_test = IggyCmdTest::default();

let test_messages: Vec<&str> = vec![
"Lorem ipsum dolor sit amet, consectetur adipiscing elit",
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris",
"nisi ut aliquip ex ea commodo consequat",
"Duis aute irure dolor in reprehenderit in voluptate velit esse",
"cillum dolore eu fugiat nulla pariatur",
"Excepteur sint occaecat cupidatat non proident, sunt in culpa",
"qui officia deserunt mollit anim id est laborum",
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem",
"accusantium doloremque laudantium, totam rem aperiam, eaque ipsa",
];

let test_headers = HashMap::from([
(
HeaderKey::from_str("HeaderKey1").unwrap(),
HeaderValue::from_str("HeaderValue1").unwrap(),
),
(
HeaderKey::from_str("HeaderKey2").unwrap(),
HeaderValue::from_str("HeaderValue2").unwrap(),
),
(
HeaderKey::from_str("HeaderKey3").unwrap(),
HeaderValue::from_str("HeaderValue3").unwrap(),
),
]);

iggy_cmd_test.setup().await;

let temp_file = tempfile::Builder::new().tempfile().unwrap();
let temp_path = temp_file.path().to_path_buf();
temp_file.close().unwrap();
let temp_path_str = temp_path.to_str().unwrap();

let message_count = test_messages.len();

iggy_cmd_test
.execute_test(TestMessagePollToFileCmd::new(
"input_stream",
"input_topic",
&test_messages,
message_count,
PollingStrategy::offset(0),
test_headers.clone(),
temp_path_str,
false,
))
.await;

iggy_cmd_test
.execute_test(TestMessageSendFromFileCmd::new(
false,
temp_path_str,
"output_stream",
"output_topic",
&test_messages,
message_count,
test_headers,
))
.await;
}
11 changes: 11 additions & 0 deletions integration/tests/cli/message/test_message_send_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,16 @@ Options:
Kind can be one of the following: raw, string, bool, int8, int16, int32, int64,
int128, uint8, uint16, uint32, uint64, uint128, float32, float64
--input-file <INPUT_FILE>
Input file with messages to be sent
{CLAP_INDENT}
File should contain messages stored in binary format. If the file does
not exist, the command will fail. If the file is not specified, the command
will read the messages from the standard input and each line will
be sent as a separate message. If the file is specified, the messages
will be read from the file and sent as is. Option cannot be used
with the messages option (messages given as command line arguments).
-h, --help
Print help (see a summary with '-h')
"#,
Expand Down Expand Up @@ -451,6 +461,7 @@ Options:
-p, --partition-id <PARTITION_ID> ID of the partition to which the message will be sent
-m, --message-key <MESSAGE_KEY> Messages key which will be used to partition the messages
-H, --headers <HEADERS> Comma separated list of key:kind:value, sent as header with the message
--input-file <INPUT_FILE> Input file with messages to be sent
-h, --help Print help (see more with '--help')
"#,
),
Expand Down
Loading

0 comments on commit 228afc3

Please sign in to comment.