Example #1
0
class MessageListener(Thread):
    """ 
    An instance of ChatTester logs in to the chat server and
    performs requests for rooms, speaks, etc...
    """

    def __init__(self, id, sender_id, thread_queue):
        Thread.__init__(self)
        self.user_id = id
        self.API = ChatAPI(
            135,
            "Sister Death Engineer",
            "http://superheroclubhouse.com/web/assets/images/users/e10a7729e97ddd7d1b6f406adf9745fa.png",
        )
        self.thread_queue = thread_queue
        self.sender_id = sender_id
        self.API.login()
        self.got_messages = {}

    def run(self):
        """Main method, log in and perform requests"""
        self.API.requestAndListen()
        if self.API.other_user_id != self.sender_id:
            self.speak("oops! Thats not who I want to talk to")
            self.API.signout()
            self.thread_queue.task_done()
            return

        self.speak("LISTENING....")
        while (len(self.got_messages)) < NUM_MESSAGES:
            messages = self.API.getMessageData()
            for m in messages:
                self.speak("GOT MESSAGE %d" % int(m["text"]))
                self.got_messages[int(m["text"])] = datetime.now()
            time.sleep(0.5)

        self.API.signout()
        self.thread_queue.task_done()

    def getRoom(self):
        room_ids = self.API.getRoomIds()
        if len(room_ids) > 0:
            return room_ids[0]
        return None

    def speak(self, txt):
        print self.name, txt

    def report(self, sent_messages):
        total = 0
        for i in range(0, NUM_MESSAGES):
            diff = self.got_messages[i] - sent_messages[i]
            diffSecs = float(diff.microseconds) / 1000000
            total += diffSecs
            print i, diffSecs
        print "%d messages, average = %f" % (NUM_MESSAGES, total / i)
Example #2
0
class ImpatientTester(Thread):
    """ 
    An instance of ChatTester logs in to the chat server and
    performs requests for rooms, speaks, etc...
    """
    
    def __init__ (self, id, thread_queue, num_iters):
        Thread.__init__(self)
        self.user_id = id
        self.API = ChatAPI(self.user_id)
        self.num_iters = num_iters
        self.thread_queue = thread_queue
        self.API.login()
        self.API.timeout = .5
        self.unique = 0
        
    def run(self):
        """Main method, log in and perform requests"""

        print self.name, " LIVES!"
        for i in range(0, self.num_iters):
            self.API.heartbeat()
            self.API.getListenResponse()
            time.sleep(.25)
            self.speak("iter = %d" % i)
        
        self.API.signout()
        myID = self.thread_queue.get(True, 1)
        self.thread_queue.task_done()
                                
    def report (self):
        self.speak("done")
        
    def speak(self, txt):
        print self.name, txt
Example #3
0
 def __init__ (self, id, thread_queue, num_iters):
     Thread.__init__(self)
     self.user_id = id
     self.API = ChatAPI(self.user_id)
     self.num_iters = num_iters
     self.thread_queue = thread_queue
     self.API.login()
     self.API.timeout = .5
     self.unique = 0
Example #4
0
 def __init__ (self, id, thread_queue, num_iters, num_users, messageTimer):
     Thread.__init__(self)
     self.user_id = id
     self.API = ChatAPI(self.user_id)
     self.num_iters = num_iters
     self.num_users = num_users
     self.thread_queue = thread_queue
     self.messageTimer = messageTimer
     self.API.login()
Example #5
0
 def __init__(self, id, sender_id, thread_queue):
     Thread.__init__(self)
     self.user_id = id
     self.API = ChatAPI(
         135,
         "Sister Death Engineer",
         "http://superheroclubhouse.com/web/assets/images/users/e10a7729e97ddd7d1b6f406adf9745fa.png",
     )
     self.thread_queue = thread_queue
     self.sender_id = sender_id
     self.API.login()
     self.got_messages = {}
Example #6
0
 def __init__(self, id, listener_id, thread_queue):
     Thread.__init__(self)
     self.user_id = id
     self.API = ChatAPI(
         134,
         "Brother Death Engineer",
         "http://superheroclubhouse.com/web/assets/images/users/9b3c74b6b8085acbb764b79bf5bda8db.png",
     )
     self.thread_queue = thread_queue
     self.listener_id = listener_id
     self.API.login()
     self.sent_messages = {}
     self.unique = 0
Example #7
0
class MessageSender(Thread):
    """ 
    An instance of ChatTester logs in to the chat server and
    performs requests for rooms, speaks, etc...
    """

    def __init__(self, id, listener_id, thread_queue):
        Thread.__init__(self)
        self.user_id = id
        self.API = ChatAPI(
            134,
            "Brother Death Engineer",
            "http://superheroclubhouse.com/web/assets/images/users/9b3c74b6b8085acbb764b79bf5bda8db.png",
        )
        self.thread_queue = thread_queue
        self.listener_id = listener_id
        self.API.login()
        self.sent_messages = {}
        self.unique = 0

    def run(self):
        """Main method, log in and perform requests"""
        self.API.requestAndListen()
        room_id = self.getRoom()
        if self.API.other_user_id != self.listener_id:
            self.speak("oops! Thats not who I want to talk to")
            self.API.signout()
            self.thread_queue.task_done()
            return

        time.sleep(2)
        self.speak("START SENDING!")
        for i in range(0, NUM_MESSAGES):
            self.sent_messages[i] = datetime.now()
            self.speak("SENDING MESSAGE %d" % i)
            self.API.messageRoom(i, room_id)
            time.sleep(0.5)

        self.API.signout()
        self.thread_queue.task_done()

    def getRoom(self):
        room_ids = self.API.getRoomIds()
        if len(room_ids) > 0:
            return room_ids[0]
        return None

    def report(self):
        self.speak("done")

    def speak(self, txt):
        print self.name, txt
Example #8
0
class ChatTester(Thread):
    """ 
    An instance of ChatTester logs in to the chat server and
    performs requests for rooms, speaks, etc...
    """
    
    def __init__ (self, id, thread_queue, num_iters, num_users, messageTimer):
        Thread.__init__(self)
        self.user_id = id
        self.API = ChatAPI(self.user_id)
        self.num_iters = num_iters
        self.num_users = num_users
        self.thread_queue = thread_queue
        self.messageTimer = messageTimer
        self.API.login()
        
    def run(self):
        """Main method, log in and perform requests"""
        global messageTimer
        print self.name, " LIVES!"
        self.API.requestAndListen()
        for i in range(0, self.num_iters):
            self.API.heartbeat()
            room_id = self.randomRoom()
            if room_id:
                messageID = self.messageTimer.nextID()
                self.messageTimer.sentMessage(messageID)
                self.API.messageRoom(messageID, room_id)
            
            self.API.heartbeat()
            self.processListen()
            
        time.sleep(1)
        self.API.heartbeat()
        self.processListen()        
        
        self.API.signout()
        
        myID = self.thread_queue.get(True, 1)
        self.thread_queue.task_done()
    
    def processListen (self):
        messages = self.API.getMessageData()
        for m in messages:
            messageID = m["text"]
            if messageID.isdigit():
                self.messageTimer.gotMessage(int(messageID))
                                
    def randomRoom (self):
        room_ids = self.API.getRoomIds()
        if len(room_ids) > 0:
            return room_ids[random.randint(0, len(room_ids) - 1)]
        return None
           
    def report (self):
        self.speak("done")
        self.API.printStats()
        
    def speak(self, txt):
        print self.name, txt