diff --git a/.gitignore b/.gitignore index 927e6b51b..64463d300 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Generated by Cargo # will have compiled files and executables /target/ +/controller-client/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html diff --git a/Cargo.toml b/Cargo.toml index 8ce420efd..a8b2b7e7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,14 +21,14 @@ members = [ [dependencies] async-stream = "0.1.2" async-trait = "0.1.17" -bincode = "1.2" +bincode2 = "2.0.1" byteorder = "1.3" futures = "0.3" lazy_static = "1.4.0" log = "0.4" serde = { version = "1.0", features = ["derive"] } serde_repr = "0.1" -snafu = "0.5.0" +snafu = "0.6.2" tokio = { version = "0.2.8", features = ["full"] } [dev-dependencies] diff --git a/controller-client/src/lib.rs b/controller-client/src/lib.rs index 02a4c6df3..d8cb69f56 100644 --- a/controller-client/src/lib.rs +++ b/controller-client/src/lib.rs @@ -21,7 +21,7 @@ pub use controller::{ scaling_policy::ScalingPolicyType, CreateScopeStatus, CreateStreamStatus, ScalingPolicy, ScopeInfo, StreamConfig, StreamInfo, }; -use snafu::Snafu; +use snafu::{Backtrace, Snafu}; use tonic::transport::channel::Channel; use tonic::{Code, Status}; @@ -36,12 +36,14 @@ pub enum ControllerError { can_retry: bool, operation: String, error_msg: String, + backtrace: Backtrace, }, #[snafu(display("Could not connect to controller {}", endpoint))] ConnectionError { can_retry: bool, endpoint: String, error_msg: String, + backtrace: Backtrace, }, } diff --git a/controller-client/src/test.rs b/controller-client/src/test.rs index fc569f259..134674b41 100644 --- a/controller-client/src/test.rs +++ b/controller-client/src/test.rs @@ -15,7 +15,7 @@ fn test_create_scope_error() { }; let fut = create_scope(request, &mut client); - rt.block_on(fut); + rt.block_on(fut).unwrap(); } #[test] @@ -41,5 +41,5 @@ fn test_create_stream_error() { }; let fut = create_stream(request, &mut client); - rt.block_on(fut); + rt.block_on(fut).unwrap(); } diff --git a/src/wire_protocol/commands.rs b/src/wire_protocol/commands.rs index 82816ddda..96c4d12bf 100644 --- a/src/wire_protocol/commands.rs +++ b/src/wire_protocol/commands.rs @@ -1,10 +1,9 @@ use super::error::CommandError; use super::error::InvalidData; use super::error::Io; -use bincode::Config; +use bincode2::Config; +use bincode2::LengthOption; use byteorder::{BigEndian, ByteOrder, ReadBytesExt}; -use serde::de::{self, Deserializer, Unexpected, Visitor}; -use serde::ser::Serializer; use serde::{Deserialize, Serialize}; use snafu::ResultExt; use std::fmt; @@ -43,89 +42,16 @@ pub trait Reply { } } -/** - * Wrap String to follow Java Serialize/Deserialize Style. - * - */ -pub struct JavaString(pub String); - -impl fmt::Debug for JavaString { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0) - } -} - -impl fmt::Display for JavaString { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0) - } -} - -impl PartialEq for JavaString { - fn eq(&self, other: &Self) -> bool { - self.0 == other.0 - } -} - -impl Serialize for JavaString { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - // get the length of the String. - let length = self.0.len() as u16; - // get the content of the String. - let binary = self.0.as_bytes(); - // Serialize - let mut content = vec![]; - content.extend_from_slice(&length.to_be_bytes()); - content.extend(binary); - serializer.serialize_bytes(&content) - } -} - -struct JavaStringVisitor; - -impl<'de> Visitor<'de> for JavaStringVisitor { - type Value = JavaString; - - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> fmt::Result { - formatter.write_str("A Byte buffer which contains length and content") - } - - fn visit_byte_buf(self, value: Vec) -> Result - where - E: de::Error, - { - // get the length - let _length = ((value[0] as u16) << 8) | value[1] as u16; - // construct the JavaString - let content = String::from_utf8_lossy(&value[2..]).into_owned(); - - if _length == content.len() as u16 { - Ok(JavaString(content)) - } else { - Err(de::Error::invalid_value(Unexpected::Bytes(&value), &self)) - } - } -} - -impl<'de> Deserialize<'de> for JavaString { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - deserializer.deserialize_byte_buf(JavaStringVisitor) - } -} - /* * bincode serialize and deserialize config */ lazy_static! { static ref CONFIG: Config = { - let mut config = bincode::config(); + let mut config = bincode2::config(); config.big_endian(); + config.limit(0x007f_ffff); + config.array_length(LengthOption::U32); + config.string_length(LengthOption::U16); config }; } @@ -174,9 +100,9 @@ impl Reply for HelloCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct WrongHostCommand { pub request_id: i64, - pub segment: JavaString, - pub correct_host: JavaString, - pub server_stack_trace: JavaString, + pub segment: String, + pub correct_host: String, + pub server_stack_trace: String, } impl Command for WrongHostCommand { @@ -210,8 +136,8 @@ impl Reply for WrongHostCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SegmentIsSealedCommand { pub request_id: i64, - pub segment: JavaString, - pub server_stack_trace: JavaString, + pub segment: String, + pub server_stack_trace: String, pub offset: i64, } @@ -248,9 +174,9 @@ impl Reply for SegmentIsSealedCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SegmentIsTruncatedCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, pub start_offset: i64, - pub server_stack_trace: JavaString, + pub server_stack_trace: String, pub offset: i64, } @@ -287,8 +213,8 @@ impl Reply for SegmentIsTruncatedCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SegmentAlreadyExistsCommand { pub request_id: i64, - pub segment: JavaString, - pub server_stack_trace: JavaString, + pub segment: String, + pub server_stack_trace: String, } impl Command for SegmentAlreadyExistsCommand { @@ -330,8 +256,8 @@ impl fmt::Display for SegmentAlreadyExistsCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct NoSuchSegmentCommand { pub request_id: i64, - pub segment: JavaString, - pub server_stack_trace: JavaString, + pub segment: String, + pub server_stack_trace: String, pub offset: i64, } @@ -374,8 +300,8 @@ impl fmt::Display for NoSuchSegmentCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct TableSegmentNotEmptyCommand { pub request_id: i64, - pub segment: JavaString, - pub server_stack_trace: JavaString, + pub segment: String, + pub server_stack_trace: String, } impl Command for TableSegmentNotEmptyCommand { @@ -418,7 +344,7 @@ impl fmt::Display for TableSegmentNotEmptyCommand { pub struct InvalidEventNumberCommand { pub writer_id: u128, pub event_number: i64, - pub server_stack_trace: JavaString, + pub server_stack_trace: String, } impl Command for InvalidEventNumberCommand { @@ -464,8 +390,8 @@ impl fmt::Display for InvalidEventNumberCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct OperationUnsupportedCommand { pub request_id: i64, - pub operation_name: JavaString, - pub server_stack_trace: JavaString, + pub operation_name: String, + pub server_stack_trace: String, } impl Command for OperationUnsupportedCommand { @@ -581,8 +507,8 @@ impl Command for EventCommand { pub struct SetupAppendCommand { pub request_id: i64, pub writer_id: u128, - pub segment: JavaString, - pub delegation_token: JavaString, + pub segment: String, + pub delegation_token: String, } impl Command for SetupAppendCommand { @@ -683,7 +609,7 @@ pub struct ConditionalAppendCommand { impl ConditionalAppendCommand { fn read_event(rdr: &mut Cursor<&[u8]>) -> Result { let _type_code = rdr.read_i32::()?; - let event_length = rdr.read_u64::()?; + let event_length = rdr.read_u32::()?; // read the data in event let mut msg: Vec = vec![0; event_length as usize]; rdr.read_exact(&mut msg)?; @@ -739,7 +665,7 @@ impl Request for ConditionalAppendCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct AppendSetupCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, pub writer_id: u128, pub last_event_number: i64, } @@ -844,10 +770,10 @@ impl Reply for ConditionalAppendCommand { */ #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct ReadSegmentCommand { - pub segment: JavaString, + pub segment: String, pub offset: i64, pub suggested_length: i64, - pub delegation_token: JavaString, + pub delegation_token: String, pub request_id: i64, } @@ -880,7 +806,7 @@ impl Request for ReadSegmentCommand { */ #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SegmentReadCommand { - pub segment: JavaString, + pub segment: String, pub offset: i64, pub at_tail: bool, pub end_of_segment: bool, @@ -918,9 +844,9 @@ impl Reply for SegmentReadCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct GetSegmentAttributeCommand { pub request_id: i64, - pub segment_name: JavaString, + pub segment_name: String, pub attribute_id: u128, - pub delegation_token: JavaString, + pub delegation_token: String, } impl Command for GetSegmentAttributeCommand { @@ -988,11 +914,11 @@ impl Reply for SegmentAttributeCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct UpdateSegmentAttributeCommand { pub request_id: i64, - pub segment_name: JavaString, + pub segment_name: String, pub attribute_id: u128, pub new_value: i64, pub expected_value: i64, - pub delegation_token: JavaString, + pub delegation_token: String, } impl Command for UpdateSegmentAttributeCommand { @@ -1060,8 +986,8 @@ impl Reply for SegmentAttributeUpdatedCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct GetStreamSegmentInfoCommand { pub request_id: i64, - pub segment_name: JavaString, - pub delegation_token: JavaString, + pub segment_name: String, + pub delegation_token: String, } impl Command for GetStreamSegmentInfoCommand { @@ -1095,7 +1021,7 @@ impl Request for GetStreamSegmentInfoCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct StreamSegmentInfoCommand { pub request_id: i64, - pub segment_name: JavaString, + pub segment_name: String, pub exists: bool, pub is_sealed: bool, pub is_deleted: bool, @@ -1135,10 +1061,10 @@ impl Reply for StreamSegmentInfoCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct CreateSegmentCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, pub target_rate: i32, pub scale_type: u8, - pub delegation_token: JavaString, + pub delegation_token: String, } impl Command for CreateSegmentCommand { @@ -1172,8 +1098,8 @@ impl Request for CreateSegmentCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct CreateTableSegmentCommand { pub request_id: i64, - pub segment: JavaString, - pub delegation_token: JavaString, + pub segment: String, + pub delegation_token: String, } impl Command for CreateTableSegmentCommand { @@ -1207,7 +1133,7 @@ impl Request for CreateTableSegmentCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SegmentCreatedCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, } impl Command for SegmentCreatedCommand { @@ -1241,10 +1167,10 @@ impl Reply for SegmentCreatedCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct UpdateSegmentPolicyCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, pub target_rate: i32, pub scale_type: u8, - pub delegation_token: JavaString, + pub delegation_token: String, } impl Command for UpdateSegmentPolicyCommand { @@ -1278,7 +1204,7 @@ impl Request for UpdateSegmentPolicyCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SegmentPolicyUpdatedCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, } impl Command for SegmentPolicyUpdatedCommand { @@ -1312,9 +1238,9 @@ impl Reply for SegmentPolicyUpdatedCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct MergeSegmentsCommand { pub request_id: i64, - pub target: JavaString, - pub source: JavaString, - pub delegation_token: JavaString, + pub target: String, + pub source: String, + pub delegation_token: String, } impl Command for MergeSegmentsCommand { @@ -1347,9 +1273,9 @@ impl Request for MergeSegmentsCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct MergeTableSegmentsCommand { pub request_id: i64, - pub target: JavaString, - pub source: JavaString, - pub delegation_token: JavaString, + pub target: String, + pub source: String, + pub delegation_token: String, } impl Command for MergeTableSegmentsCommand { @@ -1383,8 +1309,8 @@ impl Request for MergeTableSegmentsCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SegmentsMergedCommand { pub request_id: i64, - pub target: JavaString, - pub source: JavaString, + pub target: String, + pub source: String, pub new_target_write_offset: i64, } @@ -1419,8 +1345,8 @@ impl Reply for SegmentsMergedCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SealSegmentCommand { pub request_id: i64, - pub segment: JavaString, - pub delegation_token: JavaString, + pub segment: String, + pub delegation_token: String, } impl Command for SealSegmentCommand { @@ -1453,8 +1379,8 @@ impl Request for SealSegmentCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SealTableSegmentCommand { pub request_id: i64, - pub segment: JavaString, - pub delegation_token: JavaString, + pub segment: String, + pub delegation_token: String, } impl Command for SealTableSegmentCommand { @@ -1488,7 +1414,7 @@ impl Request for SealTableSegmentCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SegmentSealedCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, } impl Command for SegmentSealedCommand { @@ -1522,9 +1448,9 @@ impl Reply for SegmentSealedCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct TruncateSegmentCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, pub truncation_offset: i64, - pub delegation_token: JavaString, + pub delegation_token: String, } impl Command for TruncateSegmentCommand { @@ -1558,7 +1484,7 @@ impl Request for TruncateSegmentCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SegmentTruncatedCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, } impl Command for SegmentTruncatedCommand { @@ -1592,8 +1518,8 @@ impl Reply for SegmentTruncatedCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct DeleteSegmentCommand { pub request_id: i64, - pub segment: JavaString, - pub delegation_token: JavaString, + pub segment: String, + pub delegation_token: String, } impl Command for DeleteSegmentCommand { @@ -1627,9 +1553,9 @@ impl Request for DeleteSegmentCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct DeleteTableSegmentCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, pub must_be_empty: bool, // If true, the Table Segment will only be deleted if it is empty (contains no keys) - pub delegation_token: JavaString, + pub delegation_token: String, } impl Command for DeleteTableSegmentCommand { @@ -1662,7 +1588,7 @@ impl Request for DeleteTableSegmentCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct SegmentDeletedCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, } impl Command for SegmentDeletedCommand { @@ -1729,7 +1655,7 @@ impl Reply for KeepAliveCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct AuthTokenCheckFailedCommand { pub request_id: i64, - pub server_stack_trace: JavaString, + pub server_stack_trace: String, pub error_code: i32, } @@ -1799,8 +1725,8 @@ impl ErrorCode { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct UpdateTableEntriesCommand { pub request_id: i64, - pub segment: JavaString, - pub delegation_token: JavaString, + pub segment: String, + pub delegation_token: String, pub table_entries: TableEntries, } @@ -1869,8 +1795,8 @@ impl Reply for TableEntriesUpdatedCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct RemoveTableKeysCommand { pub request_id: i64, - pub segment: JavaString, - pub delegation_token: JavaString, + pub segment: String, + pub delegation_token: String, pub keys: Vec, } @@ -1905,7 +1831,7 @@ impl Request for RemoveTableKeysCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct TableKeysRemovedCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, } impl Command for TableKeysRemovedCommand { @@ -1939,8 +1865,8 @@ impl Reply for TableKeysRemovedCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct ReadTableCommand { pub request_id: i64, - pub segment: JavaString, - pub delegation_token: JavaString, + pub segment: String, + pub delegation_token: String, pub keys: Vec, } @@ -1974,7 +1900,7 @@ impl Request for ReadTableCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct TableReadCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, pub entries: TableEntries, } @@ -2008,8 +1934,8 @@ impl Reply for TableReadCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct ReadTableKeysCommand { pub request_id: i64, - pub segment: JavaString, - pub delegation_token: JavaString, + pub segment: String, + pub delegation_token: String, pub suggested_key_count: i32, pub continuation_token: Vec, } @@ -2045,7 +1971,7 @@ impl Request for ReadTableKeysCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct TableKeysReadCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, pub keys: Vec, pub continuation_token: Vec, // this is used to indicate the point from which the next keys should be fetched. } @@ -2081,8 +2007,8 @@ impl Reply for TableKeysReadCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct ReadTableEntriesCommand { pub request_id: i64, - pub segment: JavaString, - pub delegation_token: JavaString, + pub segment: String, + pub delegation_token: String, pub suggested_entry_count: i32, pub continuation_token: Vec, } @@ -2118,7 +2044,7 @@ impl Request for ReadTableEntriesCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct TableEntriesReadCommand { pub request_id: i64, - pub segment: JavaString, + pub segment: String, pub entries: TableEntries, pub continuation_token: Vec, } @@ -2154,8 +2080,8 @@ impl Reply for TableEntriesReadCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct TableKeyDoesNotExistCommand { pub request_id: i64, - pub segment: JavaString, - pub server_stack_trace: JavaString, + pub segment: String, + pub server_stack_trace: String, } impl Command for TableKeyDoesNotExistCommand { @@ -2203,8 +2129,8 @@ impl fmt::Display for TableKeyDoesNotExistCommand { #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct TableKeyBadVersionCommand { pub request_id: i64, - pub segment: JavaString, - pub server_stack_trace: JavaString, + pub segment: String, + pub server_stack_trace: String, } impl Command for TableKeyBadVersionCommand { diff --git a/src/wire_protocol/error.rs b/src/wire_protocol/error.rs index 5428bfc81..08f20116d 100644 --- a/src/wire_protocol/error.rs +++ b/src/wire_protocol/error.rs @@ -1,6 +1,6 @@ use super::connection_factory::ConnectionType; -use bincode::Error as BincodeError; -use snafu::Snafu; +use bincode2::Error as BincodeError; +use snafu::{Backtrace, Snafu}; use std::io::Error as IoError; use std::net::SocketAddr; @@ -17,16 +17,19 @@ pub enum ConnectionError { connection_type: ConnectionType, endpoint: SocketAddr, source: std::io::Error, + backtrace: Backtrace, }, #[snafu(display("Could not send data to {} asynchronously", endpoint))] SendData { endpoint: SocketAddr, source: std::io::Error, + backtrace: Backtrace, }, #[snafu(display("Could not read data from {} asynchronously", endpoint))] ReadData { endpoint: SocketAddr, source: std::io::Error, + backtrace: Backtrace, }, } @@ -42,18 +45,26 @@ pub enum CommandError { InvalidData { command_type: i32, source: BincodeError, + backtrace: Backtrace, }, #[snafu(display( "Could not serialize/deserialize command {} because of: {}", command_type, source ))] - Io { command_type: i32, source: IoError }, + Io { + command_type: i32, + source: IoError, + backtrace: Backtrace, + }, #[snafu(display( "Could not serialize/deserialize command {} because of: Unknown Command", command_type ))] - InvalidType { command_type: i32 }, + InvalidType { + command_type: i32, + backtrace: Backtrace, + }, } /// This kind of error that can be produced during Pravega read Wire Commands. @@ -64,6 +75,7 @@ pub enum ReaderError { ReadWirecommand { part: String, source: ConnectionError, + backtrace: Backtrace, }, #[snafu(display( "The payload size {} exceeds the max wirecommand size {}", @@ -73,5 +85,6 @@ pub enum ReaderError { PayloadLengthTooLong { payload_size: u32, max_wirecommand_size: u32, + backtrace: Backtrace, }, } diff --git a/src/wire_protocol/tests.rs b/src/wire_protocol/tests.rs index 44c217595..3ae65ff66 100644 --- a/src/wire_protocol/tests.rs +++ b/src/wire_protocol/tests.rs @@ -12,9 +12,9 @@ fn test_hello() { #[test] fn test_wrong_host() { - let correct_host_name = JavaString(String::from("foo")); - let segment_name = JavaString(String::from("segment-1")); - let stack_trace = JavaString(String::from("some exception")); + let correct_host_name = String::from("foo"); + let segment_name = String::from("segment-1"); + let stack_trace = String::from("some exception"); let wrong_host_command = WireCommands::WrongHost(WrongHostCommand { request_id: 1, segment: segment_name, @@ -26,8 +26,8 @@ fn test_wrong_host() { #[test] fn test_segment_is_sealed() { - let segment_name = JavaString(String::from("segment-1")); - let stack_trace = JavaString(String::from("some exception")); + let segment_name = String::from("segment-1"); + let stack_trace = String::from("some exception"); let offset_pos = 100i64; let segment_is_sealed_command = WireCommands::SegmentIsSealed(SegmentIsSealedCommand { request_id: 1, @@ -40,8 +40,8 @@ fn test_segment_is_sealed() { #[test] fn test_segment_already_exists() { - let segment_name = JavaString(String::from("segment-1")); - let stack_trace = JavaString(String::from("some exception")); + let segment_name = String::from("segment-1"); + let stack_trace = String::from("some exception"); let segment_already_exists_command = WireCommands::SegmentAlreadyExists(SegmentAlreadyExistsCommand { request_id: 1, @@ -53,8 +53,8 @@ fn test_segment_already_exists() { #[test] fn test_segment_is_truncated() { - let segment_name = JavaString(String::from("segment-1")); - let stack_trace = JavaString(String::from("some exception")); + let segment_name = String::from("segment-1"); + let stack_trace = String::from("some exception"); let start_offset_pos = 0i64; let offset_pos = 100i64; let segment_is_truncated_command = @@ -70,8 +70,8 @@ fn test_segment_is_truncated() { #[test] fn test_no_such_segment() { - let segment_name = JavaString(String::from("segment-1")); - let stack_trace = JavaString(String::from("some exception")); + let segment_name = String::from("segment-1"); + let stack_trace = String::from("some exception"); let offset_pos = 100i64; let no_such_segment_command = WireCommands::NoSuchSegment(NoSuchSegmentCommand { request_id: 1, @@ -84,8 +84,8 @@ fn test_no_such_segment() { #[test] fn test_table_segment_not_empty() { - let segment_name = JavaString(String::from("segment-1")); - let stack_trace = JavaString(String::from("some exception")); + let segment_name = String::from("segment-1"); + let stack_trace = String::from("some exception"); let table_segment_not_empty_command = WireCommands::TableSegmentNotEmpty(TableSegmentNotEmptyCommand { request_id: 1, @@ -99,7 +99,7 @@ fn test_table_segment_not_empty() { fn test_invalid_event_number() { let writer_id_number: u128 = 123; let event_num: i64 = 100; - let stack_trace = JavaString(String::from("some exception")); + let stack_trace = String::from("some exception"); let invalid_event_number_command = WireCommands::InvalidEventNumber(InvalidEventNumberCommand { writer_id: writer_id_number, @@ -111,8 +111,8 @@ fn test_invalid_event_number() { #[test] fn test_operation_unsupported() { - let name = JavaString(String::from("operation")); - let stack_trace = JavaString(String::from("some exception")); + let name = String::from("operation"); + let stack_trace = String::from("some exception"); let test_operation_unsupported_command = WireCommands::OperationUnsupported(OperationUnsupportedCommand { request_id: 1, @@ -154,8 +154,8 @@ fn test_event() { #[test] fn test_setup_append() { let writer_id_number: u128 = 123; - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let setup_append_command = WireCommands::SetupAppend(SetupAppendCommand { request_id: 1, writer_id: writer_id_number, @@ -218,7 +218,7 @@ fn test_conditional_append() { #[test] fn test_append_setup() { let writer_id_number: u128 = 123; - let segment_name = JavaString(String::from("segment-1")); + let segment_name = String::from("segment-1"); let append_setup_cmd = WireCommands::AppendSetup(AppendSetupCommand { request_id: 1, segment: segment_name, @@ -255,8 +255,8 @@ fn test_conditional_check_failed() { #[test] fn test_read_segment() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let read_segment_command = WireCommands::ReadSegment(ReadSegmentCommand { segment: segment_name, offset: 0, @@ -269,7 +269,7 @@ fn test_read_segment() { #[test] fn test_segment_read() { - let segment_name = JavaString(String::from("segment-1")); + let segment_name = String::from("segment-1"); let data = String::from("event-1").into_bytes(); let segment_read_command = WireCommands::SegmentRead(SegmentReadCommand { segment: segment_name, @@ -284,8 +284,8 @@ fn test_segment_read() { #[test] fn test_get_segment_attribute() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let attribute_id: u128 = 123; let get_segment_attribute_command = WireCommands::GetSegmentAttribute(GetSegmentAttributeCommand { @@ -308,8 +308,8 @@ fn test_segment_attribute() { #[test] fn test_update_segment_attribute() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let attribute_id: u128 = 123; let update_segment_attribute = WireCommands::UpdateSegmentAttribute(UpdateSegmentAttributeCommand { @@ -335,8 +335,8 @@ fn test_segment_attribute_updated() { #[test] fn test_get_stream_segment_info() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let get_stream_segment_info = WireCommands::GetStreamSegmentInfo(GetStreamSegmentInfoCommand { request_id: 1, segment_name, @@ -347,7 +347,7 @@ fn test_get_stream_segment_info() { #[test] fn test_stream_segment_info() { - let segment_name = JavaString(String::from("segment-1")); + let segment_name = String::from("segment-1"); let stream_segment_info = WireCommands::StreamSegmentInfo(StreamSegmentInfoCommand { request_id: 0, segment_name, @@ -363,8 +363,8 @@ fn test_stream_segment_info() { #[test] fn test_create_segment() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let create_segment_command = WireCommands::CreateSegment(CreateSegmentCommand { request_id: 1, segment: segment_name, @@ -377,8 +377,8 @@ fn test_create_segment() { #[test] fn test_create_table_segment() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let create_table_segment_command = WireCommands::CreateTableSegment(CreateTableSegmentCommand { request_id: 1, @@ -390,7 +390,7 @@ fn test_create_table_segment() { #[test] fn test_segment_created() { - let segment_name = JavaString(String::from("segment-1")); + let segment_name = String::from("segment-1"); let segment_created_cmd = WireCommands::SegmentCreated(SegmentCreatedCommand { request_id: 1, segment: segment_name, @@ -400,8 +400,8 @@ fn test_segment_created() { #[test] fn test_update_segment_policy() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let update_segment_policy_cmd = WireCommands::UpdateSegmentPolicy(UpdateSegmentPolicyCommand { request_id: 1, segment: segment_name, @@ -414,7 +414,7 @@ fn test_update_segment_policy() { #[test] fn test_segment_policy_updated() { - let segment_name = JavaString(String::from("segment-1")); + let segment_name = String::from("segment-1"); let segment_policy_updated = WireCommands::SegmentPolicyUpdated(SegmentPolicyUpdatedCommand { request_id: 0, segment: segment_name, @@ -424,9 +424,9 @@ fn test_segment_policy_updated() { #[test] fn test_merge_segment() { - let target = JavaString(String::from("segment-1")); - let source = JavaString(String::from("segment-2")); - let token = JavaString(String::from("delegation_token")); + let target = String::from("segment-1"); + let source = String::from("segment-2"); + let token = String::from("delegation_token"); let merge_segment = WireCommands::MergeSegments(MergeSegmentsCommand { request_id: 1, target, @@ -438,9 +438,9 @@ fn test_merge_segment() { #[test] fn test_merge_table_segment() { - let target = JavaString(String::from("segment-1")); - let source = JavaString(String::from("segment-2")); - let token = JavaString(String::from("delegation_token")); + let target = String::from("segment-1"); + let source = String::from("segment-2"); + let token = String::from("delegation_token"); let merge_table_segment = WireCommands::MergeTableSegments(MergeTableSegmentsCommand { request_id: 1, target, @@ -452,8 +452,8 @@ fn test_merge_table_segment() { #[test] fn test_segment_merged() { - let target = JavaString(String::from("segment-1")); - let source = JavaString(String::from("segment-2")); + let target = String::from("segment-1"); + let source = String::from("segment-2"); let segment_merged = WireCommands::SegmentsMerged(SegmentsMergedCommand { request_id: 1, target, @@ -465,8 +465,8 @@ fn test_segment_merged() { #[test] fn test_seal_segment() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let seal_segment = WireCommands::SealSegment(SealSegmentCommand { request_id: 1, segment: segment_name, @@ -477,8 +477,8 @@ fn test_seal_segment() { #[test] fn test_seal_table_segment() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let seal_table_segment = WireCommands::SealTableSegment(SealTableSegmentCommand { request_id: 1, segment: segment_name, @@ -489,7 +489,7 @@ fn test_seal_table_segment() { #[test] fn test_segment_sealed() { - let segment_name = JavaString(String::from("segment-1")); + let segment_name = String::from("segment-1"); let segment_sealed = WireCommands::SegmentSealed(SegmentSealedCommand { request_id: 1, segment: segment_name, @@ -499,8 +499,8 @@ fn test_segment_sealed() { #[test] fn test_truncate_segment() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let truncate_segment = WireCommands::TruncateSegment(TruncateSegmentCommand { request_id: 1, segment: segment_name, @@ -512,7 +512,7 @@ fn test_truncate_segment() { #[test] fn test_segment_truncated() { - let segment_name = JavaString(String::from("segment-1")); + let segment_name = String::from("segment-1"); let segment_truncated = WireCommands::SegmentTruncated(SegmentTruncatedCommand { request_id: 1, segment: segment_name, @@ -522,8 +522,8 @@ fn test_segment_truncated() { #[test] fn test_delete_segment() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let delete_segment_command = WireCommands::DeleteSegment(DeleteSegmentCommand { request_id: 1, segment: segment_name, @@ -534,7 +534,7 @@ fn test_delete_segment() { #[test] fn test_segment_deleted() { - let segment = JavaString(String::from("segment-1")); + let segment = String::from("segment-1"); let segment_deleted = WireCommands::SegmentDeleted(SegmentDeletedCommand { request_id: 1, segment, @@ -544,8 +544,8 @@ fn test_segment_deleted() { #[test] fn test_delete_table_segment() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let delete_table_segment = WireCommands::DeleteTableSegment(DeleteTableSegmentCommand { request_id: 0, segment: segment_name, @@ -563,7 +563,7 @@ fn test_keep_alive() { #[test] fn test_auth_checked_failed() { - let stack_trace = JavaString(String::from("some exception")); + let stack_trace = String::from("some exception"); let auth_checked_failed = WireCommands::AuthTokenCheckFailed(AuthTokenCheckFailedCommand { request_id: 1, server_stack_trace: stack_trace, @@ -584,8 +584,8 @@ fn test_update_table_entries() { let value_data = String::from("value-1").into_bytes(); entries.push((TableKey::new(key_data, 1), TableValue::new(value_data))); let table_entries = TableEntries { entries }; - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let _size = table_entries.size(); let update_table_entries = WireCommands::UpdateTableEntries(UpdateTableEntriesCommand { request_id: 1, @@ -609,8 +609,8 @@ fn test_table_entries_updated() { #[test] fn test_remove_table_keys() { - let segment = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment = String::from("segment-1"); + let token = String::from("delegation_token"); let mut keys = Vec::::new(); let key_data = String::from("key-1").into_bytes(); keys.push(TableKey::new(key_data, 1)); @@ -625,7 +625,7 @@ fn test_remove_table_keys() { #[test] fn test_table_keys_removed() { - let segment = JavaString(String::from("segment-1")); + let segment = String::from("segment-1"); let table_key_removed = WireCommands::TableKeysRemoved(TableKeysRemovedCommand { request_id: 1, segment, @@ -635,8 +635,8 @@ fn test_table_keys_removed() { #[test] fn test_read_table() { - let segment = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment = String::from("segment-1"); + let token = String::from("delegation_token"); let mut keys = Vec::::new(); let key_data = String::from("key-1").into_bytes(); keys.push(TableKey::new(key_data, 1)); @@ -657,7 +657,7 @@ fn test_table_read() { let value_data = String::from("value-1").into_bytes(); entries.push((TableKey::new(key_data, 1), TableValue::new(value_data))); let table_entries = TableEntries { entries }; - let segment_name = JavaString(String::from("segment-1")); + let segment_name = String::from("segment-1"); let table_read = WireCommands::TableRead(TableReadCommand { request_id: 1, segment: segment_name, @@ -669,8 +669,8 @@ fn test_table_read() { #[test] fn test_read_table_keys() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let continuation_token: Vec = vec![1, 2, 3]; let read_table_keys = WireCommands::ReadTableKeys(ReadTableKeysCommand { request_id: 0, @@ -684,7 +684,7 @@ fn test_read_table_keys() { #[test] fn test_table_keys_read() { - let segment = JavaString(String::from("segment-1")); + let segment = String::from("segment-1"); let mut keys = Vec::::new(); let key_data = String::from("key-1").into_bytes(); keys.push(TableKey::new(key_data, 1)); @@ -700,8 +700,8 @@ fn test_table_keys_read() { #[test] fn test_read_table_entries() { - let segment_name = JavaString(String::from("segment-1")); - let token = JavaString(String::from("delegation_token")); + let segment_name = String::from("segment-1"); + let token = String::from("delegation_token"); let continuation_token: Vec = vec![1, 2, 3]; let read_table_entries = WireCommands::ReadTableEntries(ReadTableEntriesCommand { request_id: 0, @@ -715,7 +715,7 @@ fn test_read_table_entries() { #[test] fn test_table_entries_read() { - let segment_name = JavaString(String::from("segment-1")); + let segment_name = String::from("segment-1"); let continuation_token: Vec = vec![1, 2, 3]; let mut entries = Vec::<(TableKey, TableValue)>::new(); let key_data = String::from("key-1").into_bytes(); @@ -733,8 +733,8 @@ fn test_table_entries_read() { #[test] fn table_key_does_not_exist() { - let segment_name = JavaString(String::from("segment-1")); - let stack_trace = JavaString(String::from("some exception")); + let segment_name = String::from("segment-1"); + let stack_trace = String::from("some exception"); let table_key_does_not_exist = WireCommands::TableKeyDoesNotExist(TableKeyDoesNotExistCommand { request_id: 0, @@ -746,8 +746,8 @@ fn table_key_does_not_exist() { #[test] fn table_key_bad_version() { - let segment_name = JavaString(String::from("segment-1")); - let stack_trace = JavaString(String::from("some exception")); + let segment_name = String::from("segment-1"); + let stack_trace = String::from("some exception"); let table_key_bad_version = WireCommands::TableKeyBadVersion(TableKeyBadVersionCommand { request_id: 0, segment: segment_name, diff --git a/src/wire_protocol/wire_commands.rs b/src/wire_protocol/wire_commands.rs index 8d1e14aee..6c9c06823 100644 --- a/src/wire_protocol/wire_commands.rs +++ b/src/wire_protocol/wire_commands.rs @@ -1,6 +1,7 @@ use super::commands::*; use super::error::CommandError; use byteorder::{BigEndian, ByteOrder}; +use snafu::{Backtrace, GenerateBacktrace}; #[derive(PartialEq, Debug)] pub enum WireCommands { @@ -600,6 +601,7 @@ impl Decode for WireCommands { )), _ => Err(CommandError::InvalidType { command_type: type_code, + backtrace: Backtrace::generate(), }), } }