Sha256: 7ca1e586d3aa3742f615d42e421e328e634a696d6db41ebc0dd7a110857ac8c5

Contents?: true

Size: 1.81 KB

Versions: 32

Compression:

Stored size: 1.81 KB

Contents

require_relative '../../helper'
require 'flexmock/test_unit'

require 'fluent/plugin/out_forward/load_balancer'

class LoadBalancerTest < Test::Unit::TestCase
  sub_test_case 'select_healthy_node' do
    test 'select healthy node' do
      lb = Fluent::Plugin::ForwardOutput::LoadBalancer.new($log)
      n1 = flexmock('node', :'standby?' => false, :'available?' => false, weight: 1)
      n2 = flexmock('node', :'standby?' => false, :'available?' => true, weight: 1)

      lb.rebuild_weight_array([n1, n2])
      lb.select_healthy_node do |node|
        assert_equal(node, n2)
      end

      lb.select_healthy_node do |node|
        assert_equal(node, n2)
      end
    end

    test 'call like round robin' do
      lb = Fluent::Plugin::ForwardOutput::LoadBalancer.new($log)
      n1 = flexmock('node', :'standby?' => false, :'available?' => true, weight: 1)
      n2 = flexmock('node', :'standby?' => false, :'available?' => true, weight: 1)

      lb.rebuild_weight_array([n1, n2])

      lb.select_healthy_node do |node|
        # to handle random choice
        if node == n1
          lb.select_healthy_node do |node|
            assert_equal(node, n2)
          end

          lb.select_healthy_node do |node|
            assert_equal(node, n1)
          end
        else
          lb.select_healthy_node do |node|
            assert_equal(node, n1)
          end

          lb.select_healthy_node do |node|
            assert_equal(node, n2)
          end
        end
      end
    end

    test 'raise an error if all node are unavialble' do
      lb = Fluent::Plugin::ForwardOutput::LoadBalancer.new($log)
      lb.rebuild_weight_array([flexmock('node', :'standby?' => false, :'available?' => false, weight: 1)])
      assert_raise(Fluent::Plugin::ForwardOutput::NoNodesAvailable) do
        lb.select_healthy_node
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
fluentd-1.10.3-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.3-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.3 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.2-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.2-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.2 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.1-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.1-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.1 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.0-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.0-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.10.0 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.9.3-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.9.3-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.9.3 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.9.2-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.9.2-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.9.2 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.9.1-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.9.1-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb