Ejemplo n.º 1
0
 def testAddDevice(self):
     "Add devices to deviceHolder. If deviceHolder is full throw an exception"
     maxSize = 3
     deviceHolder = DeviceHolder(maxSize)
     deviceHolder.addDevice(self.deviceOne, "hello_world", {"hello": "world"})
     deviceHolder.addDevice(self.deviceTwo, "hello_world", {"hello": "world"})
     name = "device_three"
     if TEST_MODE:
         ipAdress = "client3"
     else:
         ipAdress = "127.0.0.1"
     physicalName = None
     hardwareConfig = None
     taskDict = {}
     initTask = None
     port = 2883
     deviceThree = DeviceSingle( name = name
                               , ipAdress = ipAdress
                               , port = port
                               , dartRuntime = self.dartRuntime
                               , physicalName = physicalName
                               , hardwareConfig = hardwareConfig
                               , taskDict = taskDict
                               , initTask = initTask
                               )
     deviceHolder.addDevice(deviceThree, "hello_world", {"hello": "world"})
     self.assertEqual( ['device_one', 'device_two', 'device_three']
                     , deviceHolder.deviceNames
                     , msg = "Wrong names for devices"
                     )
     with self.assertRaises(Exception) as context:
         deviceHolder.addDevice(deviceThree, "hello_world", {"hello": "world"})
     self.assertTrue("DeviceHolder already full!" in str(context.exception))
Ejemplo n.º 2
0
 def _instantiateDeviceHolders(self):
     """!
     Instantiate devicHolders and append to list of DeviceHolders
     """
     if len(self.deviceHolders) > 0:
         raise ValueError("device holder already instantiated")
     elif len(self.childAggregators) > 0:
         pass
     else:
         for i in range(self._maxNumDeviceHolder):
             deviceHolder = DeviceHolder(self.maxSizeDeviceHolder)
             self.deviceHolders.append(deviceHolder)
Ejemplo n.º 3
0
 def testGetTaskStatus(self):
     "Get the task status ""in progress"" or ""finished"" "
     taskName = "task_one"
     taskParameter = {"param1": "hello", "param2": "world"}
     maxSize = 3
     deviceHolder = DeviceHolder( maxSize
         
                                )
     deviceHolder._deviceList = [ self.deviceOne, self.deviceTwo]
     taskResult = { 'duration': 5
                  , 'result': {'result_0': 10, 'result_1': None}
                  }
     self.deviceOne._openTaskDict = { taskName: taskParameter}
     self.deviceTwo._openTaskDict = { taskName: taskParameter}
     self.assertTrue( deviceHolder.devicesFinished(taskName) == False
                    , msg = "task shouldn't be finished"
                    )
     self.deviceOne._finishedTaskDict = { taskName: taskResult}
     self.deviceOne._openTaskDict = {}
     self.assertTrue( deviceHolder.devicesFinished(taskName) == False
                    , msg = "task shouldn't be finished"
                    )
     self.deviceTwo._finishedTaskDict = { taskName: taskResult}
     self.deviceTwo._openTaskDict = {}
     self.assertTrue( deviceHolder.devicesFinished(taskName) == True
                    , msg = "task should be finished"
                    )
Ejemplo n.º 4
0
 def testBroadCastTask(self):
     "Send the task simultaneously to multiple devices. The task must be added before to the device"
     taskName = "task_one"
     maxSize = 3
     parameterDict = {"param1": 5, "param2": 1}
     model = None
     hardwareRequirements = {}
     configFile = None
     task = SpecificDeviceTask( taskName
                              , parameterDict
                              , model
                              , hardwareRequirements
                              , "test" #filename
                              , "test" #function
                              , configFile
                              )
     deviceHolder = DeviceHolder(maxSize)
     taskName = task.taskName 
     parameterDict = task.parameterDict
     deviceHolder.addDevice(self.deviceOne, taskName, parameterDict)
     deviceHolder.addDevice(self.deviceTwo, taskName, parameterDict)
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceOne.name
                                     , self.deviceOne.ipAdress
                                     , self.deviceOne.port 
                                     , self.deviceOne.hardwareConfig
                                     , self.deviceOne.initTask
                                     )
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceTwo.name
                                     , self.deviceTwo.ipAdress
                                     , self.deviceTwo.port 
                                     , self.deviceTwo.hardwareConfig
                                     , self.deviceTwo.initTask
                                     )
     deviceHolder.broadcastTask(task)
Ejemplo n.º 5
0
 def testGetTaskProgress(self):
     " Get the number of already finished device and the amout of devices, where we have sent the task."
     " Get the task status ""in progress"" or ""finished"" "
     taskName = "task_one"
     taskParameter = {"param1": "hello", "param2": "world"}
     maxSize = 3
     deviceHolder = DeviceHolder(maxSize)
     deviceHolder._deviceList = [ self.deviceOne, self.deviceTwo]
     taskResult = { 'duration': 5
                  , 'result': {'result_0': 10, 'result_1': None}
                  }
     self.deviceOne._openTaskDict = { taskName: taskParameter}
     self.deviceTwo._openTaskDict = { taskName: taskParameter}
     self.assertTrue( deviceHolder.get_taskProgress(taskName) == 0
                    , msg = "wrong task progress"
                    )
     self.deviceOne._finishedTaskDict = { taskName: taskResult}
     self.deviceOne._openTaskDict = {}
     self.deviceTwo._finishedTaskDict = { taskName: taskResult}
     self.deviceTwo._openTaskDict = {}
     self.assertTrue( deviceHolder.get_taskProgress(taskName) == 2
                    , msg = "wrong task progress"
                    )
Ejemplo n.º 6
0
 def testRemoveDevice(self):
     "Remove Device from deviceHolder"
     maxSize = 3
     deviceHolder = DeviceHolder(maxSize)
     deviceHolder.addDevice(self.deviceOne, "hello_world", {"hello": "world"})
     deviceHolder.addDevice(self.deviceTwo, "hello_world", {"hello": "world"})
     deviceHolder.removeDevice(self.deviceOne)
     self.assertEqual( ['device_two']
                     , deviceHolder.deviceNames
                     , msg = "Wrong names for devices"
                     )
Ejemplo n.º 7
0
 def testStopTask(self):
     "Stop the task on server. Remove the task from the openTaskDict"
     taskName = "task_one"
     maxSize = 3
     parameterDict = {"param1": 5, "param2": 1}
     model = None
     hardwareRequirements = {}
     configFile = None
     task = SpecificDeviceTask( taskName
                              , parameterDict
                              , model
                              , hardwareRequirements
                              , "test" #filename
                              , "test" #function
                              , configFile
                              )
     deviceHolder = DeviceHolder( maxSize
                                )
     deviceHolder.addDevice(self.deviceOne, task.taskName, task.parameterDict)
     deviceHolder.addDevice(self.deviceTwo, task.taskName, task.parameterDict)
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceOne.name
                                     , self.deviceOne.ipAdress
                                     , self.deviceOne.port 
                                     , self.deviceOne.hardwareConfig
                                     , self.deviceOne.initTask
                                     )
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceTwo.name
                                     , self.deviceTwo.ipAdress
                                     , self.deviceTwo.port 
                                     , self.deviceTwo.hardwareConfig
                                     , self.deviceTwo.initTask
                                     )
     deviceHolder.broadcastTask(task)
     self.assertEqual( {'task_one': {'param1': 5, 'param2': 1}}
                     , self.deviceOne._openTaskDict
                     , msg = "Wrong entries for openTaskDict"
                     )
     deviceHolder.stopTask(task.taskName)
     self.assertEqual( {}
                     , self.deviceOne._openTaskDict
                     , msg = "Wrong entries for openTaskDict"
                     )
Ejemplo n.º 8
0
 def send_initTask_to_newDevices(self, deviceList):
     """! In the case that a device has connected on their own we must send 
         the init task to them before sending another tasks.
     """
     self.logger.log().debug(
         "selector. send_initTask_to_newDevices. deviceList " +
         str(deviceList))
     initializationDevices = []
     for device in deviceList:
         if device.hasTask(self.initTask.taskName) == False:
             initializationDevices.append(device)
     number_not_inializedDevices = len(initializationDevices)
     if number_not_inializedDevices > 0:
         deviceHolder = DeviceHolder(maxSize=number_not_inializedDevices)
         for device in initializationDevices:
             deviceHolder.addDevice(device, self.initTask.taskName,
                                    self.initTask.parameterDict)
         deviceHolder.broadcastTask(self.initTask)
Ejemplo n.º 9
0
 def testGetFinishedTasks(self):
     "Get the results from already finished devices"
     taskName = "task_one"
     maxSize = 3
     parameterDict = {"param1": 5, "param2": 1}
     parameterDict2 = {"param1": 5, "param2": 4}
     model = None
     hardwareRequirements = {}
     configFile = None
     task = SpecificDeviceTask( taskName
                              , parameterDict
                              , model
                              , hardwareRequirements
                              , "test" #filename
                              , "test" #function
                              , configFile
                              )
     deviceHolder = DeviceHolder(maxSize)
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceOne.name
                                     , self.deviceOne.ipAdress
                                     , self.deviceOne.port 
                                     , self.deviceOne.hardwareConfig
                                     , self.deviceOne.initTask
                                     )
     self.dartRuntime.generate_and_add_SingleDevice( self.deviceTwo.name
                                     , self.deviceTwo.ipAdress
                                     , self.deviceTwo.port 
                                     , self.deviceTwo.hardwareConfig
                                     , self.deviceTwo.initTask
                                     )
     deviceHolder.addDevice(self.deviceOne, task.taskName, task.parameterDict)
     deviceHolder.addDevice(self.deviceTwo, task.taskName, parameterDict2)
     deviceHolder.broadcastTask(task)
     self.assertEqual( deviceHolder.get_finishedTasks(taskName)[0].resultDict
                     , {'result_0': 6 } 
                     , msg = "Wrong entries for finished tasks"
                     )
     self.assertEqual( deviceHolder.get_finishedTasks(taskName)[1].resultDict
                     , {'result_0': 9 } 
                     , msg = "Wrong entries for finished tasks"
                     )
     with self.assertRaises(Exception) as context:
         deviceHolder.get_finishedTasks("hello")
     self.assertTrue("No task with name" in str(context.exception))