def _topicmanager(self):
     """
 Returns the configured L{TopicManager} instance to use.
 Can be overridden by subclasses that wish to change out any topic mgr parameters.
 @rtype: L{TopicManager}
 """
     return TopicManager()
Beispiel #2
0
def server_from_config(config=None, server_class=None, additional_kwargs=None):
    """
    Gets a configured L{coilmq.server.StompServer} from specified config.

    If `config` is None, global L{coilmq.config.config} var will be used instead.

    The `server_class` and `additional_kwargs` are primarily hooks for using this method
    from a testing environment.

    @param config: A C{ConfigParser.ConfigParser} instance with loaded config values.
    @type config: C{ConfigParser.ConfigParser}

    @param server_class: Which class to use for the server.  (This doesn't come from config currently.)
    @type server_class: C{class}

    @param additional_kwargs: Any additional args that should be passed to class.
    @type additional_kwargs: C{list}

    @return: The configured StompServer.
    @rtype: L{coilmq.server.StompServer}
    """
    global global_config
    if not config:
        config = global_config

    queue_store_factory = resolve_name(config.get('coilmq', 'qstore.factory'))
    subscriber_scheduler_factory = resolve_name(
        config.get('coilmq', 'scheduler.subscriber_priority_factory'))
    queue_scheduler_factory = resolve_name(
        config.get('coilmq', 'scheduler.queue_priority_factory'))

    if config.has_option('coilmq', 'auth.factory'):
        authenticator_factory = resolve_name(
            config.get('coilmq', 'auth.factory'))
        authenticator = authenticator_factory()
    else:
        authenticator = None

    server = ThreadedStompServer(
        (config.get('coilmq',
                    'listen_addr'), config.getint('coilmq', 'listen_port')),
        queue_manager=QueueManager(
            store=queue_store_factory(),
            subscriber_scheduler=subscriber_scheduler_factory(),
            queue_scheduler=queue_scheduler_factory()),
        topic_manager=TopicManager(),
        authenticator=authenticator,
        protocol=STOMP11)
    logger.info("Created server:%r" % server)
    return server
Beispiel #3
0
 def setUp(self):
     self.tm = TopicManager()
     self.conn = MockConnection()
Beispiel #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 = 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'
Beispiel #5
0
 def setUp(self):
     self.tm = TopicManager()
     self.conn = MockConnection()
Beispiel #6
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(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])
Beispiel #7
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]
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'