1
0
mirror of https://github.com/bspeice/aeron-rs synced 2024-12-21 05:28:10 -05:00

Finish write tests from Aeron

This commit is contained in:
Bradlee Speice 2019-11-02 19:12:27 -04:00
parent fff850f6b7
commit daecbf2e2f
2 changed files with 25 additions and 25 deletions

View File

@ -430,31 +430,6 @@ mod tests {
assert_eq!(write_start, 16);
}
#[test]
fn write_basic() {
let mut ring_buffer =
ManyToOneRingBuffer::new(vec![0u8; BUFFER_SIZE]).expect("Invalid buffer size");
let source_bytes = &mut [12u8, 0, 0, 0][..];
let source_len = source_bytes.len() as IndexT;
let type_id = 1;
ring_buffer
.write(type_id, &source_bytes, 0, source_len)
.unwrap();
let record_len = source_len + record_descriptor::HEADER_LENGTH;
assert_eq!(
ring_buffer.get_i64_volatile(0).unwrap(),
record_descriptor::make_header(record_len, type_id)
);
assert_eq!(
ring_buffer
.get_i64_volatile(size_of::<i64>() as IndexT)
.unwrap(),
12
);
}
#[test]
fn read_basic() {
// Similar to write basic, put something into the buffer

View File

@ -155,3 +155,28 @@ fn should_insert_padding_record_plus_message_on_buffer_wrap() {
Ok((tail + aligned_record_length + record_descriptor::ALIGNMENT) as i64)
);
}
#[test]
fn should_insert_padding_record_plus_message_on_buffer_wrap_with_head_equal_to_tail() {
let length: IndexT = 100;
let record_length: IndexT = length + record_descriptor::HEADER_LENGTH;
let aligned_record_length: IndexT = align(record_length as usize, record_descriptor::ALIGNMENT as usize) as IndexT;
let tail: IndexT = CAPACITY as IndexT - record_descriptor::ALIGNMENT;
let head: IndexT = tail;
let src_index: IndexT = 0;
let mut buffer = ManyToOneRingBuffer::new(vec![0u8; BUFFER_SZ]).unwrap();
buffer.put_i64(HEAD_COUNTER_INDEX, head as i64).unwrap();
buffer.put_i64(TAIL_COUNTER_INDEX, tail as i64).unwrap();
let src_bytes = vec![0u8; BUFFER_SZ];
let write_res = buffer.write(MSG_TYPE_ID, &src_bytes, src_index, length);
assert_eq!(write_res, Ok(true));
assert_eq!(buffer.get_i32(record_descriptor::type_offset(tail)), Ok(record_descriptor::PADDING_MSG_TYPE_ID));
assert_eq!(buffer.get_i32(record_descriptor::length_offset(tail)), Ok(record_descriptor::ALIGNMENT));
assert_eq!(buffer.get_i32(record_descriptor::length_offset(0)), Ok(record_length));
assert_eq!(buffer.get_i32(record_descriptor::type_offset(0)), Ok(MSG_TYPE_ID));
assert_eq!(buffer.get_i64(TAIL_COUNTER_INDEX), Ok((tail + aligned_record_length + record_descriptor::ALIGNMENT) as i64));
}