Sha256: eb7c5cf126ff5dbab68599a9eb111856f13d96b2a2809618d67b4686400de287

Contents?: true

Size: 1.99 KB

Versions: 5

Compression:

Stored size: 1.99 KB

Contents

# Allow test to be run in-place without requiring a gem install
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'

require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'ruby_skynet/doozer/client'

# NOTE:
# This test assumes that doozerd is running locally on the default port of 8046

# Unit Test for RubySkynet::Doozer::Client
class DoozerClientTest < Test::Unit::TestCase
  context RubySkynet::Doozer::Client do

    context "without server" do
      should "raise exception when cannot reach doozer server after 5 retries" do
        exception = assert_raise ResilientSocket::ConnectionFailure do
          RubySkynet::Doozer::Client.new(
            # Bad server address to test exception is raised
            :server                 => 'localhost:9999',
            :connect_retry_interval => 0.1,
            :connect_retry_count    => 5)
        end
        assert_match /After 5 connection attempts to host 'localhost:9999': Errno::ECONNREFUSED/, exception.message
      end

    end

    context "with client connection" do
      setup do
        @client = RubySkynet::Doozer::Client.new(:server => 'localhost:8046')
      end

      def teardown
        if @client
          @client.close
          @client.delete('/test/foo')
        end
      end

      should "return current revision" do
        assert @client.current_revision >= 0
      end

      should "successfully set and get data" do
        new_revision = @client.set('/test/foo', 'value')
        result = @client.get('/test/foo')
        assert_equal 'value', result.value
        assert_equal new_revision, result.rev
      end

      should "successfully set and get data using array operators" do
        @client['/test/foo'] = 'value2'
        result = @client['/test/foo']
        assert_equal 'value2', result
      end

      should "fetch directories in a path" do
        @path = '/'
        count = 0
        until @client.directory(@path, count).nil?
          count += 1
        end
        assert count > 0
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ruby_skynet-0.5.0 test/doozer_client_test.rb
ruby_skynet-0.4.0 test/doozer_client_test.rb
ruby_skynet-0.4.0.pre2 test/doozer_client_test.rb
ruby_skynet-0.4.0.pre test/doozer_client_test.rb
ruby_skynet-0.3.0 test/doozer_client_test.rb