Skip to content
Closed
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,18 @@ fn decode_request(
"hosted Gateway V2 does not yet support AllowTentativeWrites",
));
}
if metadata.read_consistency_strategy.is_some() {
if metadata.consistency_level.is_some() && metadata.read_consistency_strategy.is_some() {
return Err(gateway_v2_bad_request(
"hosted Gateway V2 does not yet support non-default ReadConsistencyStrategy",
"RNTBD request cannot contain both ConsistencyLevel and ReadConsistencyStrategy",
));
}
if let Some(value) = metadata.read_consistency_strategy {
Comment thread
simorenoh marked this conversation as resolved.
Outdated
if !matches!(value, 0x01..=0x04) {
return Err(gateway_v2_bad_request(
"RNTBD request contains an unknown ReadConsistencyStrategy value",
));
}
}
if let Some(value) = metadata.consistency_level {
if !matches!(value, 0x00..=0x04) {
return Err(gateway_v2_bad_request(
Expand Down Expand Up @@ -925,6 +932,87 @@ mod tests {
assert!(error.to_string().contains("AllowTentativeWrites"));
}

#[test]
fn latest_committed_read_consistency_strategy_is_accepted() {
let frame = RntbdRequestFrame {
resource_type: ResourceType::Document,
operation_type: OperationType::ReadFeed,
activity_id: Uuid::new_v4(),
metadata: vec![
Token::database_name("db".to_owned()),
Token::collection_name("coll".to_owned()),
Token::read_consistency_strategy(
crate::options::ReadConsistencyStrategy::LatestCommitted,
),
Token::payload_present(false),
],
body: None,
};
let outer = Request::new(
Url::parse("http://127.0.0.1:18444/dbs/db/colls/coll/docs").unwrap(),
Method::Post,
);

decode_request(&outer, frame, ConsistencyLevel::Session).unwrap();
}

#[test]
fn unknown_read_consistency_strategy_is_rejected() {
let frame = RntbdRequestFrame {
resource_type: ResourceType::Document,
operation_type: OperationType::ReadFeed,
activity_id: Uuid::new_v4(),
metadata: vec![
Token::database_name("db".to_owned()),
Token::collection_name("coll".to_owned()),
Token::new(
RntbdRequestToken::ReadConsistencyStrategy,
TokenValue::Byte(0x05),
),
Token::payload_present(false),
],
body: None,
};
let outer = Request::new(
Url::parse("http://127.0.0.1:18444/dbs/db/colls/coll/docs").unwrap(),
Method::Post,
);

let error = decode_request(&outer, frame, ConsistencyLevel::Session).unwrap_err();
assert!(error.to_string().contains("ReadConsistencyStrategy"));
}

#[test]
fn consistency_level_and_read_consistency_strategy_are_rejected() {
let frame = RntbdRequestFrame {
resource_type: ResourceType::Document,
operation_type: OperationType::ReadFeed,
activity_id: Uuid::new_v4(),
metadata: vec![
Token::database_name("db".to_owned()),
Token::collection_name("coll".to_owned()),
Token::new(
RntbdRequestToken::ConsistencyLevel,
TokenValue::Byte(consistency_wire_byte(ConsistencyLevel::Session)),
),
Token::read_consistency_strategy(
crate::options::ReadConsistencyStrategy::LatestCommitted,
),
Token::payload_present(false),
],
body: None,
};
let outer = Request::new(
Url::parse("http://127.0.0.1:18444/dbs/db/colls/coll/docs").unwrap(),
Method::Post,
);

let error = decode_request(&outer, frame, ConsistencyLevel::Session).unwrap_err();
assert!(error
.to_string()
.contains("both ConsistencyLevel and ReadConsistencyStrategy"));
}

#[test]
fn rejects_wrong_types_for_known_tokens() {
let outer = Request::new(
Expand Down
Loading