Beispiel #1
0
 def test_not_connected(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.send('/queue/fake')
     except StompConnectionError:
         pass
     else:
         raise Exception(
             'Expected connection error, but nothing frame could be sent.')
Beispiel #2
0
 def test_connected_timeout(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.connect(connectedTimeout=self.TIMEOUT)
     except StompCancelledError:
         pass
     else:
         raise Exception(
             'Expected connected timeout, but connection was established.')
Beispiel #3
0
 def test_stomp_protocol_error_on_connect(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port)
     client = Stomp(config)
     try:
         yield client.connect()
     except StompProtocolError:
         pass
     else:
         raise Exception(
             'Expected a StompProtocolError, but nothing was raised.')
Beispiel #4
0
 def test_connected_timeout_after_failover(self):
     port = self.connections[0].getHost().port
     config = StompConfig(
         uri=
         'failover:(tcp://nosuchhost:65535,tcp://localhost:%d)?startupMaxReconnectAttempts=2,initialReconnectDelay=0,randomize=false'
         % port)
     client = Stomp(config)
     try:
         yield client.connect(connectedTimeout=self.TIMEOUT)
     except StompCancelledError:
         pass
     else:
         raise Exception(
             'Expected connected timeout, but connection was established.')
Beispiel #5
0
    def test_failover_on_connection_lost(self):
        ports = tuple(c.getHost().port for c in self.connections)
        config = StompConfig(
            uri=
            'failover:(tcp://localhost:%d,tcp://localhost:%d)?startupMaxReconnectAttempts=0,initialReconnectDelay=0,randomize=false,maxReconnectAttempts=1'
            % ports)
        client = Stomp(config)

        yield client.connect()
        self.connections[0].stopListening()
        queue = '/queue/fake'
        client.send(queue, b'shutdown')
        try:
            yield client.disconnected
        except StompConnectionError:
            yield client.connect()
        else:
            raise Exception('Unexpected clean disconnect.')
        client.send(queue, b'fake message')

        try:
            yield client.disconnected
        except StompProtocolError:
            pass
        else:
            raise Exception('Unexpected clean disconnect.')
Beispiel #6
0
    def test_disconnect_on_stomp_protocol_error(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri='tcp://localhost:%d' % port)
        client = Stomp(config)

        yield client.connect()
        client.send('/queue/fake', b'fake message')
        try:
            yield client.disconnected
        except StompProtocolError as e:
            self.assertTrue(isinstance(e.frame, StompFrame))
        else:
            raise Exception(
                'Expected a StompProtocolError, but nothing was raised.')
Beispiel #7
0
 def run(self):
     client = Stomp(self.config)
     yield client.connect()
     headers = {
         # client-individual mode is necessary for concurrent processing
         # (requires ActiveMQ >= 5.2)
         StompSpec.ACK_HEADER:
         StompSpec.ACK_CLIENT_INDIVIDUAL,
         # the maximal number of messages the broker will let you work on at the same time
         'activemq.prefetchSize':
         '100',
     }
     client.subscribe(self.QUEUE,
                      headers,
                      listener=SubscriptionListener(
                          self.consume, errorDestination=self.ERROR_QUEUE))
Beispiel #8
0
    def test_disconnect_connection_lost_unexpectedly(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri='tcp://localhost:%d' % port, version='1.1')
        client = Stomp(config)

        yield client.connect()

        self._got_message = defer.Deferred()
        client.subscribe('/queue/bla',
                         headers={StompSpec.ID_HEADER: 4711},
                         listener=SubscriptionListener(
                             self._on_message,
                             ack=False))  # we're acking the frames ourselves
        yield self._got_message

        disconnected = client.disconnected
        client.send('/queue/fake',
                    b'shutdown')  # tell the broker to drop the connection
        try:
            yield disconnected
        except StompConnectionError:
            pass
        else:
            raise Exception(
                'Expected unexpected loss of connection, but disconnect went gracefully.'
            )

        self.wait.callback(None)
Beispiel #9
0
 def run(self, _):
     client = Stomp(self.config)
     yield client.connect()
     client.add(ReceiptListener(1.0))
     for j in range(10):
         yield client.send(self.QUEUE,
                           json.dumps({
                               'count': j
                           }).encode(),
                           receipt='message-%d' % j)
     client.disconnect(receipt='bye')
     yield client.disconnected  # graceful disconnect: waits until all receipts have arrived
Beispiel #10
0
    def test_multi_subscriptions(self):
        port = self.connections[0].getHost().port
        config = StompConfig(uri='tcp://localhost:%d' % port)
        client = Stomp(config)
        yield client.connect()

        listeners = []
        for j in range(2):
            listener = SubscriptionListener(self._on_message)
            yield client.subscribe('/queue/%d' % j,
                                   headers={'bla': j},
                                   listener=listener)
            listeners.append(listener)

        for (j, listener) in enumerate(listeners):
            self.assertEquals(listener._headers['bla'], j)

        yield client.disconnect()
        yield client.disconnected
Beispiel #11
0
    def test_replay_after_failover(self):
        ports = tuple(c.getHost().port for c in self.connections)
        config = StompConfig(
            uri=
            'failover:(tcp://localhost:%d)?startupMaxReconnectAttempts=0,initialReconnectDelay=0,maxReconnectAttempts=1'
            % ports)
        client = Stomp(config)
        queue = '/queue/bla'
        try:
            client.subscribe(
                queue, listener=SubscriptionListener(self._on_message)
            )  # client is not connected, so it won't accept subscriptions
        except StompConnectionError:
            pass
        else:
            raise Exception('Unexpected successful subscribe.')

        self.assertEquals(client.session._subscriptions,
                          {})  # check that no subscriptions have been accepted
        yield client.connect()

        self.shutdown = True  # the callback handler will kill the broker connection ...
        client.subscribe(queue,
                         listener=SubscriptionListener(self._on_message))
        try:
            yield client.disconnected  # the callback handler has killed the broker connection
        except StompConnectionError:
            pass
        else:
            raise Exception('Unexpected clean disconnect.')

        self.shutdown = False  # the callback handler will not kill the broker connection, but callback self._got_message
        self._got_message = defer.Deferred()

        yield client.connect()
        self.assertNotEquals(client.session._subscriptions,
                             [])  # the subscriptions have been replayed ...

        result = yield self._got_message
        self.assertEquals(result, None)  # ... and the message comes back

        yield client.disconnect()
        yield client.disconnected
        self.assertEquals(
            list(client.session.replay()),
            [])  # after a clean disconnect, the subscriptions are forgotten.
Beispiel #12
0
 def test_disconnect_timeout(self):
     port = self.connections[0].getHost().port
     config = StompConfig(uri='tcp://localhost:%d' % port, version='1.1')
     client = Stomp(config)
     yield client.connect()
     self._got_message = defer.Deferred()
     client.subscribe('/queue/bla',
                      headers={StompSpec.ID_HEADER: 4711},
                      listener=SubscriptionListener(
                          self._on_message,
                          ack=False))  # we're acking the frames ourselves
     yield self._got_message
     try:
         yield client.disconnect(timeout=0.02)
     except StompCancelledError:
         pass
     else:
         raise Exception(
             'Expected disconnect timeout, but disconnect went gracefully.')
     yield client.disconnected
     self.wait.callback(None)