<commit_before>require File.expand_path(File.dirname(__FILE__) + '/../test_helper')


module Beetle

  class EncodingTest < Test::Unit::TestCase

    test "a message should encode/decode the message format version correctly" do
      header = header_with_params({})
      m = Message.new("queue", header, 'foo')
      assert_equal Message::FORMAT_VERSION, m.format_version
    end

    test "a redundantly encoded message should have the redundant flag set on delivery" do
      header = header_with_params(:redundant => true)
      m = Message.new("queue", header, 'foo')
      assert m.redundant?
      assert_equal(Message::FLAG_REDUNDANT, m.flags & Message::FLAG_REDUNDANT)
    end

    test "encoding a message with a specfied time to live should set an expiration time" do
      Message.expects(:now).returns(25)
      header = header_with_params(:ttl => 17)
      m = Message.new("queue", header, 'foo')
      assert_equal 42, m.expires_at
    end

    test "encoding a message should set the default expiration date if none is provided in the call to encode" do
      Message.expects(:now).returns(1)
      header = header_with_params({})
      m = Message.new("queue", header, 'foo')
      assert_equal 1 + Message::DEFAULT_TTL, m.expires_at
    end<commit_msg>test for the decoding fallback<commit_after>require File.expand_path(File.dirname(__FILE__) + '/../test_helper')


module Beetle

  class EncodingTest < Test::Unit::TestCase

    test "a message should encode/decode the message format version correctly" do
      header = header_with_params({})
      m = Message.new("queue", header, 'foo')
      assert_equal Message::FORMAT_VERSION, m.format_version
    end

    test "a redundantly encoded message should have the redundant flag set on delivery" do
      header = header_with_params(:redundant => true)
      m = Message.new("queue", header, 'foo')
      assert m.redundant?
      assert_equal(Message::FLAG_REDUNDANT, m.flags & Message::FLAG_REDUNDANT)
    end

    test "encoding a message with a specfied time to live should set an expiration time" do
      Message.expects(:now).returns(25)
      header = header_with_params(:ttl => 17)
      m = Message.new("queue", header, 'foo')
      assert_equal 42, m.expires_at
    end

    test "encoding a message should set the default expiration date if none is provided in the call to encode" do
      Message.expects(:now).returns(1)
      header = header_with_params({})
      m = Message.new("queue", header, 'foo')
      assert_equal 1 + Message::DEFAULT_TTL, m.expires_at
    end

    test "decoding a message should be able to decode messages which were encoded with the old encoding mechanism" do
      header = stub("header")
      header.stubs(:properties).returns({})
      payload = 'foobar'
      v1_message_body = Message.encode_v1(payload)
      v1_message = Message.new(:fooqueue, header, v1_message_body, {})

      assert_equal payload, v1_message.data
      assert_equal 1, v1_message.format_version
    end
{'fraction_non_alphanumeric': 0.09773182121414276, 'fraction_numerical': 0.007671781187458306, 'mean_word_length': 3.5097744360902254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '3192483', 'n_tokens_mistral': 896, 'n_tokens_neox': 861, 'n_words': 272}