def test_command_setting(self):
     inputunit = configure_unit(unit_setup = unit_core.GenericUnit, input_ids = [], update_cycle = 0, description = "Input unit - clock")
     print "INPUTUNIT.unit_id", inputunit.unit_id
     processunit = configure_unit(unit_setup = unit_core.PassThruUnit, input_ids = [inputunit.unit_id], update_cycle = 0, description = "PassThruUnit unit")
     print "PROCESSUNIT.unit_id", processunit.unit_id
     # Process announces
     
     for __ in xrange(5):
         inputunit.update()
         processunit.update()
         
     # Create a task that requests configuration from input unit 
     id = uuid.uuid4().hex
     taskboard = Taskboard(id)
     command = {"setting":{"common": {"configurable": {"update_cycle": 9999}}}}                   
     task = Task(unit_id = processunit.unit_id, from_unit = processunit.unit_id, to_unit = inputunit.unit_id, command = command)
     task_id = task.task_id
     taskboard.add(task)
     
     for __ in xrange(5):
         inputunit.update()
         processunit.update()
         
     # Should be no memory initially on inputunit       
     self.assertEquals(inputunit.configuration.unit_config["common"]["configurable"]["update_cycle"], 9999)                
 def test_command_announce_a(self):
     inputunit = configure_unit(unit_setup = unit_core.GenericUnit, input_ids = [], update_cycle = 0, description = "Input unit - clock")
     print "INPUTUNIT.unit_id", inputunit.unit_id
     processunit = configure_unit(unit_setup = unit_core.PassThruUnit, input_ids = [inputunit.unit_id], update_cycle = 0, description = "PassThruUnit unit")
     print "PROCESSUNIT.unit_id", processunit.unit_id
     # Process announces
     
     for __ in xrange(5):
         inputunit.update()
         processunit.update()
         
     # Create a task that requests configuration from input unit 
     id = uuid.uuid4().hex
     taskboard = Taskboard(id)
     command = {"announce":{}}                
     task = Task(unit_id = processunit.unit_id, from_unit = processunit.unit_id, to_unit = inputunit.unit_id, command = command)
     task_id = task.task_id
     taskboard.add(task)
     
     for __ in xrange(5):
         inputunit.update()
         processunit.update()
         
     print "task.response", task.response
     inputunit.taskboard.debug()
     processunit.taskboard.debug()
         
           
     self.assertTrue(False)
 def test_command_configuration(self):
     # Test sending a configuration request, and confirming the unit responds
     # with current configuration.
     inputunit = configure_unit(unit_setup = unit_core.GenericUnit, input_ids = [], update_cycle = 0, description = "Test string af31")
     print "INPUTUNIT.unit_id", inputunit.unit_id
     processunit = configure_unit(unit_setup = unit_core.PassThruUnit, input_ids = [inputunit.unit_id], update_cycle = 0, description = "PassThruUnit unit")
     print "PROCESSUNIT.unit_id", processunit.unit_id
     # Process announces
     
     for __ in xrange(5):
         inputunit.update()
         processunit.update()
         
     # Create a task that requests configuration
     id = uuid.uuid4().hex
     taskboard = Taskboard(id)
     command = {"configuration":"Null"}
                 
     task = Task(unit_id = processunit.unit_id, from_unit = processunit.unit_id, to_unit = inputunit.unit_id, command = command)
     task_id = task.task_id
     taskboard.add(task)
     
     for __ in xrange(5):
         inputunit.update()
         processunit.update()
         
     # Should be no memory initially on inputunit       
     self.assertEquals(inputunit.configuration.unit_config["common"]["non_configurable"]["description"], "Test string af31")
Esempio n. 4
0
    def test_listen_for_response(self):
        taskboard = Taskboard(uuid.uuid4().hex)

        command = {"memory": {}}
        id = uuid.uuid4().hex
        to = uuid.uuid4().hex

        # Create a task
        #task = taskboard.request(to, command)
        task = Task(id, from_unit=id, to_unit=to, command=command)
        #taskboard.add(task)

        print "posted task", task.json()

        # Should be no response.
        self.assertTrue(task.response == {})
        self.assertTrue(task.board == 'Backlog')

        response = {"test": "test"}
        task.add_response(response=response)

        #taskboard.respond(task)

        self.assertTrue(task.response <> {})
        self.assertTrue(task.board == 'Backlog')
Esempio n. 5
0
    def test_chronicle(self):

        # Create a task that requests configuration from input unit
        id0 = uuid.uuid4().hex
        id1 = uuid.uuid4().hex
        id2 = uuid.uuid4().hex
        taskboard = Taskboard(id1)
        command = {"announce": {}}
        chronicle = [{'time_ms': 0.0, 'unit_id': id0, 'hop': 1}]

        task = Task(unit_id=id0,
                    chronicle=chronicle,
                    from_unit=id1,
                    to_unit=id2,
                    command=command)
        taskboard.add(task)
        self.assertTrue(len(task.chronicle) == 1)

        c = Chronicle(unit_id=id1, chronicle=task.chronicle)
        c.update()

        task.chronicle = c.json()
        self.assertTrue(len(task.chronicle) == 2)

        c = Chronicle(unit_id=id2, chronicle=task.chronicle)
        c.update()

        self.assertTrue(len(task.chronicle) == 3)

        print "task.chronicle", c.chronicle

        # Test last
        self.assertEquals(c.last(), id2)
        # Test next
        self.assertEquals(c.next(id1), id2)
        self.assertEquals(c.next(id0), id1)
        # Test previous
        self.assertEquals(c.previous(id1), id0)
        self.assertEquals(c.previous(id2), id1)

        # Test error condition

        self.assertRaises(LookupError, lambda: c.next(id2))

        self.assertRaises(LookupError, lambda: c.previous(id0))
Esempio n. 6
0
    def test_command_setting(self):
        inputunit = configure_unit(unit_setup=unit_core.GenericUnit,
                                   input_ids=[],
                                   update_cycle=0,
                                   description="Input unit - clock")
        print "INPUTUNIT.unit_id", inputunit.unit_id
        processunit = configure_unit(unit_setup=unit_core.PassThruUnit,
                                     input_ids=[inputunit.unit_id],
                                     update_cycle=0,
                                     description="PassThruUnit unit")
        print "PROCESSUNIT.unit_id", processunit.unit_id
        # Process announces

        for __ in xrange(5):
            inputunit.update()
            processunit.update()

        # Create a task that requests configuration from input unit
        id = uuid.uuid4().hex
        taskboard = Taskboard(id)
        command = {
            "setting": {
                "common": {
                    "configurable": {
                        "update_cycle": 9999
                    }
                }
            }
        }
        task = Task(unit_id=processunit.unit_id,
                    from_unit=processunit.unit_id,
                    to_unit=inputunit.unit_id,
                    command=command)
        task_id = task.task_id
        taskboard.add(task)

        for __ in xrange(5):
            inputunit.update()
            processunit.update()

        # Should be no memory initially on inputunit
        self.assertEquals(
            inputunit.configuration.unit_config["common"]["configurable"]
            ["update_cycle"], 9999)
    def test_request(self):
        from_unit = uuid.uuid4().hex
        taskboard = Taskboard(uuid.uuid4().hex)

        command = {"test":"test"}
        to = uuid.uuid4().hex

        task = Task(unit_id = from_unit, command = command, to_unit = to, from_unit = from_unit)
        
        # Pass a dict object to to taskboard.request
        taskboard.request(to, command)
        
        print "task_id", taskboard.tasks[0].task_id
        
        
        r= taskboard_interface.get_task(taskboard.tasks[0].task_id)
        print r
        t = r['task_id']
        print t
        self.assertEquals(t,taskboard.tasks[0].task_id)
 def test_chronicle(self):
         
     # Create a task that requests configuration from input unit
     id0 = uuid.uuid4().hex 
     id1 = uuid.uuid4().hex
     id2 = uuid.uuid4().hex
     taskboard = Taskboard(id1)
     command = {"announce":{}}
     chronicle = [{'time_ms': 0.0, 'unit_id': id0, 'hop': 1}]
                
     task = Task(unit_id = id0, chronicle = chronicle, from_unit = id1, to_unit = id2, command = command)     
     taskboard.add(task)  
     self.assertTrue(len(task.chronicle)==1)
     
     c = Chronicle(unit_id = id1, chronicle = task.chronicle)
     c.update()
     
     task.chronicle = c.json()      
     self.assertTrue(len(task.chronicle)==2)
     
     c = Chronicle(unit_id = id2, chronicle = task.chronicle)
     c.update()
     
     self.assertTrue(len(task.chronicle)==3)
     
     print "task.chronicle", c.chronicle
      
     # Test last
     self.assertEquals(c.last(), id2)
     # Test next
     self.assertEquals(c.next(id1), id2)
     self.assertEquals(c.next(id0), id1)
     # Test previous
     self.assertEquals(c.previous(id1), id0)
     self.assertEquals(c.previous(id2), id1)
     
     # Test error condition
     
     self.assertRaises(LookupError, lambda: c.next(id2))
     
     self.assertRaises(LookupError, lambda: c.previous(id0))
Esempio n. 9
0
    def test_command_configuration(self):
        # Test sending a configuration request, and confirming the unit responds
        # with current configuration.
        inputunit = configure_unit(unit_setup=unit_core.GenericUnit,
                                   input_ids=[],
                                   update_cycle=0,
                                   description="Test string af31")
        print "INPUTUNIT.unit_id", inputunit.unit_id
        processunit = configure_unit(unit_setup=unit_core.PassThruUnit,
                                     input_ids=[inputunit.unit_id],
                                     update_cycle=0,
                                     description="PassThruUnit unit")
        print "PROCESSUNIT.unit_id", processunit.unit_id
        # Process announces

        for __ in xrange(5):
            inputunit.update()
            processunit.update()

        # Create a task that requests configuration
        id = uuid.uuid4().hex
        taskboard = Taskboard(id)
        command = {"configuration": "Null"}

        task = Task(unit_id=processunit.unit_id,
                    from_unit=processunit.unit_id,
                    to_unit=inputunit.unit_id,
                    command=command)
        task_id = task.task_id
        taskboard.add(task)

        for __ in xrange(5):
            inputunit.update()
            processunit.update()

        # Should be no memory initially on inputunit
        self.assertEquals(
            inputunit.configuration.unit_config["common"]["non_configurable"]
            ["description"], "Test string af31")
Esempio n. 10
0
    def test_request(self):
        from_unit = uuid.uuid4().hex
        taskboard = Taskboard(uuid.uuid4().hex)

        command = {"test": "test"}
        to = uuid.uuid4().hex

        task = Task(unit_id=from_unit,
                    command=command,
                    to_unit=to,
                    from_unit=from_unit)

        # Pass a dict object to to taskboard.request
        taskboard.request(to, command)

        print "task_id", taskboard.tasks[0].task_id

        r = taskboard_interface.get_task(taskboard.tasks[0].task_id)
        print r
        t = r['task_id']
        print t
        self.assertEquals(t, taskboard.tasks[0].task_id)
Esempio n. 11
0
    def test_add(self):
        # Taskboard - Add and remove a task
        id = uuid.uuid4().hex
        taskboard = Taskboard(id)
        task = Task(unit_id=id,
                    from_unit=uuid.uuid4().hex,
                    to_unit=uuid.uuid4().hex)
        task_id = task.task_id
        taskboard.add(task)
        search_task = taskboard.find_task(task.task_id)
        # Expect to find the task we have just added
        self.assertEquals(task_id, search_task.task_id)

        taskboard.remove(task)
        self.assertRaises(LookupError, lambda: taskboard.find_task(task_id))
Esempio n. 12
0
    def test_command_announce_a(self):
        inputunit = configure_unit(unit_setup=unit_core.GenericUnit,
                                   input_ids=[],
                                   update_cycle=0,
                                   description="Input unit - clock")
        print "INPUTUNIT.unit_id", inputunit.unit_id
        processunit = configure_unit(unit_setup=unit_core.PassThruUnit,
                                     input_ids=[inputunit.unit_id],
                                     update_cycle=0,
                                     description="PassThruUnit unit")
        print "PROCESSUNIT.unit_id", processunit.unit_id
        # Process announces

        for __ in xrange(5):
            inputunit.update()
            processunit.update()

        # Create a task that requests configuration from input unit
        id = uuid.uuid4().hex
        taskboard = Taskboard(id)
        command = {"announce": {}}
        task = Task(unit_id=processunit.unit_id,
                    from_unit=processunit.unit_id,
                    to_unit=inputunit.unit_id,
                    command=command)
        task_id = task.task_id
        taskboard.add(task)

        for __ in xrange(5):
            inputunit.update()
            processunit.update()

        print "task.response", task.response
        inputunit.taskboard.debug()
        processunit.taskboard.debug()

        self.assertTrue(False)
 def test_add(self):
     # Taskboard - Add and remove a task 
     id = uuid.uuid4().hex
     taskboard = Taskboard(id)
     task = Task(unit_id = id, from_unit = uuid.uuid4().hex, to_unit = uuid.uuid4().hex)
     task_id = task.task_id
     taskboard.add(task)
     search_task = taskboard.find_task(task.task_id)
     # Expect to find the task we have just added
     self.assertEquals(task_id, search_task.task_id)
     
     taskboard.remove(task) 
     self.assertRaises(LookupError, lambda: taskboard.find_task(task_id))
Esempio n. 14
0
    def test_taskboard(self):
        # Taskboard - Add and remove a task
        from_id = uuid.uuid4().hex
        to_id = uuid.uuid4().hex
        taskboard = Taskboard(from_id)
        task = Task(unit_id=from_id, from_unit=from_id, to_unit=to_id)
        expected_task_id = task.task_id
        taskboard.add(task)
        task = taskboard.find_task(task.task_id)
        # Expect to find the task we have just added
        self.assertEquals(expected_task_id, task.task_id)

        taskboard.remove(task)
        self.assertRaises(LookupError, taskboard.find_task, expected_task_id)
 def test_taskboard(self):
     # Taskboard - Add and remove a task 
     from_id = uuid.uuid4().hex
     to_id = uuid.uuid4().hex
     taskboard = Taskboard(from_id)
     task = Task(unit_id = from_id, from_unit = from_id, to_unit = to_id)
     expected_task_id = task.task_id
     taskboard.add(task)
     task = taskboard.find_task(task.task_id)
     # Expect to find the task we have just added
     self.assertEquals(expected_task_id, task.task_id)
     
     taskboard.remove(task)
     self.assertRaises(LookupError, taskboard.find_task, expected_task_id)
Esempio n. 16
0
    def test_command_memory(self):
        # Test sending memory and replacing contents of
        # existing memory

        # Set update cycle to 10,000 to avoid generating data.
        inputunit = configure_unit(unit_setup=unit_core.GenericUnit,
                                   input_ids=[],
                                   update_cycle=0,
                                   description="Test string af31")
        print "INPUTUNIT.unit_id", inputunit.unit_id
        processunit = configure_unit(unit_setup=unit_core.PassThruUnit,
                                     input_ids=[inputunit.unit_id],
                                     update_cycle=0,
                                     description="PassThruUnit unit")
        print "PROCESSUNIT.unit_id", processunit.unit_id
        # Process announces

        for __ in xrange(5):
            inputunit.update()
            processunit.update()

        # Test that empty strings can be sent/
        id = uuid.uuid4().hex
        taskboard = Taskboard(id)
        command = {"memory": {'forecast': [], 'history': []}}

        task = Task(unit_id=processunit.unit_id,
                    from_unit=processunit.unit_id,
                    to_unit=inputunit.unit_id,
                    command=command)
        taskboard.add(task)

        for __ in xrange(1):
            inputunit.update()
            processunit.update()

        print "forecast"
        for i in inputunit.memory.forecast:
            print i.data
        print "history"
        for i in inputunit.memory.history:
            print i.data

        self.assertRaises(IndexError,
                          lambda: inputunit.memory.forecast[0].data)
        self.assertRaises(IndexError, lambda: inputunit.memory.history[0].data)
        ''' Test that array of data points can be sent and received '''

        #         print "forecast"
        #         for i in inputunit.memory.forecast:
        #             print i.data
        #         print "history"
        #         for i in inputunit.memory.history:
        #             print i.data

        self.assertRaises(IndexError, lambda: inputunit.memory.history[0].data)
        self.assertRaises(IndexError,
                          lambda: inputunit.memory.forecast[0].data)

        command = {
            "memory": {
                'forecast': [{
                    'time_stamp': 'Sat, 27 Sep 2014 23:32:00 -0000',
                    'data': {
                        'dummy_reading': 707
                    }
                }, {
                    'time_stamp': 'Sat, 27 Sep 2014 23:31:59 -0000',
                    'data': {
                        'dummy_reading': 808
                    }
                }, {
                    'time_stamp': 'Sat, 27 Sep 2014 23:31:57 -0000',
                    'data': {
                        'dummy_reading': 909
                    }
                }],
                'history': [{
                    'time_stamp': 'Sat, 27 Sep 2014 23:32:00 -0000',
                    'data': {
                        'dummy_reading': 404
                    }
                }, {
                    'time_stamp': 'Sat, 27 Sep 2014 23:31:59 -0000',
                    'data': {
                        'dummy_reading': 505
                    }
                }, {
                    'time_stamp': 'Sat, 27 Sep 2014 23:31:57 -0000',
                    'data': {
                        'dummy_reading': 606
                    }
                }]
            }
        }

        task = Task(unit_id=processunit.unit_id,
                    from_unit=processunit.unit_id,
                    to_unit=inputunit.unit_id,
                    command=command)
        taskboard.add(task)

        for __ in xrange(1):
            inputunit.update()
            processunit.update()

        print "forecast"
        for i in inputunit.memory.forecast:
            print i.data
        print "history"
        for i in inputunit.memory.history:
            print i.data
        # Should be no memory initially on inputunit

        self.assertEquals({"dummy_reading": 707},
                          inputunit.memory.forecast[0].data)
        self.assertEquals({"dummy_reading": 404},
                          inputunit.memory.history[0].data)
    def test_command_memory(self):
        # Test sending memory and replacing contents of
        # existing memory
        
        # Set update cycle to 10,000 to avoid generating data.
        inputunit = configure_unit(unit_setup = unit_core.GenericUnit, input_ids = [], update_cycle = 0, description = "Test string af31")
        print "INPUTUNIT.unit_id", inputunit.unit_id
        processunit = configure_unit(unit_setup = unit_core.PassThruUnit, input_ids = [inputunit.unit_id], update_cycle = 0, description = "PassThruUnit unit")
        print "PROCESSUNIT.unit_id", processunit.unit_id
        # Process announces
        
        for __ in xrange(5):
            inputunit.update()
            processunit.update()
            
        # Test that empty strings can be sent/
        id = uuid.uuid4().hex
        taskboard = Taskboard(id)
        command = {"memory":
                    {'forecast': [], 
                     'history': []}
                   }
                            
        task = Task(unit_id = processunit.unit_id, from_unit = processunit.unit_id, to_unit = inputunit.unit_id, command = command)
        taskboard.add(task)
        
        for __ in xrange(1):
            inputunit.update()
            processunit.update()

        print "forecast"
        for i in inputunit.memory.forecast:
            print i.data
        print "history"
        for i in inputunit.memory.history:
            print i.data
            
        self.assertRaises(IndexError,lambda: inputunit.memory.forecast[0].data)
        self.assertRaises(IndexError, lambda: inputunit.memory.history[0].data)
            
        ''' Test that array of data points can be sent and received '''     
      
#         print "forecast"
#         for i in inputunit.memory.forecast:
#             print i.data
#         print "history"
#         for i in inputunit.memory.history:
#             print i.data
        
        self.assertRaises(IndexError, lambda: inputunit.memory.history[0].data)
        self.assertRaises(IndexError, lambda: inputunit.memory.forecast[0].data)
        
        command = {"memory":
                    {'forecast': 
                        [{'time_stamp': 'Sat, 27 Sep 2014 23:32:00 -0000', 'data': {'dummy_reading': 707}},
                         {'time_stamp': 'Sat, 27 Sep 2014 23:31:59 -0000', 'data': {'dummy_reading': 808}}, 
                         {'time_stamp': 'Sat, 27 Sep 2014 23:31:57 -0000', 'data': {'dummy_reading': 909}}], 
                     'history': 
                        [{'time_stamp': 'Sat, 27 Sep 2014 23:32:00 -0000', 'data': {'dummy_reading': 404}},
                         {'time_stamp': 'Sat, 27 Sep 2014 23:31:59 -0000', 'data': {'dummy_reading': 505}}, 
                         {'time_stamp': 'Sat, 27 Sep 2014 23:31:57 -0000', 'data': {'dummy_reading': 606}}]}
                   }
        
        task = Task(unit_id = processunit.unit_id, from_unit = processunit.unit_id, to_unit = inputunit.unit_id, command = command)
        taskboard.add(task)
        
        for __ in xrange(1):
            inputunit.update()
            processunit.update()
 
        print "forecast"
        for i in inputunit.memory.forecast:
            print i.data
        print "history"
        for i in inputunit.memory.history:
            print i.data           
        # Should be no memory initially on inputunit       

        self.assertEquals({"dummy_reading":707}, inputunit.memory.forecast[0].data)
        self.assertEquals({"dummy_reading":404}, inputunit.memory.history[0].data)