Sha256: 190057bef55054d82bd7161a8944b3ccd722aa80a0cd3caa85430251cc443d72

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 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'

# Register an appender if one is not already registered
if SemanticLogger::Logger.appenders.size == 0
  SemanticLogger::Logger.default_level = :trace
  SemanticLogger::Logger.appenders << SemanticLogger::Appender::File.new('test.log')
end

RubySkynet::Server.port = 2100
RubySkynet::Server.region = 'Test'
RubySkynet::Server.hostname = '127.0.0.1'

class TestService
  include RubySkynet::Service

  # Methods implemented by this service
  # Must take a Hash as input
  # Must Return a Hash response or nil for no response
  def echo(params)
    params
  end
end

# Unit Test for ResilientSocket::TCPClient
class RubySkynetServiceTest < Test::Unit::TestCase
  context 'RubySkynet::Service' do
    context "with server" do
      setup do
        RubySkynet::Server.start
        @service_name = 'TestService'
        @version = 1
        @region = 'Test'
        @doozer_key = "/services/#{@service_name}/#{@version}/#{@region}/127.0.0.1/2100"
      end

      teardown do
        begin
          RubySkynet::Server.stop
        rescue Celluloid::DeadActorError
        end
      end

      should "have correct service key" do
        assert_equal @doozer_key, TestService.service_key
      end

      should "register service" do
        RubySkynet::Registry.doozer_pool.with_connection do |doozer|
          assert_equal true, doozer[@doozer_key].length > 20
        end
      end

      context "calling with a client" do
        setup do
          @client = RubySkynet::Client.new(@service_name, @version, @region)
        end

        should "successfully send and receive data" do
          reply = @client.call(:echo, 'some' => 'parameters')
          assert_equal 'some', reply.keys.first
          assert_equal 'parameters', reply.values.first
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby_skynet-0.4.0.pre2 test/ruby_skynet_service_test.rb
ruby_skynet-0.4.0.pre test/ruby_skynet_service_test.rb