Exemple #1
0
    def test_to_and_from_bytes(self):
        block_size = 64
        block = b'a' * block_size
        segment = ReadWriteSegment(123, block_size=block_size)
        block_number = segment.write_data(block)

        serialized = segment.to_bytes()
        deserialized = ReadOnlySegment(serialized, 123, block_size=block_size)

        self.assertEqual(
            deserialized.read_block(block_number)[:len(block)], block)
Exemple #2
0
    def test_to_read_only_should_return_a_read_only_segment_with_same_bytes(
            self):
        block_size = 64
        segment = ReadWriteSegment(123, block_size=block_size)
        block_bytes = block_size * b'a'
        segment.write_data(block_bytes)
        segment.write_inode(block_bytes, 123)
        read_only = segment.to_read_only()

        self.assertIsInstance(read_only, ReadOnlySegment)
        self.assertEqual(read_only.to_bytes(), segment.to_bytes())
Exemple #3
0
    def test_read_block_from_a_previous_segment_should_return_the_block(self):
        block_size = 64
        address = BlockAddress(123, 1)
        block_bytes = b'abc'
        segment = ReadWriteSegment(123, block_size=block_size)
        segment.write_data(block_size * b'x')
        segment.write_data(block_bytes)
        backend = Mock()
        backend.get_segment.return_value = segment.to_bytes()
        log = Log(999, backend, block_size=block_size)

        result = log.read_block(address)

        self.assertEqual(bytes(result[:len(block_bytes)]), block_bytes)
        backend.get_segment.assert_called_once_with(address.segmentid)