コード例 #1
0
class TopicManagerTest(unittest.TestCase):
    """ Tests for the L{TopicManager} class. """
    
    def setUp(self):
        self.tm = TopicManager()
        self.conn = MockConnection()
    
    def test_subscribe(self):
        """ Test subscribing a connection to the topic. """
        dest = '/topic/dest'
        
        self.tm.subscribe(self.conn, dest)
        f = StompFrame('MESSAGE', headers={'destination': dest}, body='Empty')
        self.tm.send(f)
        
        print self.conn.frames
        assert len(self.conn.frames) == 1
        assert self.conn.frames[0] == f
    
    def test_unsubscribe(self):
        """ Test unsubscribing a connection from the queue. """
        dest = '/topic/dest'
        
        self.tm.subscribe(self.conn, dest)
        f = StompFrame('MESSAGE', headers={'destination': dest}, body='Empty')
        self.tm.send(f)
        
        print self.conn.frames
        assert len(self.conn.frames) == 1
        assert self.conn.frames[0] == f
        
        self.tm.unsubscribe(self.conn, dest)
        f = StompFrame('MESSAGE', headers={'destination': dest}, body='Empty')
        self.tm.send(f)
        
        assert len(self.conn.frames) == 1
        
    def send_simple(self):
        """ Test a basic send command. """
        dest = '/topic/dest'
        
        f = StompFrame('SEND', headers={'destination': dest}, body='Empty')
        self.tm.send(f)
        
        # Assert some side-effects
        assert 'message-id' in f.headers
        assert f.cmd == 'MESSAGE'
コード例 #2
0
class TopicManagerTest(unittest.TestCase):
    """ Tests for the L{TopicManager} class. """
    def setUp(self):
        self.tm = TopicManager()
        self.conn = MockConnection()

    def test_subscribe(self):
        """ Test subscribing a connection to the topic. """
        dest = '/topic/dest'

        self.tm.subscribe(self.conn, dest)
        f = StompFrame('MESSAGE', headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        print self.conn.frames
        assert len(self.conn.frames) == 1
        assert self.conn.frames[0] == f

    def test_unsubscribe(self):
        """ Test unsubscribing a connection from the queue. """
        dest = '/topic/dest'

        self.tm.subscribe(self.conn, dest)
        f = StompFrame('MESSAGE', headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        print self.conn.frames
        assert len(self.conn.frames) == 1
        assert self.conn.frames[0] == f

        self.tm.unsubscribe(self.conn, dest)
        f = StompFrame('MESSAGE', headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        assert len(self.conn.frames) == 1

    def send_simple(self):
        """ Test a basic send command. """
        dest = '/topic/dest'

        f = StompFrame('SEND', headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        # Assert some side-effects
        assert 'message-id' in f.headers
        assert f.cmd == 'MESSAGE'
コード例 #3
0
ファイル: test_topic.py プロジェクト: hozn/coilmq
class TopicManagerTest(unittest.TestCase):
    """ Tests for the L{TopicManager} class. """

    def setUp(self):
        self.tm = TopicManager()
        self.conn = MockConnection()

    def test_subscribe(self):
        """ Test subscribing a connection to the topic. """
        dest = '/topic/dest'

        self.tm.subscribe(self.conn, dest)
        f = Frame(frames.MESSAGE, headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        self.assertEqual(len(self.conn.frames), 1)
        self.assertEqual(self.conn.frames[0], f)

    def test_unsubscribe(self):
        """ Test unsubscribing a connection from the queue. """
        dest = '/topic/dest'

        self.tm.subscribe(self.conn, dest)
        f = Frame(frames.MESSAGE, headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        self.assertEqual(len(self.conn.frames), 1)
        self.assertEqual(self.conn.frames[0], f)

        self.tm.unsubscribe(self.conn, dest)
        f = Frame(frames.MESSAGE, headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        self.assertEqual(len(self.conn.frames), 1)

    def test_send_simple(self):
        """ Test a basic send command. """
        dest = '/topic/dest'

        f = Frame(frames.SEND, headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        # Assert some side-effects
        self.assertIn('message-id', f.headers)
        self.assertEqual(f.cmd, 'message')

    def test_send_subscriber_timeout(self):
        """ Test a send command when one subscriber errs out. """

        class TimeoutConnection(object):
            reliable_subscriber = False

            def send_frame(self, frame):
                raise socket.timeout("timed out")

            def reset(self):
                pass

        dest = '/topic/dest'

        bad_client = TimeoutConnection()

        # Subscribe both a good client and a bad client.
        self.tm.subscribe(bad_client, dest)
        self.tm.subscribe(self.conn, dest)

        f = Frame('message', headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        # Make sure out good client got the message.
        self.assertEqual(len(self.conn.frames), 1)
        self.assertEqual(self.conn.frames[0], f)

        # Make sure our bad client got disconnected
        # (This might be a bit too intimate.)
        self.assertNotIn(bad_client, self.tm._topics[dest])
コード例 #4
0
class TopicManagerTest(unittest.TestCase):
    """ Tests for the L{TopicManager} class. """
    def setUp(self):
        self.tm = TopicManager()
        self.conn = MockConnection()

    def test_subscribe(self):
        """ Test subscribing a connection to the topic. """
        dest = '/topic/dest'

        self.tm.subscribe(self.conn, dest)
        f = Frame('MESSAGE', headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        print self.conn.frames
        assert len(self.conn.frames) == 1
        assert self.conn.frames[0] == f

    def test_unsubscribe(self):
        """ Test unsubscribing a connection from the queue. """
        dest = '/topic/dest'

        self.tm.subscribe(self.conn, dest)
        f = Frame('MESSAGE', headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        print self.conn.frames
        assert len(self.conn.frames) == 1
        assert self.conn.frames[0] == f

        self.tm.unsubscribe(self.conn, dest)
        f = Frame('MESSAGE', headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        assert len(self.conn.frames) == 1

    def send_simple(self):
        """ Test a basic send command. """
        dest = '/topic/dest'

        f = Frame('SEND', headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        # Assert some side-effects
        assert 'message-id' in f.headers
        assert f.command == 'MESSAGE'

    def send_subscriber_timeout(self):
        """ Test a send command when one subscriber errs out. """
        class TimeoutConnection(object):
            reliable_subscriber = False

            def send_frame(self, frame):
                raise socket.timeout("timed out")

            def reset(self):
                pass

        dest = '/topic/dest'

        bad_client = TimeoutConnection()

        # Subscribe both a good client and a bad client.
        self.tm.subscribe(bad_client, dest)
        self.tm.subscribe(self.conn, dest)

        f = Frame('MESSAGE', headers={'destination': dest}, body='Empty')
        self.tm.send(f)

        # Make sure out good client got the message.
        assert len(self.conn.frames) == 1
        assert self.conn.frames[0] == f

        # Make sure our bad client got disconnected
        # (This might be a bit too intimate.)
        assert bad_client not in self.tm._topics[dest]