def test_2(self):
        '''With evaluation'''

        q = WishboneQueue(max_size=1000001)

        for _ in xrange(1000000):
            q.put(1)
    def test_2(self):
        '''With evaluation'''

        q = WishboneQueue(max_size=1000001)

        for _ in xrange(1000000):
            q.put(1)
示例#3
0
 def test_putUnlock(self):
     queue = WishboneQueue()
     queue.putLock()
     try:
         queue.put("test")
     except QueueLocked:
         pass
     else:
         raise AssertionError ("Queue putUnlock() does not seem to have the desired effect.")
示例#4
0
 def test_init_max_size(self):
     queue = WishboneQueue(max_size=1)
     queue.put("test")
     try:
         queue.put("test")
     except QueueFull:
         pass
     else:
         raise AssertionError("Queue max_size does not appear to be working.")
示例#5
0
    def test_putLock(self):
        queue = WishboneQueue()
        queue.putLock()

        try:
            queue.put("test")
        except QueueLocked:
            pass
        else:
            raise AssertionError("Queue putLock() not having desired effect.")
示例#6
0
 def test_getUnlock(self):
     queue = WishboneQueue()
     queue.put("test")
     queue.getLock()
     try:
         queue.get()
     except QueueLocked:
         queue.getUnlock()
         assert queue.get() == "test"
     else:
         raise AssertionError ("Queue getLock() does not seem to have the desired effect.")
示例#7
0
    def test_waitUntilFreePlace(self):
        from gevent import spawn, sleep
        def go(queue):
            queue.waitUntilFreePlace()

        queue = WishboneQueue(max_size=1)
        queue.put("test")

        instance=spawn(go, queue)
        sleep()
        assert not instance.ready()

        queue.get()
        sleep()
        assert instance.ready()
示例#8
0
    def test_waitUntilData(self):
        from gevent import spawn, sleep
        def go(queue):
            queue.waitUntilData()

        queue = WishboneQueue()
        queue.put("blah")
        instance=spawn(go, queue)
        sleep()
        assert instance.ready()

        queue = WishboneQueue()
        instance=spawn(go, queue)
        sleep()
        assert not instance.ready()
示例#9
0
    def test_waitUntilPutAllowed(self):
        from gevent import spawn, sleep
        def go(queue):
            queue.waitUntilPutAllowed()
            queue.put("test")

        queue = WishboneQueue()
        queue.putLock()

        instance=spawn(go, queue)
        sleep()
        assert not instance.ready()

        queue.putUnlock()
        sleep()
        assert instance.ready()
示例#10
0
    def test_lock(self):
        queue = WishboneQueue()
        queue.put("test")
        queue.lock()
        try:
            queue.put("test")
        except QueueLocked:
            pass
        else:
            raise AssertionError("Queue lock() not having desired effect.")

        try:
            queue.get()
        except QueueLocked:
            pass
        else:
            raise AssertionError("Queue lock not having desired effect.")

        assert queue.isLocked() == (True, True)
示例#11
0
    def test_stats(self):
        queue = WishboneQueue()

        for _ in xrange(10):
            queue.put("test")

        for _ in xrange(9):
            queue.get()

        stats = queue.stats()

        assert isinstance(stats, dict)
        assert stats["in_total"] == 10
        assert stats["out_total"] == 9
        assert stats["size"] == 1
示例#12
0
 def test_clear(self):
     queue = WishboneQueue()
     queue.put("test")
     assert queue.size() == 1
示例#13
0
    def test_1(self):
        '''No evaluation'''
        q = WishboneQueue()

        for _ in xrange(1000000):
            q.put(1)
示例#14
0
 def test_rescue(self):
     queue = WishboneQueue()
     queue.lock()
     queue.rescue("test")
     queue.unlock()
     assert queue.get() == "test"
    def test_1(self):
        '''No evaluation'''
        q = WishboneQueue()

        for _ in xrange(1000000):
            q.put(1)
示例#16
0
 def test_isLocked(self):
     queue = WishboneQueue()
     queue.getLock()
     assert queue.isLocked() == (True, False)
示例#17
0
 def test_size(self):
     queue = WishboneQueue()
     queue.lock()
     queue.rescue("test")
     assert queue.size() == 1
示例#18
0
 def test_get(self):
     queue = WishboneQueue()
     queue.put("test")
     assert queue.get() == "test"
示例#19
0
 def test_empty(self):
     queue = WishboneQueue()
     queue.put("test")
     queue.clear()
     assert queue.size() == 0
示例#20
0
class QLogging():

    '''
    Generates Wishbone formatted log messages following the Syslog priority
    definition.

    Generated logs are stored in a local queue <self.logs>.  It is up to an
    external process the consume this queue.

    '''

    def __init__(self, name):
        self.logs=WishboneQueue()
        self.name=name
        self.pid=getpid()

    def __log(self, level, message):
        self.logs.put({"header":{},"data":(level, time(), self.pid, self.name, message)})

    def emergency(self, message):
        """Generates a log message with priority emergency(0).
        """
        self.__log(0, message)
    emerg=emergency

    def alert(self, message):
        """Generates a log message with priority alert(1).
        """
        self.__log(1, message)

    def critical(self, message):
        """Generates a log message with priority critical(2).
        """
        self.__log(2, message)
    crit=critical

    def error(self, message):
        """Generates a log message with priority error(3).
        """
        self.__log(3, message)
    err=error

    def warning(self, message):
        """Generates a log message with priority warning(4).
        """
        self.__log(4, message)
    warn=warning

    def notice(self, message):
        """Generates a log message with priority notice(5).
        """
        self.__log(5, message)

    def informational(self, message):
        """Generates a log message with priority informational(6).
        """
        self.__log(6, message)
    info=informational

    def debug(self, message):
        """Generates a log message with priority debug(7).
        """
        self.__log(7, message)
示例#21
0
 def __init__(self, name):
     self.logs=WishboneQueue()
     self.name=name
     self.pid=getpid()
示例#22
0
    def test_dump(self):
        queue = WishboneQueue()
        queue.put("test")
        queue.put("test")

        assert len([x for x in queue.dump()]) == 2