class TestHostStompEngine(unittest.TestCase):

    engine = inject.attr('stompEngine')

    def setUp(self):
        self.stompProtocol = StompProtocolFactory().buildProtocol(
            ('127.0.0.1', 0))
        self.fakeTransport = proto_helpers.StringTransport()

    def tearDown(self):
        self.fakeTransport.clear()

    def test_connection(self):
        self.stompProtocol.makeConnection(self.fakeTransport)
        #ignore the connection request sent. We aren't testing that here
        self.fakeTransport.clear()

        #pretend we've received successful ack of our connection request.
        #check that the host engine subscribes to the topics upon connection
        connectedMsg = """CONNECTED
session:ID:snorky.local-49191-1185461799654-3:18"""
        self.stompProtocol.dataReceived(connectedMsg)

        msg1 = stomper.subscribe(destinations.CONN_DESTINATION)
        msg2 = stomper.subscribe(destinations.CMD_RES_DESTINATION)

        self.assertTrue(msg1 in self.fakeTransport.value())
        self.assertTrue(msg2 in self.fakeTransport.value())
Example #2
0
def start(config, brokerTimeout=60.0):
    """
  Start twisted event loop and the fun should begin...

  @param brokerTimeout how long to wait for a broker 
  
  @return a negative number upon failure. Otherwise, it never returns.
  """

    manager = multiprocessing.Manager()
    serverUpEvent = manager.Event()
    broker = multiprocessing.Process(target=startSTOMPBroker,
                                     args=(config, serverUpEvent))
    broker.daemon = True
    broker.name = 'STOMP-Broker'
    broker.start()

    serverUpEvent.wait(brokerTimeout)
    if not serverUpEvent.is_set():
        logger.fatal("Broker not available after %.1f seconds. Giving up",
                     brokerTimeout)
        return -1

    stompProtocolFactory = StompProtocolFactory()

    xmlrpcService = HostXMLRPCService()
    xmlrpcService.makeEngineAccesible()

    host = config.get('Broker', 'host')
    port = int(config.get('Broker', 'port'))
    reactor.connectTCP(host, port, stompProtocolFactory)
    reactor.run()
Example #3
0
class TestStompProtocolFactory(unittest.TestCase):
    class _MyFakeConnector(proto_helpers._FakeConnector):
        connectionAttempts = 0

        def connect(self):
            self.connectionAttempts += 1

    #God bless Python!
    proto_helpers._FakeConnector = _MyFakeConnector

    def setUp(self):
        self.factory = StompProtocolFactory()

    def _fakeConnect(self_):
        self_.connectionAttempts += 1

    def test_reconnection(self):
        clock = task.Clock()
        self.factory.clock = clock
        self.factory.maxRetries = 3

        fakeReactor = proto_helpers.MemoryReactor()
        self.assertEquals(0, len(fakeReactor.tcpClients))
        connector = fakeReactor.connectTCP('fakehost', 1234, self.factory)
        self.assertEquals(1, len(fakeReactor.tcpClients))

        for i in xrange(self.factory.maxRetries):
            self.factory.clientConnectionFailed(connector, "Attempt %d" % i)
            self.assertEquals(1, len(clock.getDelayedCalls()))

            clock.advance(self.factory.delay)
            self.assertEquals(0, len(clock.getDelayedCalls()))
            self.assertEquals(i + 1, connector.connectionAttempts)

        self.factory.clientConnectionFailed(connector, "Attempt %d" % i)
        self.assertEquals(0, len(clock.getDelayedCalls()))

        clock.advance(self.factory.delay)
        self.assertEquals(self.factory.retries - 1,
                          connector.connectionAttempts)
class TestStompProtocolFactory(unittest.TestCase):
  class _MyFakeConnector( proto_helpers._FakeConnector ):
    connectionAttempts = 0
    def connect(self):
      self.connectionAttempts += 1

  #God bless Python!
  proto_helpers._FakeConnector = _MyFakeConnector

  def setUp(self):
    self.factory = StompProtocolFactory()

  def _fakeConnect(self_):
    self_.connectionAttempts += 1

  def test_reconnection(self):
    clock = task.Clock()
    self.factory.clock = clock
    self.factory.maxRetries = 3

    fakeReactor = proto_helpers.MemoryReactor()
    self.assertEquals(0, len(fakeReactor.tcpClients))
    connector = fakeReactor.connectTCP('fakehost', 1234, self.factory)
    self.assertEquals(1, len(fakeReactor.tcpClients))

    for i in xrange( self.factory.maxRetries ):
      self.factory.clientConnectionFailed(connector, "Attempt %d" % i)
      self.assertEquals(1, len(clock.getDelayedCalls()))

      clock.advance( self.factory.delay )
      self.assertEquals(0, len(clock.getDelayedCalls()))
      self.assertEquals(i+1, connector.connectionAttempts)

    self.factory.clientConnectionFailed(connector, "Attempt %d" % i)
    self.assertEquals(0, len(clock.getDelayedCalls()))

    clock.advance( self.factory.delay )
    self.assertEquals(self.factory.retries-1, connector.connectionAttempts)
def start(config):
    """Start twisted event loop and the fun should begin..."""
    host = config.get('Broker', 'host')
    port = int(config.get('Broker', 'port'))
    username = config.get('Broker', 'username')
    password = config.get('Broker', 'password')

    stompProtocolFactory = StompProtocolFactory()

    #spawnChirpServerProcess(config)

    #reactor.connectTCP(host, port, stompProtocolFactory)
    #reactor.run()
    return internet.TCPClient(host, port, stompProtocolFactory)
Example #6
0
    def setUp(self):
        factory = StompProtocolFactory()

        self.protocol = factory.buildProtocol(
            ('127.0.0.1', 0))  #addr isn't used anyway: we are faking it
        self.fakeTransport = proto_helpers.StringTransport()
Example #7
0
 def setUp(self):
     self.factory = StompProtocolFactory()
  def setUp(self):
    factory = StompProtocolFactory()

    self.protocol = factory.buildProtocol(('127.0.0.1',0)) #addr isn't used anyway: we are faking it
    self.fakeTransport = proto_helpers.StringTransport()
 def setUp(self):
   self.factory = StompProtocolFactory()
 def setUp(self):
     self.stompProtocol = StompProtocolFactory().buildProtocol(
         ('127.0.0.1', 0))
     self.fakeTransport = proto_helpers.StringTransport()