2021-11-03 15:33:38 +00:00
|
|
|
use crate::common::server_fixture::{ServerFixture, ServerType};
|
2021-03-16 13:19:44 +00:00
|
|
|
use assert_cmd::Command;
|
2021-09-16 19:15:24 +00:00
|
|
|
use generated_types::google::longrunning::IoxOperation;
|
|
|
|
use generated_types::influxdata::iox::management::v1::{operation_metadata::Job, Dummy};
|
2021-03-16 13:19:44 +00:00
|
|
|
use predicates::prelude::*;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_start_stop() {
|
2021-11-03 15:33:38 +00:00
|
|
|
let server_fixture = ServerFixture::create_single_use(ServerType::Database).await;
|
2021-03-16 13:19:44 +00:00
|
|
|
let addr = server_fixture.grpc_base();
|
|
|
|
let duration = std::time::Duration::from_secs(10).as_nanos() as u64;
|
|
|
|
|
2021-09-16 19:15:24 +00:00
|
|
|
let stdout: IoxOperation = serde_json::from_slice(
|
2021-03-16 13:19:44 +00:00
|
|
|
&Command::cargo_bin("influxdb_iox")
|
|
|
|
.unwrap()
|
|
|
|
.arg("operation")
|
|
|
|
.arg("test")
|
|
|
|
.arg(duration.to_string())
|
|
|
|
.arg("--host")
|
|
|
|
.arg(addr)
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.get_output()
|
|
|
|
.stdout,
|
|
|
|
)
|
|
|
|
.expect("expected JSON output");
|
|
|
|
|
2021-09-16 19:15:24 +00:00
|
|
|
assert_eq!(stdout.metadata.total_count, 1);
|
|
|
|
match stdout.metadata.job {
|
|
|
|
Some(Job::Dummy(Dummy { nanos, .. })) => assert_eq!(nanos, vec![duration]),
|
|
|
|
_ => panic!("expected dummy job got {:?}", stdout.metadata.job),
|
2021-03-16 13:19:44 +00:00
|
|
|
}
|
|
|
|
|
2021-09-16 19:15:24 +00:00
|
|
|
let operations: Vec<IoxOperation> = serde_json::from_slice(
|
2021-03-16 13:19:44 +00:00
|
|
|
&Command::cargo_bin("influxdb_iox")
|
|
|
|
.unwrap()
|
|
|
|
.arg("operation")
|
|
|
|
.arg("list")
|
|
|
|
.arg("--host")
|
|
|
|
.arg(addr)
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.get_output()
|
|
|
|
.stdout,
|
|
|
|
)
|
|
|
|
.expect("expected JSON output");
|
|
|
|
|
2021-03-17 16:32:34 +00:00
|
|
|
assert_eq!(operations.len(), 1);
|
2021-09-16 19:15:24 +00:00
|
|
|
match &operations[0].metadata.job {
|
|
|
|
Some(Job::Dummy(Dummy { nanos, .. })) => {
|
2021-03-16 13:19:44 +00:00
|
|
|
assert_eq!(nanos.len(), 1);
|
|
|
|
assert_eq!(nanos[0], duration);
|
|
|
|
}
|
2021-09-16 19:15:24 +00:00
|
|
|
_ => panic!("expected dummy job got {:?}", &operations[0].metadata.job),
|
2021-03-16 13:19:44 +00:00
|
|
|
}
|
|
|
|
|
2021-09-16 19:15:24 +00:00
|
|
|
let name = &operations[0].operation.name;
|
2021-03-17 16:32:34 +00:00
|
|
|
|
2021-03-16 13:19:44 +00:00
|
|
|
Command::cargo_bin("influxdb_iox")
|
|
|
|
.unwrap()
|
|
|
|
.arg("operation")
|
|
|
|
.arg("cancel")
|
2021-09-16 19:15:24 +00:00
|
|
|
.arg(name.clone())
|
2021-03-16 13:19:44 +00:00
|
|
|
.arg("--host")
|
|
|
|
.arg(addr)
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.stdout(predicate::str::contains("Ok"));
|
2021-03-17 16:32:34 +00:00
|
|
|
|
2021-09-16 19:15:24 +00:00
|
|
|
let completed: IoxOperation = serde_json::from_slice(
|
2021-03-17 16:32:34 +00:00
|
|
|
&Command::cargo_bin("influxdb_iox")
|
|
|
|
.unwrap()
|
|
|
|
.arg("operation")
|
|
|
|
.arg("wait")
|
2021-09-16 19:15:24 +00:00
|
|
|
.arg(name.to_string())
|
2021-03-17 16:32:34 +00:00
|
|
|
.arg("--host")
|
|
|
|
.arg(addr)
|
|
|
|
.assert()
|
|
|
|
.success()
|
|
|
|
.get_output()
|
|
|
|
.stdout,
|
|
|
|
)
|
|
|
|
.expect("expected JSON output");
|
|
|
|
|
2021-09-16 19:15:24 +00:00
|
|
|
assert_eq!(completed.metadata.pending_count, 0);
|
|
|
|
assert_eq!(completed.metadata.total_count, 1);
|
|
|
|
assert_eq!(completed.metadata.cancelled_count, 1);
|
|
|
|
assert_eq!(&completed.metadata.job, &operations[0].metadata.job)
|
2021-03-16 13:19:44 +00:00
|
|
|
}
|