Skip to content

Commit

Permalink
test: add integration test for hints
Browse files Browse the repository at this point in the history
  • Loading branch information
fengjiachun committed Jul 30, 2024
1 parent 1e6dc03 commit 3fe0516
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/client/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Database {
let mut request = tonic::Request::new(request);
let metadata = request.metadata_mut();
for (key, value) in hints {
let key = AsciiMetadataKey::from_bytes(format!("x-greptime-hint:{}", key).as_bytes())
let key = AsciiMetadataKey::from_bytes(format!("x-greptime-hint-{}", key).as_bytes())
.map_err(|_| {
InvalidAsciiSnafu {
value: key.to_string(),
Expand Down
10 changes: 7 additions & 3 deletions src/servers/src/grpc/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use tonic::{Request, Response, Status, Streaming};
use crate::grpc::greptime_handler::GreptimeRequestHandler;
use crate::grpc::{cancellation, TonicResult};

pub const GREPTIME_DB_HEADER_HINT_PREFIX: &str = "x-greptime-hint:";
pub const GREPTIME_DB_HEADER_HINT_PREFIX: &str = "x-greptime-hint-";

pub(crate) struct DatabaseService {
handler: GreptimeRequestHandler,
Expand Down Expand Up @@ -177,7 +177,11 @@ mod tests {
#[test]
fn test_extract_hints() {
let mut metadata = MetadataMap::new();
metadata.insert("x-greptime-hint:append_mode", "true".parse().unwrap());
let prev = metadata.insert(
"x-greptime-hint-append_mode",
MetadataValue::from_static("true"),
);
assert!(prev.is_none());
let hints = extract_hints(&metadata);
assert_eq!(hints, vec![("append_mode".to_string(), "true".to_string())]);
}
Expand All @@ -186,7 +190,7 @@ mod tests {
fn extract_hints_ignores_non_ascii_metadata() {
let mut metadata = MetadataMap::new();
metadata.insert_bin(
"x-greptime-hint:merge_mode",
"x-greptime-hint-merge_mode-bin",
MetadataValue::from_bytes(b"last_non_null"),
);
let hints = extract_hints(&metadata);
Expand Down
31 changes: 19 additions & 12 deletions tests-integration/tests/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,13 @@ async fn insert_with_hints_and_assert(db: &Database) {
InsertRequests {
inserts: vec![request],
},
&[("append_mode", "true"), ("merge_mode", "last_non_null")],
&[("append_mode", "true")],
)
.await;
assert_eq!(result.unwrap(), 4);

// show table
let output = db.sql("SHOW CREATE TABLE demo").await.unwrap();
let output = db.sql("SHOW CREATE TABLE demo;").await.unwrap();

let record_batches = match output.data {
OutputData::RecordBatches(record_batches) => record_batches,
Expand All @@ -426,16 +426,23 @@ async fn insert_with_hints_and_assert(db: &Database) {

let pretty = record_batches.pretty_print().unwrap();
let expected = "\
+-------+------+--------+-------------------------+
| host | cpu | memory | ts |
+-------+------+--------+-------------------------+
| host1 | 0.31 | 0.1 | 1970-01-01T00:00:00.100 |
| host2 | | 0.2 | 1970-01-01T00:00:00.101 |
| host3 | 0.41 | | 1970-01-01T00:00:00.102 |
| host4 | 0.2 | 0.3 | 1970-01-01T00:00:00.103 |
| host5 | 66.6 | 1024.0 | 2022-12-28T04:17:07 |
| host6 | 88.8 | 333.3 | 2022-12-28T04:17:08 |
+-------+------+--------+-------------------------+\
+-------+-------------------------------------+
| Table | Create Table |
+-------+-------------------------------------+
| demo | CREATE TABLE IF NOT EXISTS \"demo\" ( |
| | \"host\" STRING NULL, |
| | \"cpu\" DOUBLE NULL, |
| | \"memory\" DOUBLE NULL, |
| | \"ts\" TIMESTAMP(3) NOT NULL, |
| | TIME INDEX (\"ts\"), |
| | PRIMARY KEY (\"host\") |
| | ) |
| | |
| | ENGINE=mito |
| | WITH( |
| | append_mode = 'true' |
| | ) |
+-------+-------------------------------------+\
";
assert_eq!(pretty, expected);
}
Expand Down

0 comments on commit 3fe0516

Please sign in to comment.