def test_configure_sequence(self): p = PeriodicLog() p.configure({'name': 'log', 'parent': None, 'period': 1}) h = CompositeNode() h.configure({'name': 'columns', 'parent': p}) c = PeriodicAverageColumn() c.configure({ 'position': 0, 'name': '2', 'parent': h, 'function': self._next }) p.start() try: l = [] v = [] for i in range(0, 100): l.append(c._evaluate()) v.append(i - 0.5) if l.pop(0) != None: raise 'First delta not None.' v.pop(0) for i in l: j = v.pop(0) if i != j: raise 'Incorrect average of %s should be %s.' % (i, j) finally: p.stop() return
def test_configure_1(self): p = PeriodicLog() p.configure({'name':'log','parent':None, 'period':1}) h = CompositeNode() h.configure({'name':'columnholder','parent':p}) c = PeriodicColumn() c.configure({'position':0, 'name':'0', 'parent':h, 'function':self._random, 'args':()}) c.start() try: c.function() finally: c.stop() return
def test_configure_sequence_get(self): p = PeriodicLog() p.configure({'name': 'log', 'parent': None, 'period': 1}) h = CompositeNode() h.configure({'name': 'columns', 'parent': p}) c = PeriodicDeltaColumn() c.configure({ 'position': 0, 'name': '2', 'parent': h, 'function': self._next }) p.start() try: l = [] if c.get() != None: raise 'Get didn\'t return None on first get' if c.get() != None: raise 'Get didn\'t return None on second get' self.seq.value = 0 c.function() self._next() self._next() self._next() if c.get() != self.seq.value - 1: raise 'Got incorrect value after incrementing' finally: p.stop() return
def test_configure_sequence(self): p = PeriodicLog() p.configure({'name': 'log', 'parent': None, 'period': 1}) h = CompositeNode() h.configure({'name': 'columns', 'parent': p}) c = PeriodicDeltaColumn() c.configure({ 'position': 0, 'name': '2', 'parent': h, 'function': self._next }) p.start() try: l = [] for i in range(0, 100): l.append(c.function()) if l.pop(0) != None: raise 'First delta not None.' for i in l: if i != 1: raise 'Incoreect delta of %s should be %s.' % (i, 1) finally: p.stop() return
def test_configure_2(self): p = PeriodicLog() p.configure({'name':'log','parent':None, 'period':1}) h = CompositeNode() h.configure({'name':'columnholder','parent':p}) c = PeriodicColumn() c.configure({'position':1, 'name':'1', 'parent':h, 'context':'import random', 'function':'random.uniform', 'args':'(0,100)'}) c.start() try: c.function() finally: c.stop() return
def test_configure_3(self): p = PeriodicLog() p.configure({'name':'log','parent':None, 'period':1}) h = CompositeNode() h.configure({'name':'columnholder','parent':p}) c = PeriodicColumn() c.configure({'position':2, 'name':'2', 'parent':h, 'context':'', 'function':'mpx.lib.node.as_node("/").configuration', 'args':'()','conversion':'none'}) c.start() try: c.function() finally: c.stop() return
def test_configure_sequence(self): p = PeriodicLog() p.configure({'name':'log','parent':None, 'period':1}) h = CompositeNode() h.configure({'name':'columns','parent':p}) c = PeriodicAverageColumn() c.configure({'position':0, 'name':'2', 'parent':h, 'function':self._next}) p.start() try: l = [] v = [] for i in range(0,100): l.append(c._evaluate()) v.append(i-0.5) if l.pop(0) != None: raise 'First delta not None.' v.pop(0) for i in l: j = v.pop(0) if i != j: raise 'Incorrect average of %s should be %s.' % (i, j) finally: p.stop() return
def test_configure_sequence_get(self): p = PeriodicLog() p.configure({'name':'log','parent':None, 'period':1}) h = CompositeNode() h.configure({'name':'columns','parent':p}) c = PeriodicDeltaColumn() c.configure({'position':0, 'name':'2', 'parent':h, 'function':self._next}) p.start() try: l = [] if c.get() != None: raise 'Get didn\'t return None on first get' if c.get() != None: raise 'Get didn\'t return None on second get' self.seq.value = 0 c.function() self._next() self._next() self._next() if c.get() != self.seq.value - 1: raise 'Got incorrect value after incrementing' finally: p.stop() return
def _configure(self): p = PeriodicLog() p.configure({'name':'log','parent':None, 'period':1}) h = CompositeNode() h.configure({'name':'columnholder','parent':p}) # Add a compiled function with compile arguments. c = PeriodicColumn() c.configure({'position':0, 'name':'0', 'parent':h, 'function':self._random, 'args':()}) self.collector.add_column(c) # Add a string function, context and arguments. c = PeriodicColumn() c.configure({'position':1, 'name':'1', 'parent':h, 'context':'import random', 'function':'random.uniform', 'args':'()'}) self.collector.add_column(c) # Add a node column. c = PeriodicColumn() c.configure({'position':2, 'name':'2', 'parent':h, 'context':'', 'function':'mpx.lib.node.as_node("/").configuration', 'args':'()'}) self.collector.add_column(c)
def _configure(self): p = PeriodicLog() p.configure({'name': 'log', 'parent': None, 'period': 1}) h = CompositeNode() h.configure({'name': 'columnholder', 'parent': p}) # Add a compiled function with compile arguments. c = PeriodicColumn() c.configure({ 'position': 0, 'name': '0', 'parent': h, 'function': self._random, 'args': () }) self.collector.add_column(c) # Add a string function, context and arguments. c = PeriodicColumn() c.configure({ 'position': 1, 'name': '1', 'parent': h, 'context': 'import random', 'function': 'random.uniform', 'args': '()' }) self.collector.add_column(c) # Add a node column. c = PeriodicColumn() c.configure({ 'position': 2, 'name': '2', 'parent': h, 'context': '', 'function': 'mpx.lib.node.as_node("/").configuration', 'args': '()' }) self.collector.add_column(c)
def test_configure_random(self): p = PeriodicLog() p.configure({'name':'log','parent':None, 'period':1}) h = CompositeNode() h.configure({'name':'columns','parent':p}) c = PeriodicDeltaColumn() c.configure({'position':0, 'name':'0', 'parent':h, 'function':self._random, 'args':()}) p.start() try: for i in range(0,1000): c.function() finally: p.stop() return
def test_configure_context_random(self): p = PeriodicLog() p.configure({'name':'log','parent':None, 'period':1}) h = CompositeNode() h.configure({'name':'columns','parent':p}) c = PeriodicAverageColumn() c.configure({'position':0, 'name':'1', 'parent':h, 'context':'import random', 'function':'random.uniform', 'args':'(0,100)'}) p.start() try: for i in range(0,1000): c.function() finally: p.stop() return
def test_configure_random(self): p = PeriodicLog() p.configure({'name': 'log', 'parent': None, 'period': 1}) h = CompositeNode() h.configure({'name': 'columns', 'parent': p}) c = PeriodicAverageColumn() c.configure({ 'position': 0, 'name': '0', 'parent': h, 'function': self._random, 'args': () }) p.start() try: for i in range(0, 1000): c.function() finally: p.stop() return
def test_configure_context_random(self): p = PeriodicLog() p.configure({'name': 'log', 'parent': None, 'period': 1}) h = CompositeNode() h.configure({'name': 'columns', 'parent': p}) c = PeriodicDeltaColumn() c.configure({ 'position': 0, 'name': '1', 'parent': h, 'context': 'import random', 'function': 'random.uniform', 'args': '(0,100)' }) p.start() try: for i in range(0, 1000): c.function() finally: p.stop() return
def test_configure_sequence(self): p = PeriodicLog() p.configure({'name':'log','parent':None, 'period':1}) h = CompositeNode() h.configure({'name':'columns','parent':p}) c = PeriodicDeltaColumn() c.configure({'position':0, 'name':'2', 'parent':h, 'function':self._next}) p.start() try: l = [] for i in range(0,100): l.append(c.function()) if l.pop(0) != None: raise 'First delta not None.' for i in l: if i != 1: raise 'Incoreect delta of %s should be %s.' % (i, 1) finally: p.stop() return
def get_slice(self,column,start,end): stream = StreamingTupleWithCallback(self._get_item_callback, self._get_length_callback) stream.set_meta('data',PeriodicLog.get_slice(self,column,start,end,1)) return stream
def test_add_entry_event(self): class Consumer(EventConsumerAbstract): def __init__(self, *args, **kw): EventConsumerAbstract.__init__(self, *args, **kw) self.entries = [] self.errors = [] self.lock = Lock() def event_thread(self,event): # The values returned in the event: values = event.values # The column as read from the source Log instance: column_dict = event.source[event.seq] # A map of COLUMN_DICT keys to VALUES indexes. column_value_map = { 'c0':0, } # Validate that the list of values matches the actual column in # the log: for key,index in column_value_map.items(): if not column_dict.has_key(key): self.errors.append('column_dict has no %r key.' % key) return if index >= len(values): self.errors.append('Index(%r) >= len(values:%r).' % (index, len(values))) return if column_dict[key] != values[index]: self.errors.append( 'column_dict[%r]:%r != values[%r]:%r' % ( key, column_dict[key], index, values[index])) return self.lock.acquire() try: # If any entries are left, the test will fail. self.entries.remove(values) except: # Also, if errors is not empty the test will fail. self.errors.append("Failed to find %r in entries." % values) self.lock.release() def event_handler(self,event): t = Thread(target=self.event_thread, args=(event,)) t.start() return consumer = Consumer() p = PeriodicLog() p.configure({'name':'log','parent':None, 'period':0}) h = CompositeNode() h.configure({'name':'columns','parent':p}) c = PeriodicColumn() c.configure({'position':0, 'name':'c0', 'parent':h, 'function':'None',}) p.event_subscribe(consumer, LogAddEntryEvent) p.start() try: for c0 in range(0,10): entry = [c0,] consumer.entries.append(entry) p.add_entry(entry) t1 = time.time() while consumer.entries: if (time.time() - t1) >= 1.0: msgs = [ "Failed to recieve matching events after 1 second." ] msgs.extend(consumer.errors) self.fail('\n'.join(msgs)) pause(0.1) finally: p.stop() return