示例#1
0
    def test_subscriber_notification(self):
        messages = []
        Timeout = True
        onReceive = lambda m: self._onReceive(messages, m)
        onTimeout = lambda: self._onTimeout(messages)

        c = Channel(10)

        self.assertEqual(0, len(c.subscribers))
        c.subscribe(onReceive, None, timeoutSec = 1)
        self.assertEqual(1, len(c.subscribers))

        c.publish("data", False)
        self.assertEqual("[(0, 'data')]", str(messages))
        self.assertEqual(0, len(c.subscribers))
示例#2
0
    def test_purge_message(self):
        c = Channel(1)

        self.assertEqual(0, len(c.messageQueue))
        c.publish("data")
        self.assertEqual(1, len(c.messageQueue))
        c.purgeMessageQueue()
        self.assertEqual(1, len(c.messageQueue))

        time.sleep(1)
        c.purgeMessageQueue()
        self.assertEqual(0, len(c.messageQueue))
示例#3
0
    def test_purge_subscribers(self):
        c = Channel(1)
        messages = []
        onTimeout = lambda: self._onTimeout(messages)

        self.assertEqual(0, len(c.subscribers))
        c.subscribe(None, onTimeout, timeoutSec = 1)
        self.assertEqual(1, len(c.subscribers))
        c.purgeSubscribers()
        self.assertEqual(1, len(c.subscribers))
        self.assertEqual(0, len(messages))

        time.sleep(1)
        print c.subscribers
        c.purgeSubscribers()
        self.assertEqual(0, len(c.subscribers))
        self.assertEqual("timeout", messages[0])
示例#4
0
 def __init__(self):
     Channel.__init__(self, fan_in=True, fan_out=False)
示例#5
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.experiments = {}
     self.current = {}
示例#6
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.devices = None
     self.nodes = None
     self.view = {}
示例#7
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.records = []
示例#8
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.channel_reset([])
示例#9
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.queue_root = { 'children': [] }
     self.queue_status = 'IDLE'
示例#10
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.experiments = {}
     self.current = {}
示例#11
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.devices = None
     self.nodes = None
     self.view = {}
示例#12
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.records = []
示例#13
0
    def test_publish(self):
        messages = []
        onReceive = lambda m: self._onReceive(messages, m)

        c = Channel(10)
        self.assertEqual(0, len(c.messageQueue))
        c.subscribe(onReceive, None)
        self.assertEqual(0, len(messages))

        c.publish("data1")
        c.publish("data2")
        self.assertEqual(1, len(c.messageQueue))
        c.subscribe(onReceive, None)
        self.assertEqual(2, len(messages))

        time.sleep(1)
        c.publish("data3")
        self.assertEqual(2, len(c.messageQueue))
        c.subscribe(onReceive, None)
        self.assertEqual(3, len(messages))
        self.assertEqual("[(0, 'data1'), (1, 'data2'), (2, 'data3')]", str(messages))
示例#14
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.queue_root = {'children': []}
     self.queue_status = 'IDLE'
示例#15
0
 def __init__(self):
     Channel.__init__(self, fan_in=True, fan_out=False)
示例#16
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.channel_reset([])
示例#17
0
    def test_subscribe_with_id(self):
        messages = []
        onReceive = lambda m: self._onReceive(messages, m)

        c = Channel(10)
        c.publish("data1")
        c.publish("data2")
        c.publish("data3")

        c.subscribe(onReceive, None)
        self.assertEqual(3, len(messages))

        c.subscribe(onReceive, None, minId = 1)
        self.assertEqual(2, len(messages))

        c.subscribe(onReceive, None, minId = 2)
        self.assertEqual(1, len(messages))

        c.subscribe(onReceive, None, minId = 3)
        self.assertEqual(0, len(messages))