Пример #1
0
    def setUp(self):
        self.msg_server = OnDemandPublisher()
        self.msg_server.start()
        self.deliveryDest = functools.partial(self._deliveryDest)
        self.bus = BusAdapter()
        self.delivery_event = threading.Event()

        # Content and topic for outgoing msgs sent
        # via the OnDemandPublisher instance:

        self.reference_msg_content = 'rTmzntNSQLmXokesBpLmAbPYeysftXnuntfdPKrxMVNUuqVFHFzfcrrSaRssdHuMRhPYjXKYrJjwKcyeYycEzQSkJubTabeSFLRS'
        self.reference_named_topic = 'MyTopic'
        self.reference_pattern_topic = r'MyTopic*'
        self.reference_pattern_obj = re.compile(self.reference_pattern_topic)
        self.reference_pattern_matching_topic = 'MyTopicHurray'
        self.reference_context = 'myContext'

        # Msg with a non-pattern, i.e. fixed-name topic:
        self.reference_bus_msg = BusMessage(
            topicName=self.reference_named_topic,
            content=self.reference_msg_content,
            context=self.reference_context)

        # Msg with a topic that will match self.reference_pattern_topic:
        self.reference_bus_wildcard_msg = BusMessage(
            topicName=self.reference_pattern_matching_topic,
            content=self.reference_msg_content,
            context=self.reference_context)
Пример #2
0
    def __init__(self):
        '''
        Constructor
        '''
        self.host = 'localhost'
        self.port = 6379

        self.letterChoice = string.letters
        self.bus = BusAdapter()
Пример #3
0
    def __init__(self, busMsg=None):
        super(MessageOutStreamer, self).__init__()

        self.daemon = True
        self.streamBus = BusAdapter()
        self.busMsg = BusMessage() if busMsg is None else busMsg

        self.done = False
        self._paused = False
        self._stream_interval = STREAM_INTERVAL
Пример #4
0
 def setUpClass(cls):
     super(LtiBridgeTester, cls).setUpClass()
     cls.bus = BusAdapter()
     if not is_running('lti_schoolbus_bridge'):
         cls.bridge_was_running = False
         # We assume that the lti bridge executable is 
         # in the parent directory:
         currDir = os.path.dirname(__file__)
         path = os.path.join(currDir, '../lti_schoolbus_bridge.py')
         subprocess.Popen(path, shell=True)
         print('Started lti_schoolbus_bridge.py')
     else:
         cls.bridge_was_running = True
    def __init__(self):
        '''
        Constructor
        '''
        self.bus = BusAdapter()
        self.bus.subscribeToTopic(SchoolbusWikipedia.TOPIC,
                                  functools.partial(self.get_info_handler))

        # Hang till keyboard_interrupt:
        try:
            self.exit_event = threading.Event().wait()
        except KeyboardInterrupt:
            print('Exiting wikipedia module.')
Пример #6
0
    def __init__(self, topic_to_follow):
        '''
        Constructor
        '''
        target_file = '/tmp/msgFile.txt'
        self.bus = BusAdapter()

        # Make sure to start with a new file
        try:
            os.remove(target_file)
        except:
            pass

        self.fd = open(target_file, 'a')
        self.bus.subscribeToTopic(topic_to_follow,
                                  functools.partial(self.handle_bus_msg))
Пример #7
0
    def __init__(self, correctValue=None, beSynchronous=False):
        threading.Thread.__init__(self, name='ReceptionTesterThread')
        self.correctValue = correctValue
        self.beSynchronous = beSynchronous

        self.testBus = BusAdapter()

        # Subscribe, and ensure that context is delivered
        # with each message:
        self.testBus.subscribeToTopic('myTopic',
                                      deliveryCallback=functools.partial(
                                          self.messageReceiver),
                                      context={
                                          'foo': 10,
                                          'bar': 'my string'
                                      })
        self.interruptEvent = threading.Event()
        self.done = False
Пример #8
0
    def __init__(self,
                 msgMd5=None,
                 beSynchronous=False,
                 topic_to_wait_on='test'):
        threading.Thread.__init__(self, name='PerfTestReceptor')
        self.setDaemon(True)

        self.beSynchronous = beSynchronous
        self.topic_to_wait_on = topic_to_wait_on

        self.testBus = BusAdapter()

        # Subscribe, and ensure that context is delivered
        # with each message:
        self.testBus.subscribeToTopic(topic_to_wait_on,
                                      functools.partial(self.messageReceiver),
                                      context=msgMd5)
        self.interruptEvent = threading.Event()
        self.done = False
Пример #9
0
    def __init__(self,
                 msgMd5=None,
                 beSynchronous=False,
                 topic_to_wait_on=RedisPerformanceTester.PUBLISH_TOPIC):
        threading.Thread.__init__(self, name='PerfTestReceptor')
        self.daemon = True

        self.rxed_count = 0
        self.beSynchronous = beSynchronous

        self.testBus = BusAdapter()

        # Subscribe, and ensure that context is delivered
        # with each message:
        self.testBus.subscribeToTopic(topic_to_wait_on,
                                      functools.partial(self.messageReceiver),
                                      context=msgMd5)
        self.interruptEvent = threading.Event()
        self.done = False
Пример #10
0
 def setUpClass(cls):
     cls.bus = BusAdapter()
Пример #11
0
    (certFile, keyFile) = JsBusBridge.getCertAndKey()
    sslArgsDict = {'certfile': certFile, 'keyfile': keyFile}

    # For SSL:
    if SSL_USED:
        protocol_spec = 'wss'
        http_server = tornado.httpserver.HTTPServer(application,
                                                    ssl_options=sslArgsDict)
        application.listen(JS_BRIDGE_WEBSOCKET_PORT, ssl_options=sslArgsDict)
    else:
        protocol_spec = 'ws'
        http_server = tornado.httpserver.HTTPServer(application)
        application.listen(JS_BRIDGE_WEBSOCKET_PORT)

    JsBusBridge.bus = BusAdapter(host=bus_server)

    start_msg = 'Starting JavaScript/SchoolBus bridge server on %s://%s:%d/jsbusbridge/' % \
        (protocol_spec, socket.gethostname(), JS_BRIDGE_WEBSOCKET_PORT)

    print(start_msg)

    try:
        ioloop = tornado.ioloop.IOLoop.instance()
        ioloop.start()
    except KeyboardInterrupt:
        shutdown()
    except Exception as e:
        print('Bombed out of tornado IO loop: %s' % ` e `)

    print('School bus JavaScript bridge has shut down.')
Пример #12
0
    def __init__(self,
                 serveEchos=True,
                 listenOn=None,
                 streamMsgs=False,
                 checkSyntax=True,
                 oneShotMsg=None):
        '''
        Initialize the test harness server. 
        
        :param serveEchos: if True receives messages on ECHO_TOPIC, and returns  
            message with the same content, but different timestamp as a synchronous call. 
        :type serveEchos: bool
        :param listenOn: if this parameter provides an array of topic(s), messages on these
            topics are received and counted, then placed on self.bus_msg_queue. Intermittent reception counts
            and reception rates are printed to the console, and place on self.bus_stats_queue.
        :type listenOn: {None | [string]}
        :param streamMsgs: if True, a continuous stream of messages are sent to
            STREAM_TOPIC. The timestamp is changed each time.
        :type streamMsgs: bool
        :param checkSyntax: if true, listens on SYNTAX_TOPIC, checks incoming messages
            for conformance to SchoolBus message format, and synchronously returns a result.
        :type checkSyntax: bool
        :param oneShotMsg: if non-none this parameter is expected to be a two-tuple
            containing a topic and a content. Either may be None. If topic is None,
            the message is sent to STREAM_TOPIC. If content is None, content will be
            a random string of length STANDARD_MSG_LENGTH.
        :type oneShotMsg: { None | ({string | None}, {string | None})}
        '''
        threading.Thread.__init__(self)

        self.loglevel = OnDemandPublisher.LOG_LEVEL_DEBUG
        #self.loglevel = OnDemandPublisher.LOG_LEVEL_INFO
        #self.loglevel = OnDemandPublisher.LOG_LEVEL_NONE

        #***********
        #         print ('serveEchos %s' % serveEchos)
        #         print ('listenOn %s' % listenOn)
        #         print ('streamMsgs %s' % streamMsgs)
        #         print('checkSyntax %s' % checkSyntax)
        #         print('oneShotMsg %s' % str(oneShotMsg))
        #         sys.exit()
        #***********

        self._serveEchos = serveEchos

        self.daemon = True
        self.testBus = BusAdapter()
        self.done = False
        # No topics yet that we are to listen to, but drop msgs for:
        self.topics_to_rx = []

        self.echo_topic = ECHO_TOPIC
        self.syntax_check_topic = SYNTAX_TOPIC
        self.standard_msg_len = STANDARD_MSG_LENGTH
        self._stream_interval = STREAM_INTERVAL

        self._stream_topic = STREAM_TOPIC
        self.standard_bus_msg = self.createMessage(STREAM_TOPIC,
                                                   STANDARD_MSG_LENGTH,
                                                   content=None)

        self.one_shot_topic = STREAM_TOPIC
        self.one_shot_content = self.standard_bus_msg

        # Queue into which incoming messages are fed
        # for consumers to communicated to clients, such
        # as a Web UI:
        self.bus_msg_queue = Queue.Queue(MAX_SAVED_MSGS)

        # Queue to which aggregate stats will be written:
        self.bus_stats_queue = Queue.Queue(MAX_SAVED_MSGS)

        # Create a 'standard' message to send out
        # when asked to via SIGUSR1 or the Web:

        if oneShotMsg is not None:
            # The oneShotMsg arg may have one of the following values:
            #   - None if oneshot was not requested.
            #   - An empty array if -o (or --oneshot)
            #        was listed in the command line,
            #        but neither topic nor message content
            #        were specified.
            #   - A one-element array if the topic was
            #        specified
            #   - A two-element array if both topic and
            #        content were specified.

            (one_shot_topic, self.one_shot_content) = oneShotMsg
            if one_shot_topic is not None:
                self.one_shot_topic = one_shot_topic

            # Create a message that one can have sent on demand
            # by sending a SIGUSR1 to the server, or using
            # the Web UI:

            self.standard_oneshot_msg = self.createMessage(
                self.one_shot_topic, content=self.one_shot_content)
            # Send the standard msg:
            self.sendMessage(self.standard_oneshot_msg)
        else:
            # Create a standard message with default topic/content:
            self.standard_oneshot_msg = self.createMessage()

        # Start time of a 10,000 messages batch:
        self.batch_start_time = time.time()

        # Subscribe, and ensure that context is delivered
        # with each message:

        if serveEchos:
            self.serve_echo = True

        if listenOn is not None:
            # Array of topics to listen to
            # If we are to listen to some (additional) topic(s),
            # on which no action is taken, subscribe to it/them now:
            self['topicsToRx'] = listenOn

        if checkSyntax:
            self.check_syntax = True

        self.interruptEvent = threading.Event()

        # Number of messages received and echoed:
        self.numEchoed = 0
        # Alternative to above when not echoing: Number of msgs just received:
        self.numReceived = 0
        self.mostRecentRxTime = None
        self.printedResetting = False

        # Not asked to send a message yet.
        self.sendMsg = False

        if streamMsgs is not None:
            # The streamMsgs arg may have one of the following values:
            #   - None if streaming messages was not requested.
            #   - An empty array if -s (or --streamMsgs)
            #        was listed in the command line,
            #        but neither topic nor message content
            #        were specified.
            #   - A one-element array if the topic was
            #        specified
            #   - A two-element array if both topic and
            #        content were specified.

            self.msg_streamer = MessageOutStreamer(self.standard_bus_msg)

            # The caller passed in a tuple with
            # topic and content for streaming. If they
            # are non-None, update the streamer:

            (stream_topic, stream_content) = streamMsgs
            if stream_topic is not None:
                self.stream_topic = stream_topic
            if stream_content is not None:
                self.stream_content = stream_content

            # Start streaming:

            self.msg_streamer.pause(True)
            self.msg_streamer.start()

        else:
            # Create a standard message with default topic/content:
            self.standard_stream_msg = self.createMessage()
            self.msg_streamer = None