<commit_before># coding: utf-8
import unittest

from hazelcast.protocol.client_message import *

READ_HEADER = "00" * 16 + "1200"


class ClientMessageTest(unittest.TestCase):
    def test_header_fields(self):
        message = ClientMessage(payload_size=30)

        correlation_id = 6474838
        message_type = 987
        flags = 5
        partition_id = 27
        frame_length = 100
        data_offset = 17

        message.set_correlation_id(correlation_id)
        message.set_message_type(message_type)
        message.set_flags(flags)
        message.set_partition_id(partition_id)
        message.set_frame_length(frame_length)
        message.set_data_offset(data_offset)

        self.assertEqual(correlation_id, message.get_correlation_id())
        self.assertEqual(message_type, message.get_message_type())
        self.assertEqual(flags, message.get_flags())
        self.assertEqual(partition_id, message.get_partition_id())
        self.assertEqual(frame_length, message.get_frame_length())
        self.assertEqual(data_offset, message.get_data_offset())

    def test_append_byte(self):
        message = ClientMessage(payload_size=30)

        message.append_byte(0x21)
        message.append_byte(0xF2)
        message.append_byte(0x34)

        self.assertEqual("21f234", binascii.hexlify(message.buffer[18:21]))

    def test_append_bool(self):
        message = ClientMessage(payload_size=30)

        message.append_bool(True)

        self.assertEqual("01", binascii.hexlify(message.buffer[18:19]))

    def test_append_int(self):
        message = ClientMessage(payload_size=30)

        message.append_int(0x1feeddcc)

        self.assertEqual("ccddee1f", binascii.hexlify(message.buffer[18:22]))

    def test_append_long(self):
        message = ClientMessage(payload_size=30)

        message.append_long(0x1feeddccbbaa8765)

        self.assertEqual("6587aabbccddee1f", binascii.hexlify(message.buffer[18:26]))

    def test_append_str(self):
        message = ClientMessage(payload_size=30)

        frame_length = 1
        flags = 2
        message_type = 3
        correlation_id = 4
        partition_id = 5

        message.set_correlation_id(correlation_id)
        message.set_message_type(message_type)
        message.set_flags(flags)
        message.set_partition_id(partition_id)
        message.set_frame_length(frame_length)

        message.append_str("abc")

        # buffer content should be
        # 01000000 00 02 0300 04000000 05000000 1200 03000000 616263 0000000000000000000000000000000000000000000000
        self.assertEqual("01000000", binascii.hexlify(message.buffer[0:4]))
        self.assertEqual("00", binascii.hexlify(message.buffer[4:5]))
        self.assertEqual("02", binascii.hexlify(message.buffer[5:6]))
        self.assertEqual("0300", binascii.hexlify(message.buffer[6:8]))
        self.assertEqual("04000000", binascii.hexlify(message.buffer[8:12]))
        self.assertEqual("05000000", binascii.hexlify(message.buffer[12:16]))
        self.assertEqual("1200", binascii.hexlify(message.buffer[16:18]))
        self.assertEqual("03000000", binascii.hexlify(message.buffer[18:22]))
        self.assertEqual("616263", binascii.hexlify(message.buffer[22:25]))

        print message

    def test_read_byte(self):
        hexstr = READ_HEADER + "78"
        buf = binascii.unhexlify(hexstr)

        message = ClientMessage(buff=buf)
        self.assertEqual(0x78, message.read_byte())

    def test_read_bool(self):
        hexstr = READ_HEADER + "01"
        buf = binascii.unhexlify(hexstr)

        message = ClientMessage(buff=buf)
        self.assertEqual(True, message.read_bool())

    def test_read_int(self):
        hexstr = READ_HEADER + "12345678"
        buf = binascii.unhexlify(hexstr)

        message = ClientMessage(buff=buf)
        self.assertEqual(0x78563412, message.read_int())

    def test_read_long(self):
        hexstr = READ_HEADER + "6587aabbccddee1f"
        buf = binascii.unhexlify(hexstr)

        message = ClientMessage(buff=buf)
        self.assertEqual(0x1feeddccbbaa8765, message.read_long())
<commit_msg>update client message tests for correlation_id being 8 byte sized long value<commit_after># coding: utf-8
import unittest

from hazelcast.protocol.client_message import *

READ_HEADER = "00" * 20 + "1600"


class ClientMessageTest(unittest.TestCase):
    def test_header_fields(self):
        message = ClientMessage(payload_size=30)

        correlation_id = 6474838
        message_type = 987
        flags = 5
        partition_id = 27
        frame_length = 100
        data_offset = 17

        message.set_correlation_id(correlation_id)
        message.set_message_type(message_type)
        message.set_flags(flags)
        message.set_partition_id(partition_id)
        message.set_frame_length(frame_length)
        message.set_data_offset(data_offset)

        self.assertEqual(correlation_id, message.get_correlation_id())
        self.assertEqual(message_type, message.get_message_type())
        self.assertEqual(flags, message.get_flags())
        self.assertEqual(partition_id, message.get_partition_id())
        self.assertEqual(frame_length, message.get_frame_length())
        self.assertEqual(data_offset, message.get_data_offset())

    def test_append_byte(self):
        message = ClientMessage(payload_size=30)

        message.append_byte(0x21)
        message.append_byte(0xF2)
        message.append_byte(0x34)

        data_offset = message.get_data_offset()
        self.assertEqual("21f234", binascii.hexlify(message.buffer[data_offset:data_offset+3]))

    def test_append_bool(self):
        message = ClientMessage(payload_size=30)

        message.append_bool(True)

        data_offset = message.get_data_offset()
        self.assertEqual("01", binascii.hexlify(message.buffer[data_offset:data_offset+1]))

    def test_append_int(self):
        message = ClientMessage(payload_size=30)

        message.append_int(0x1feeddcc)

        data_offset = message.get_data_offset()
        self.assertEqual("ccddee1f", binascii.hexlify(message.buffer[data_offset:data_offset+4]))

    def test_append_long(self):
        message = ClientMessage(payload_size=30)

        message.append_long(0x1feeddccbbaa8765)

        data_offset = message.get_data_offset()
        self.assertEqual("6587aabbccddee1f", binascii.hexlify(message.buffer[data_offset:data_offset+8]))

    def test_append_str(self):
        message = ClientMessage(payload_size=30)

        frame_length = 1
        flags = 2
        message_type = 3
        correlation_id = 4
        partition_id = 5

        message.set_correlation_id(correlation_id)
        message.set_message_type(message_type)
        message.set_flags(flags)
        message.set_partition_id(partition_id)
        message.set_frame_length(frame_length)

        message.append_str("abc")

        # buffer content should be
        # 01000000 00 02 0300 0400000000000000 05000000 1600 03000000 616263 0000000000000000000000000000000000000000000000
        self.assertEqual("01000000", binascii.hexlify(message.buffer[0:4]))
        self.assertEqual("00", binascii.hexlify(message.buffer[4:5]))
        self.assertEqual("02", binascii.hexlify(message.buffer[5:6]))
        self.assertEqual("0300", binascii.hexlify(message.buffer[6:8]))
        self.assertEqual("0400000000000000", binascii.hexlify(message.buffer[8:16]))
        self.assertEqual("05000000", binascii.hexlify(message.buffer[16:20]))
        self.assertEqual("1600", binascii.hexlify(message.buffer[20:22]))
        self.assertEqual("03000000", binascii.hexlify(message.buffer[22:26]))
        self.assertEqual("616263", binascii.hexlify(message.buffer[26:29]))

        print message

    def test_read_byte(self):
        hexstr = READ_HEADER + "78"
        buf = binascii.unhexlify(hexstr)

        message = ClientMessage(buff=buf)
        self.assertEqual(0x78, message.read_byte())

    def test_read_bool(self):
        hexstr = READ_HEADER + "01"
        buf = binascii.unhexlify(hexstr)

        message = ClientMessage(buff=buf)
        self.assertEqual(True, message.read_bool())

    def test_read_int(self):
        hexstr = READ_HEADER + "12345678"
        buf = binascii.unhexlify(hexstr)

        message = ClientMessage(buff=buf)
        self.assertEqual(0x78563412, message.read_int())

    def test_read_long(self):
        hexstr = READ_HEADER + "6587aabbccddee1f"
        buf = binascii.unhexlify(hexstr)

        message = ClientMessage(buff=buf)
        self.assertEqual(0x1feeddccbbaa8765, message.read_long())

{'fraction_non_alphanumeric': 0.10245663057398999, 'fraction_numerical': 0.06974036558388637, 'mean_word_length': 3.351570415400203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5690926', 'n_tokens_mistral': 3110, 'n_tokens_neox': 2591, 'n_words': 371}