Sha256: 229d74384a59f54d83a0dd74c56b9e5e556a9830e03196f86f9d1792733c67f9

Contents?: true

Size: 1.81 KB

Versions: 19

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 healty 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

19 entries across 19 versions & 1 rubygems

Version Path
fluentd-1.8.0.rc3 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.8.0.rc2 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.8.0.rc1 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.4-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.4-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.4 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.3-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.3-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.3 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.2-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.2-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.2 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.1-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.1-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.1 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.0-x64-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.0-x86-mingw32 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.0 test/plugin/out_forward/test_load_balancer.rb
fluentd-1.7.0.rc1 test/plugin/out_forward/test_load_balancer.rb