Sha256: dca1a36b641f3275320f0dc37b9e38765a2c4f7c753fbe20d4c0c9f0ad719011

Contents?: true

Size: 1.72 KB

Versions: 20

Compression:

Stored size: 1.72 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, :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.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 =~ /ResourceFindRequest.*fields.*improperly set/
  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

20 entries across 20 versions & 1 rubygems

Version Path
protobuf-2.3.2-java spec/functional/zmq_server_spec.rb
protobuf-2.3.2 spec/functional/zmq_server_spec.rb
protobuf-2.3.1-java spec/functional/zmq_server_spec.rb
protobuf-2.3.1 spec/functional/zmq_server_spec.rb
protobuf-2.3.0-java spec/functional/zmq_server_spec.rb
protobuf-2.3.0 spec/functional/zmq_server_spec.rb
protobuf-2.2.7-java spec/functional/zmq_server_spec.rb
protobuf-2.2.7 spec/functional/zmq_server_spec.rb
protobuf-2.2.6-java spec/functional/zmq_server_spec.rb
protobuf-2.2.6 spec/functional/zmq_server_spec.rb
protobuf-2.2.5-java spec/functional/zmq_server_spec.rb
protobuf-2.2.5 spec/functional/zmq_server_spec.rb
protobuf-2.2.4 spec/functional/zmq_server_spec.rb
protobuf-2.2.3 spec/functional/zmq_server_spec.rb
protobuf-2.2.2 spec/functional/zmq_server_spec.rb
protobuf-2.2.1 spec/functional/zmq_server_spec.rb
protobuf-2.2.0 spec/functional/zmq_server_spec.rb
protobuf-2.1.3 spec/functional/zmq_server_spec.rb
protobuf-2.1.2 spec/functional/zmq_server_spec.rb
protobuf-2.1.1 spec/functional/zmq_server_spec.rb