Ejemplo n.º 1
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.º 2
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.º 3
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))
Ejemplo n.º 4
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"
                     )