2021-03-08 17:35:19 +00:00
|
|
|
use influxdb_iox_client::write::{self, WriteError};
|
|
|
|
use test_helpers::assert_contains;
|
|
|
|
|
2021-03-09 19:08:55 +00:00
|
|
|
use crate::common::server_fixture::ServerFixture;
|
2021-03-08 17:35:19 +00:00
|
|
|
|
2021-03-12 13:56:14 +00:00
|
|
|
use super::util::{create_readable_database, rand_name};
|
|
|
|
|
2021-03-09 19:08:55 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn test_write() {
|
|
|
|
let fixture = ServerFixture::create_shared().await;
|
2021-03-09 20:47:29 +00:00
|
|
|
let mut write_client = write::Client::new(fixture.grpc_channel());
|
2021-03-08 17:35:19 +00:00
|
|
|
|
|
|
|
let db_name = rand_name();
|
2021-03-12 13:56:14 +00:00
|
|
|
create_readable_database(&db_name, fixture.grpc_channel()).await;
|
2021-03-08 17:35:19 +00:00
|
|
|
|
|
|
|
let lp_lines = vec![
|
|
|
|
"cpu,region=west user=23.2 100",
|
|
|
|
"cpu,region=west user=21.0 150",
|
|
|
|
"disk,region=east bytes=99i 200",
|
|
|
|
];
|
|
|
|
|
|
|
|
let num_lines_written = write_client
|
|
|
|
.write(&db_name, lp_lines.join("\n"))
|
|
|
|
.await
|
|
|
|
.expect("write succeded");
|
|
|
|
|
|
|
|
assert_eq!(num_lines_written, 3);
|
|
|
|
|
|
|
|
// ---- test bad data ----
|
|
|
|
let err = write_client
|
|
|
|
.write(&db_name, "XXX")
|
|
|
|
.await
|
|
|
|
.expect_err("expected write to fail");
|
|
|
|
|
|
|
|
assert_contains!(
|
|
|
|
err.to_string(),
|
|
|
|
r#"Client specified an invalid argument: Violation for field "lp_data": Invalid Line Protocol: A generic parsing error occurred"#
|
|
|
|
);
|
|
|
|
assert!(matches!(dbg!(err), WriteError::ServerError(_)));
|
|
|
|
|
|
|
|
// ---- test non existent database ----
|
|
|
|
let err = write_client
|
|
|
|
.write("Non_existent_database", lp_lines.join("\n"))
|
|
|
|
.await
|
|
|
|
.expect_err("expected write to fail");
|
|
|
|
|
|
|
|
assert_contains!(
|
|
|
|
err.to_string(),
|
|
|
|
r#"Unexpected server error: Some requested entity was not found: Resource database/Non_existent_database not found"#
|
|
|
|
);
|
|
|
|
assert!(matches!(dbg!(err), WriteError::ServerError(_)));
|
|
|
|
}
|