Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add large file test #31

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions aws-throwaway/examples/aws-throwaway-test-large-file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use aws_throwaway::{Aws, CleanupResources, Ec2InstanceDefinition, InstanceType};
use std::{path::Path, time::Instant};
use tracing_subscriber::EnvFilter;

const FILE_LEN: usize = 1024 * 1024 * 100; // 100MB

#[tokio::main]
async fn main() {
let (non_blocking, _guard) = tracing_appender::non_blocking(std::io::stdout());
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.with_writer(non_blocking)
.init();

let aws = Aws::builder(CleanupResources::AllResources).build().await;
let instance = aws
.create_ec2_instance(Ec2InstanceDefinition::new(InstanceType::T2Micro))
.await;

let start = Instant::now();
std::fs::write("some_local_file", vec![0; FILE_LEN]).unwrap(); // create 100MB file
println!("Time to create 100MB file locally {:?}", start.elapsed());

let start = Instant::now();
instance
.ssh()
.push_file(Path::new("some_local_file"), Path::new("some_remote_file"))
.await;
println!("Time to push 100MB file {:?}", start.elapsed());

let start = Instant::now();
instance
.ssh()
.pull_file(Path::new("some_remote_file"), Path::new("some_local_file"))
.await;
println!("Time to pull 100MB file {:?}", start.elapsed());

assert_eq!(std::fs::read("some_local_file").unwrap().len(), FILE_LEN);
std::fs::remove_file("some_local_file").unwrap();

aws.cleanup_resources().await;
println!("\nAll AWS throwaway resources have been deleted")
}