Sha256: 8baf9991d3dbbc62635c83147081295f97a93e93ea051f3fa3de94c999506507

Contents?: true

Size: 1.59 KB

Versions: 156

Compression:

Stored size: 1.59 KB

Contents

require_relative 'helper'
require 'fluent/variable_store'

class VariableStoreTest < Test::Unit::TestCase
  def setup
  end

  def teardown
    Fluent::VariableStore.try_to_reset do
      # nothing
    end
  end

  sub_test_case '#fetch_or_build' do
    test 'fetch same object when the same key is passed' do
      c1 = Fluent::VariableStore.fetch_or_build(:test)
      c2 = Fluent::VariableStore.fetch_or_build(:test)

      assert_equal c1, c2
      assert_equal c1.object_id, c2.object_id

      c3 = Fluent::VariableStore.fetch_or_build(:test2)
      assert_not_equal c1.object_id, c3.object_id
    end

    test 'can be passed a default value' do
      c1 = Fluent::VariableStore.fetch_or_build(:test, default_value: Set.new)
      c2 = Fluent::VariableStore.fetch_or_build(:test)

      assert_kind_of Set, c1
      assert_equal c1, c2
      assert_equal c1.object_id, c2.object_id
    end
  end

  sub_test_case '#try_to_reset' do
    test 'reset all values' do
      c1 = Fluent::VariableStore.fetch_or_build(:test)
      c1[:k1] = 1
      assert_equal 1, c1[:k1]

      Fluent::VariableStore.try_to_reset do
        # nothing
      end

      c1 = Fluent::VariableStore.fetch_or_build(:test)
      assert_nil c1[:k1]
    end

    test 'rollback resetting if error raised' do
      c1 = Fluent::VariableStore.fetch_or_build(:test)
      c1[:k1] = 1
      assert_equal 1, c1[:k1]

      assert_raise(RuntimeError.new('pass')) do
        Fluent::VariableStore.try_to_reset do
          raise 'pass'
        end
      end

      c1 = Fluent::VariableStore.fetch_or_build(:test)
      assert_equal 1, c1[:k1]
    end
  end
end

Version data entries

156 entries across 156 versions & 7 rubygems

Version Path
fluentd-1.14.5-x86-mingw32 test/test_variable_store.rb
fluentd-1.14.5-x64-mingw32 test/test_variable_store.rb
fluentd-1.14.5 test/test_variable_store.rb
fluentd-1.14.4-x64-mingw-ucrt test/test_variable_store.rb
fluentd-1.14.4-x64-mingw32 test/test_variable_store.rb
fluentd-1.14.4-x86-mingw32 test/test_variable_store.rb
fluentd-1.14.4 test/test_variable_store.rb
fluentd-1.14.3-x86-mingw32 test/test_variable_store.rb
fluentd-1.14.3-x64-mingw32 test/test_variable_store.rb
fluentd-1.14.3 test/test_variable_store.rb
fluentd-1.14.2-x86-mingw32 test/test_variable_store.rb
fluentd-1.14.2-x64-mingw32 test/test_variable_store.rb
fluentd-1.14.2 test/test_variable_store.rb
fluentd-1.14.1-x86-mingw32 test/test_variable_store.rb
fluentd-1.14.1-x64-mingw32 test/test_variable_store.rb
fluentd-1.14.1 test/test_variable_store.rb
fluentd-1.14.0-x86-mingw32 test/test_variable_store.rb
fluentd-1.14.0-x64-mingw32 test/test_variable_store.rb
fluentd-1.14.0 test/test_variable_store.rb
fluentd-1.14.0.rc test/test_variable_store.rb