Skip to content
This repository
tree: c3436b88b7
Fetching contributors…

Cannot retrieve contributors at this time

file 55 lines (45 sloc) 1.742 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
require 'ReflectorClient'
require 'runit/testcase'
require 'ReflectorServer'
require "thread"

class ReflectorClientTestCase < RUNIT::TestCase

  def test_reflectMessages

    serverMessages = "E8=FIX.4.2\0019=13\00135=AC\001108=30\00110=31\001\n"
    serverMessages += "I8=FIX.4.2\0019=13\00135=AS\001108=10\00110=31\001\n"
    serverMessages += "E8=FIX.4.2\0019=13\00135=BC\001108=25\00110=31\001\n"
    serverMessages += "I8=FIX.4.2\0019=13\00135=BS\001108=15\00110=31\001\n"

    clientMessages = "iCONNECT\n"
    clientMessages += "I8=FIX.4.2\0019=13\00135=AC\001108=30\00110=31\001\n"
    clientMessages += "E8=FIX.4.2\0019=13\00135=AS\001108=10\00110=31\001\n"
    clientMessages += "I8=FIX.4.2\0019=13\00135=BC\001108=25\00110=31\001\n"
    clientMessages += "E8=FIX.4.2\0019=13\00135=BS\001108=15\00110=31\001\n"
    clientMessages += "iDISCONNECT\n"

    server = ReflectorServer.new(serverMessages)
    client = ReflectorClient.new(clientMessages, "localhost", RUNIT::TestCase.port)

    def client.next
      begin
return @queue.pop 0
      rescue
return nil
      end
    end

    def client.compareAction(e, a)
      if !defined? @queue
@queue = Queue.new
      end
      @queue.push(e)
      @queue.push(a)
    end
    
    Thread.start do
      server.listen(RUNIT::TestCase.port)
    end
    server.wait

    client.start()
    assert_equals("8=FIX.4.2\0019=13\00135=AS\001108=10\00110=31\001", client.next)
    assert_equals("8=FIX.4.2\0019=13\00135=AS\001108=10\00110=31\001", client.next)
    assert_equals("8=FIX.4.2\0019=13\00135=BS\001108=15\00110=31\001", client.next)
    assert_equals("8=FIX.4.2\0019=13\00135=BS\001108=15\00110=31\001", client.next)
    assert_equals(nil, client.next)
    server.stop
  end

end
Something went wrong with that request. Please try again.