Exemple #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))
Exemple #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))
Exemple #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])
Exemple #4
0
 def __init__(self):
     Channel.__init__(self, fan_in=True, fan_out=False)
Exemple #5
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.experiments = {}
     self.current = {}
Exemple #6
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.devices = None
     self.nodes = None
     self.view = {}
Exemple #7
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.records = []
Exemple #8
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.channel_reset([])
Exemple #9
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.queue_root = { 'children': [] }
     self.queue_status = 'IDLE'
Exemple #10
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.experiments = {}
     self.current = {}
Exemple #11
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.devices = None
     self.nodes = None
     self.view = {}
Exemple #12
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.records = []
Exemple #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))
Exemple #14
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.queue_root = {'children': []}
     self.queue_status = 'IDLE'
Exemple #15
0
 def __init__(self):
     Channel.__init__(self, fan_in=True, fan_out=False)
Exemple #16
0
 def __init__(self):
     Channel.__init__(self, fan_in=False, fan_out=True)
     self.channel_reset([])
Exemple #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))