Sha256: d59e086a1bc7040d4dde04823fc7ca028b97084e35d90a7ea9af66251b876466

Contents?: true

Size: 1.87 KB

Versions: 19

Compression:

Stored size: 1.87 KB

Contents

require 'spec_helper'
require 'spec/support/test/resource_service'

describe 'Functional ZMQ Client' do
  before(:all) do
    load "protobuf/zmq.rb"
    Thread.abort_on_exception = true
    server = OpenStruct.new(:host => "127.0.0.1", 
                            :port => 9399, 
                            :worker_port => 9400, 
                            :backlog => 100, 
                            :threshold => 100, 
                            :threads => 5)

    @server_thread = Thread.new(server) { |s| Protobuf::Rpc::ZmqRunner.run(s) }
    Thread.pass until Protobuf::Rpc::Zmq::Server.running?
  end

  after(:all) do
    ::Protobuf::Rpc::Zmq::Server.stop
    @server_thread.try(:join)
  end

  it 'runs fine when required fields are set' do
    expect {
      client = ::Test::ResourceService.client

      client.find(:name => 'Test Name', :active => true) do |c|
        c.on_success do |succ|
          succ.name.should eq("Test Name")
          succ.status.should eq(::Test::StatusType::ENABLED)
        end

        c.on_failure do |err|
          raise err.inspect
        end
      end
    }.to_not raise_error
  end

  it 'calls the on_failure callback when a message is malformed' do
    error = nil
    request = ::Test::ResourceFindRequest.new(:active => true)
    client = ::Test::ResourceService.client

    client.find(request) do |c|
      c.on_success { raise "shouldn't pass"}
      c.on_failure {|e| error = e}
    end
    error.message.should =~ /name.*required/
  end

  it 'calls the on_failure callback when the request type is wrong' do
    error = nil
    request = ::Test::Resource.new(:name => 'Test Name')
    client = ::Test::ResourceService.client

    client.find(request) do |c|
      c.on_success { raise "shouldn't pass"}
      c.on_failure {|e| error = e}
    end
    error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
protobuf-2.7.12 spec/functional/zmq_server_spec.rb
protobuf-2.7.11-java spec/functional/zmq_server_spec.rb
protobuf-2.7.11 spec/functional/zmq_server_spec.rb
protobuf-2.7.10-java spec/functional/zmq_server_spec.rb
protobuf-2.7.10 spec/functional/zmq_server_spec.rb
protobuf-2.7.9-java spec/functional/zmq_server_spec.rb
protobuf-2.7.9 spec/functional/zmq_server_spec.rb
protobuf-2.7.8-java spec/functional/zmq_server_spec.rb
protobuf-2.7.8 spec/functional/zmq_server_spec.rb
protobuf-2.7.7-java spec/functional/zmq_server_spec.rb
protobuf-2.7.7 spec/functional/zmq_server_spec.rb
protobuf-2.7.6-java spec/functional/zmq_server_spec.rb
protobuf-2.7.6 spec/functional/zmq_server_spec.rb
protobuf-2.7.5-java spec/functional/zmq_server_spec.rb
protobuf-2.7.5 spec/functional/zmq_server_spec.rb
protobuf-2.7.4-java spec/functional/zmq_server_spec.rb
protobuf-2.7.4 spec/functional/zmq_server_spec.rb
protobuf-2.7.3-java spec/functional/zmq_server_spec.rb
protobuf-2.7.3 spec/functional/zmq_server_spec.rb