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))
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))
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])
def __init__(self): Channel.__init__(self, fan_in=True, fan_out=False)
def __init__(self): Channel.__init__(self, fan_in=False, fan_out=True) self.experiments = {} self.current = {}
def __init__(self): Channel.__init__(self, fan_in=False, fan_out=True) self.devices = None self.nodes = None self.view = {}
def __init__(self): Channel.__init__(self, fan_in=False, fan_out=True) self.records = []
def __init__(self): Channel.__init__(self, fan_in=False, fan_out=True) self.channel_reset([])
def __init__(self): Channel.__init__(self, fan_in=False, fan_out=True) self.queue_root = { 'children': [] } self.queue_status = 'IDLE'
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))
def __init__(self): Channel.__init__(self, fan_in=False, fan_out=True) self.queue_root = {'children': []} self.queue_status = 'IDLE'
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))