-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
165 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use tokio::process::Command; | ||
|
||
use crate::run_command_async; | ||
use std::{ | ||
path::{Path, PathBuf}, | ||
time::Duration, | ||
}; | ||
|
||
pub async fn run_python_smoke_test(address: &str) { | ||
ensure_uv_is_installed().await; | ||
|
||
let project_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("src/connection/kafka/python"); | ||
let uv_binary = uv_binary_path(); | ||
let config = format!( | ||
r#"{{ | ||
'bootstrap_servers': ["{address}"], | ||
}}"# | ||
); | ||
tokio::time::timeout( | ||
Duration::from_secs(60), | ||
run_command_async( | ||
&project_dir, | ||
uv_binary.to_str().unwrap(), | ||
&["run", "main.py", &config], | ||
), | ||
) | ||
.await | ||
.unwrap(); | ||
} | ||
|
||
/// Install a specific version of UV to: | ||
/// * avoid developers having to manually install an external tool | ||
/// * avoid issues due to a different version being installed | ||
pub async fn ensure_uv_is_installed() { | ||
let uv_binary = uv_binary_path(); | ||
|
||
if let Ok(output) = Command::new(uv_binary).arg("--help").output().await { | ||
if output.status.success() { | ||
// already correctly installed | ||
return; | ||
} | ||
} | ||
|
||
// Install to this custom path to avoid overwriting any UV already installed by the user. | ||
// Specifically uses `..` instead of absolute path to avoid spaces messing up the bash script | ||
let path = "../target/uv"; | ||
|
||
run_command_async( | ||
Path::new("."), | ||
"bash", | ||
&[ | ||
"-c", | ||
&format!("curl -LsSf https://astral.sh/uv/0.4.6/install.sh | env INSTALLER_NO_MODIFY_PATH=1 UV_INSTALL_DIR={path} sh"), | ||
], | ||
) | ||
.await | ||
} | ||
|
||
fn uv_binary_path() -> PathBuf { | ||
Path::new(env!("CARGO_MANIFEST_DIR")) | ||
.parent() | ||
.unwrap() | ||
.join("target/uv/bin/uv") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from kafka import KafkaConsumer | ||
from kafka import KafkaProducer | ||
import sys | ||
|
||
def main(): | ||
config = eval(sys.argv[1]) | ||
print("Running kafka-python script with config:") | ||
print(config) | ||
|
||
producer = KafkaProducer(**config) | ||
producer.send('test_topic', b'some_message_bytes').get(timeout=10) | ||
producer.send('test_topic', b'another_message').get(timeout=10) | ||
|
||
consumer = KafkaConsumer('test_topic', auto_offset_reset='earliest', **config) | ||
|
||
msg = next(consumer) | ||
assert(msg.topic == "test_topic") | ||
assert(msg.value == b"some_message_bytes") | ||
assert(msg.offset == 0) | ||
|
||
msg = next(consumer) | ||
assert(msg.topic == "test_topic") | ||
assert(msg.value == b"another_message") | ||
assert(msg.offset == 1) | ||
|
||
print("kafka-python script passed all test cases") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[project] | ||
name = "python" | ||
version = "0.1.0" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = ">=3.12" | ||
dependencies = [ | ||
"kafka-python-ng>=2.2.3", | ||
] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters