def setUp(self): server = "https://127.0.0.0.1:7777" client_key = "000" name1 = "device_one" name2 = "device_two" if TEST_MODE: ipAdress1 = "client1" ipAdress2 = "client2" else: ipAdress1 = "127.0.0.1" ipAdress2 = "127.0.0.1" self.dartRuntime = DartRuntime( server , client_key , TEST_MODE , ERROR_PROBABILITY ) self.deviceOne = DeviceSingle( name = name1 , ipAdress = ipAdress1 , port = 2883 , dartRuntime = self.dartRuntime , physicalName = None , hardwareConfig = None , taskDict = {} , initTask = None ) self.deviceTwo = DeviceSingle( name = name2 , ipAdress = ipAdress2 , port = 2883 , dartRuntime = self.dartRuntime , physicalName = None , hardwareConfig = None , taskDict = {} , initTask = None )
def startFedDART(self, runtimeFile=None, deviceFile=None, maximal_numberDevices=-1): """! @param deviceFile path to already known devices @todo specify deviceFile """ self.logger.log().debug('start feddart server, config: ' + str(locals())) with open(runtimeFile) as runtimeFile: runtime = json.load(runtimeFile) self._runtime = DartRuntime(runtime["server"], runtime["client_key"], self._testMode, self._errorProbability, maximal_numberDevices, self.maximalNumberOpenJobs) self._selector = self.runtime.instantiateSelector( self._maxSizeDeviceHolder) if self._initTask: self.selector.initTask = self._initTask if deviceFile is not None: with open(deviceFile) as deviceFile: deviceFile = json.load(deviceFile) for deviceName in deviceFile: self.selector.addSingleDevice( deviceName, deviceFile[deviceName]["ipAdress"], deviceFile[deviceName]["port"], deviceFile[deviceName]["hardware_config"])
def setUp(self): server = "https://127.0.0.0.1:7777" client_key = "000" name = "device_one" if TEST_MODE: ipAdress = "client1" else: ipAdress = "127.0.0.1" self.dartRuntime = DartRuntime(server, client_key, TEST_MODE, ERROR_PROBABILITY) physicalName = None hardwareConfig = None taskDict = {} initTask = None port = 2883 self.deviceSingle = DeviceSingle(name=name, ipAdress=ipAdress, port=port, dartRuntime=self.dartRuntime, physicalName=physicalName, hardwareConfig=hardwareConfig, taskDict=taskDict, initTask=initTask)
class TestDeviceSingle(unittest.TestCase): def setUp(self): server = "https://127.0.0.0.1:7777" client_key = "000" name1 = "device_one" name2 = "device_two" if TEST_MODE: ipAdress1 = "client1" ipAdress2 = "client2" else: ipAdress1 = "127.0.0.1" ipAdress2 = "127.0.0.1" self.dartRuntime = DartRuntime( server , client_key , TEST_MODE , ERROR_PROBABILITY ) self.deviceOne = DeviceSingle( name = name1 , ipAdress = ipAdress1 , port = 2883 , dartRuntime = self.dartRuntime , physicalName = None , hardwareConfig = None , taskDict = {} , initTask = None ) self.deviceTwo = DeviceSingle( name = name2 , ipAdress = ipAdress2 , port = 2883 , dartRuntime = self.dartRuntime , physicalName = None , hardwareConfig = None , taskDict = {} , initTask = None ) def tearDown(self): pass 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)) 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" ) 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) 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" ) 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)) 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" ) 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" )
class TestDeviceSingle(unittest.TestCase): def setUp(self): server = "https://127.0.0.0.1:7777" client_key = "000" name = "device_one" if TEST_MODE: ipAdress = "client1" else: ipAdress = "127.0.0.1" self.dartRuntime = DartRuntime(server, client_key, TEST_MODE, ERROR_PROBABILITY) physicalName = None hardwareConfig = None taskDict = {} initTask = None port = 2883 self.deviceSingle = DeviceSingle(name=name, ipAdress=ipAdress, port=port, dartRuntime=self.dartRuntime, physicalName=physicalName, hardwareConfig=hardwareConfig, taskDict=taskDict, initTask=initTask) def tearDown(self): pass def testAddTask(self): "Add tasks to openTaskDict. If task is already existing through an exception" taskName = "task_one" taskParameter = {"param1": "hello", "param2": "world"} self.deviceSingle.addTask(taskName, taskParameter) self.assertEqual(self.deviceSingle.openTaskDict, {'task_one': { 'param1': 'hello', 'param2': 'world' }}, msg="Wrong dict entries for openTaskDict") taskName = "task_one" taskParameter = {"param1": "hello", "param2": "world"} with self.assertRaises(Exception) as context: self.deviceSingle.addTask(taskName, taskParameter) self.assertTrue("already in openTaskDict!" in str(context.exception)) taskName = "task_two" taskParameter = {"param1": "hello", "param2": "world"} self.deviceSingle.addTask(taskName, taskParameter) self.assertEqual(self.deviceSingle.openTaskDict, { 'task_one': { 'param1': 'hello', 'param2': 'world' }, 'task_two': { 'param1': 'hello', 'param2': 'world' } }, msg="Wrong dict entries for openTaskDict") def testAddFinishedTask(self): "Add tasks to finishedTaskDict. If task is already existing through an exception" taskName = "task_one" taskResult = { 'duration': 5, 'result': { 'result_0': 10, 'result_1': None } } self.deviceSingle._addFinishedTask(taskName, taskResult) self.assertEqual(self.deviceSingle.finishedTaskDict, {'task_one': taskResult}, msg="Wrong dict entries for finishedTaskDict") taskName = "task_one" with self.assertRaises(Exception) as context: self.deviceSingle._addFinishedTask(taskName, taskResult) self.assertTrue( "already in finishedTaskDict!" in str(context.exception)) taskName = "task_two" self.deviceSingle._addFinishedTask(taskName, taskResult) self.assertEqual(self.deviceSingle.finishedTaskDict, { 'task_one': taskResult, 'task_two': taskResult }, msg="Wrong dict entries for finishedTaskDict") def testisOpenTask(self): "Check if taskName is in openTaskDict" taskName = "task_one" taskParameter = {"param1": "hello", "param2": "world"} self.deviceSingle.addTask(taskName, taskParameter) self.assertTrue(self.deviceSingle.isOpenTask("task_one") == True, msg="Task should be an open task") self.assertTrue(self.deviceSingle.isOpenTask("task_two") == False, msg="Task should be not an open task") def testRemoveOpenTask(self): "Try to remove tasks from openTaskDict" taskName = "task_one" taskParameter = {"param1": "hello", "param2": "world"} self.deviceSingle.addTask(taskName, taskParameter) taskName = "task_two" self.deviceSingle.addTask(taskName, taskParameter) self.deviceSingle.removeOpenTask("task_one") self.assertTrue(self.deviceSingle.isOpenTask("task_one") == False, msg="Task should not be an open task") self.assertEqual(self.deviceSingle.openTaskDict, {'task_two': { 'param1': 'hello', 'param2': 'world' }}, msg="Wrong dict entries for openTaskDict") def testGetOpenTaskParameter(self): "Get the parameter of an open task" taskName = "task_one" taskParameter = {"param1": "hello", "param2": "world"} self.deviceSingle.addTask(taskName, taskParameter) self.assertEqual(self.deviceSingle.getOpenTaskParameter("task_one"), { 'param1': 'hello', 'param2': 'world' }, msg="Wrong parameter for task!") with self.assertRaises(Exception) as context: self.deviceSingle.getOpenTaskParameter("task_twp") self.assertTrue("Open task with name" in str(context.exception)) def testGetFinishedTaskResult(self): "Get the result of a finished task" taskName = "task_one" taskResult = { 'duration': 5, 'result': { 'result_0': 10, 'result_1': None } } self.deviceSingle._addFinishedTask(taskName, taskResult) self.assertEqual(self.deviceSingle._getFinishedTaskResult("task_one"), taskResult, msg="Wrong results for task!") with self.assertRaises(Exception) as context: self.deviceSingle._getFinishedTaskResult("task_two") self.assertTrue("Finished task with name" in str(context.exception)) def testHasTask(self): "Check if the device has a task with such an name in open or finished tasks" taskName = "task_one" taskParameter = {"param1": "hello", "param2": "world"} self.deviceSingle.addTask(taskName, taskParameter) taskName = "task_two" taskResult = { 'duration': 5, 'result': { 'result_0': 10, 'result_1': None } } self.deviceSingle._addFinishedTask(taskName, taskResult) self.assertTrue(self.deviceSingle.hasTask("task_one") == True, msg="Device should have task") self.assertTrue(self.deviceSingle.hasTask("task_two") == True, msg="Device should have task") self.assertTrue(self.deviceSingle.hasTask("task_three") == False, msg="Device should not have task") def testInitTask(self): "Check if the init task is executed" taskName = "task_one" parameterDict = {"bool_string": "True"} model = None hardwareRequirements = {} configFile = None task = InitTask( parameterDict, model, hardwareRequirements, "test" #filename , "init" #function , configFile) self.assertTrue(self.deviceSingle.initialized == True, msg="Device should be initialized") self.deviceSingle._initialized = False self.deviceSingle.initTask = task self.deviceSingle.addTask(task.taskName, task.parameterDict) self.dartRuntime.add_SingleDevice(self.deviceSingle) self.assertTrue(self.deviceSingle.initialized, msg="Device should be initialized") def testStartTask(self): "Check starting a task. A task must be added before we can start the task" taskName = "task_one" parameterDict = {"param1": 5, "param2": 3} model = None hardwareRequirements = {} configFile = None task = SpecificDeviceTask( taskName, parameterDict, model, hardwareRequirements, "test" #filename , "test" #function , configFile) self.dartRuntime.generate_and_add_SingleDevice( self.deviceSingle.name, self.deviceSingle.ipAdress, self.deviceSingle.port, self.deviceSingle.hardwareConfig, self.deviceSingle.initTask) self.deviceSingle.addTask(task.taskName, task.parameterDict) self.deviceSingle.startTask(task) taskName = "task_two" task_two = SpecificDeviceTask( taskName, parameterDict, model, hardwareRequirements, "test" #filename , "test" #function , configFile) with self.assertRaises(Exception) as context: self.deviceSingle.startTask(task_two) self.assertTrue("Add the task" in str(context.exception)) def testGetTaskResult(self): "Try to get results from valid and unvalid task names" taskName = "task_one" taskParameter = {"param1": "hello", "param2": "world"} taskResult = { 'duration': 5, 'result': { 'result_0': 10, 'result_1': None } } self.deviceSingle._addFinishedTask(taskName, taskResult) self.assertEqual(self.deviceSingle.get_taskResult("task_one"), { 'duration': 5, 'result': { 'result_0': 10, 'result_1': None } }, msg="Wrong results for task!") with self.assertRaises(Exception) as context: self.deviceSingle.get_taskResult("hello") self.assertTrue("No task with name" in str(context.exception)) self.assertEqual(self.deviceSingle.openTaskDict, {}, msg="No open task!") self.assertEqual(self.deviceSingle.finishedTaskDict, { 'task_one': { 'duration': 5, 'result': { 'result_0': 10, 'result_1': None } } }, msg="wrong finished tasks!") def testChangefromOpentoFinishedTask(self): "Check if a finished task is removed from the openTaskDict" taskName = "task_one" parameterDict = {"param1": 5, "param2": 3} model = None hardwareRequirements = {} configFile = None task = SpecificDeviceTask( taskName, parameterDict, model, hardwareRequirements, "test" #filename , "test" #function , configFile) self.dartRuntime.generate_and_add_SingleDevice( self.deviceSingle.name, self.deviceSingle.ipAdress, self.deviceSingle.port, self.deviceSingle.hardwareConfig, self.deviceSingle.initTask) self.deviceSingle.addTask(task.taskName, task.parameterDict) self.deviceSingle.startTask(task) self.deviceSingle.get_taskResult(taskName) self.assertEqual(self.deviceSingle.openTaskDict, {}, msg="No open task!") def testHasTaskResult(self): "Check the results from valid and unvalid task names" taskName = "task_one" taskParameter = {"param1": "hello", "param2": "world"} self.deviceSingle.addTask(taskName, taskParameter) taskResult = { 'duration': 5, 'result': { 'result_0': 10, 'result_1': None } } self.assertTrue(self.deviceSingle.has_taskResult("task_one") == False, msg="There should be a result from the task!") self.deviceSingle._addFinishedTask(taskName, taskResult) self.assertTrue(self.deviceSingle.has_taskResult("task_one") == True, msg="There should be a result from the task!") with self.assertRaises(Exception) as context: self.deviceSingle.has_taskResult("hello") self.assertTrue("No task with name" in str(context.exception))
def setUp(self): taskName = "task_one" maxSize = 3 parameterDict = { "device_one": {"param1": 5, "param2": 1} , "device_two": {"param1": 5, "param2": 1} } model = None hardwareRequirements = {} configFile = None self.task = SpecificDeviceTask( taskName , parameterDict , model , hardwareRequirements , "test" #filename , "test" #function , configFile ) server = "https://127.0.0.0.1:7777" client_key = "000" name1 = "device_one" name2 = "device_two" if TEST_MODE: ipAdress1 = "client1" ipAdress2 = "client2" else: ipAdress1 = "127.0.0.1" ipAdress2 = "127.0.0.1" self.dartRuntime = DartRuntime( server , client_key , TEST_MODE , ERROR_PROBABILITY ) self.deviceOne = DeviceSingle( name = name1 , ipAdress = ipAdress1 , port = 2883 , dartRuntime = self.dartRuntime , physicalName = None , hardwareConfig = None , taskDict = {} , initTask = None ) self.deviceTwo = DeviceSingle( name = name2 , ipAdress = ipAdress2 , port = 2883 , dartRuntime = self.dartRuntime , physicalName = None , hardwareConfig = None , taskDict = {} , initTask = None ) 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 )
class TestDeviceAggregator(unittest.TestCase): def setUp(self): taskName = "task_one" maxSize = 3 parameterDict = { "device_one": {"param1": 5, "param2": 1} , "device_two": {"param1": 5, "param2": 1} } model = None hardwareRequirements = {} configFile = None self.task = SpecificDeviceTask( taskName , parameterDict , model , hardwareRequirements , "test" #filename , "test" #function , configFile ) server = "https://127.0.0.0.1:7777" client_key = "000" name1 = "device_one" name2 = "device_two" if TEST_MODE: ipAdress1 = "client1" ipAdress2 = "client2" else: ipAdress1 = "127.0.0.1" ipAdress2 = "127.0.0.1" self.dartRuntime = DartRuntime( server , client_key , TEST_MODE , ERROR_PROBABILITY ) self.deviceOne = DeviceSingle( name = name1 , ipAdress = ipAdress1 , port = 2883 , dartRuntime = self.dartRuntime , physicalName = None , hardwareConfig = None , taskDict = {} , initTask = None ) self.deviceTwo = DeviceSingle( name = name2 , ipAdress = ipAdress2 , port = 2883 , dartRuntime = self.dartRuntime , physicalName = None , hardwareConfig = None , taskDict = {} , initTask = None ) 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 ) def tearDown(self): pass def testNumberDeviceHolders(self): "Check if deviceHolders are sucessfully instantiated " maxSizeDeviceHolder = 1 maxNumDeviceHolder = 2 maxNumChildAggregators = 2 deviceAggregator = DeviceAggregator( [ self.deviceOne , self.deviceTwo ] , self.task , maxSizeDeviceHolder = maxSizeDeviceHolder , maxNumDeviceHolder = maxNumDeviceHolder , maxNumChildAggregators = maxNumChildAggregators , logServer = None ) self.assertTrue( len(deviceAggregator.deviceHolders) == 2 , msg = "wrong number of deviceHolder" ) def testNumberDeviceHoldersWithChildAggrators(self): "Check if deviceHolders are sucessfully instantiated for child aggregators" maxSizeDeviceHolder = 1 maxNumDeviceHolder = 1 maxNumChildAggregators = 2 deviceAggregator = DeviceAggregator( [ self.deviceOne , self.deviceTwo ] , self.task , maxSizeDeviceHolder = maxSizeDeviceHolder , maxNumDeviceHolder = maxNumDeviceHolder , maxNumChildAggregators = maxNumChildAggregators , logServer = None ) self.assertTrue( len(deviceAggregator.deviceHolders) == 0 , msg = "wrong number of deviceHolder" ) self.assertTrue( len(deviceAggregator.childAggregators) == 2 , msg = "wrong number of child aggregators" ) def testisTaskFinished(self): "Check if task is finished" maxSizeDeviceHolder = 1 maxNumDeviceHolder = 2 maxNumChildAggregators = 2 deviceAggregator = DeviceAggregator( [ self.deviceOne , self.deviceTwo ] , self.task , maxSizeDeviceHolder = maxSizeDeviceHolder , maxNumDeviceHolder = maxNumDeviceHolder , maxNumChildAggregators = maxNumChildAggregators , logServer = None ) self.assertTrue( deviceAggregator.isTaskFinished() == False , msg = "task shouldn't be finished" ) deviceAggregator.sendTask() self.assertTrue( deviceAggregator.isTaskFinished() == True , msg = "task should be finished" ) def testisTaskFinishedWithChildAggrators(self): "Check if task is finished with child aggregators" maxSizeDeviceHolder = 1 maxNumDeviceHolder = 1 maxNumChildAggregators = 2 deviceAggregator = DeviceAggregator( [ self.deviceOne , self.deviceTwo ] , self.task , maxSizeDeviceHolder = maxSizeDeviceHolder , maxNumDeviceHolder = maxNumDeviceHolder , maxNumChildAggregators = maxNumChildAggregators , logServer = None ) self.assertTrue( deviceAggregator.isTaskFinished() == False , msg = "task shouldn't be finished" ) deviceAggregator.sendTask() self.assertTrue( deviceAggregator.isTaskFinished() == True , msg = "task should be finished" ) def testRequestAggregation(self): "Get the result of the task" maxSizeDeviceHolder = 1 maxNumDeviceHolder = 2 maxNumChildAggregators = 2 deviceAggregator = DeviceAggregator( [ self.deviceOne , self.deviceTwo ] , self.task , maxSizeDeviceHolder = maxSizeDeviceHolder , maxNumDeviceHolder = maxNumDeviceHolder , maxNumChildAggregators = maxNumChildAggregators , logServer = None ) self.assertTrue( len(deviceAggregator.requestAggregation()) == 0 , msg = "there is no result atm available" ) deviceAggregator.sendTask() self.assertTrue( len(deviceAggregator.requestAggregation()) == 2 , msg = "each device should return a result" ) def testRequestAggregationWithChildAggrators(self): "Get the result of the task with child aggregators" maxSizeDeviceHolder = 1 maxNumDeviceHolder = 1 maxNumChildAggregators = 2 deviceAggregator = DeviceAggregator( [ self.deviceOne , self.deviceTwo ] , self.task , maxSizeDeviceHolder = maxSizeDeviceHolder , maxNumDeviceHolder = maxNumDeviceHolder , maxNumChildAggregators = maxNumChildAggregators , logServer = None ) self.assertTrue( len(deviceAggregator.requestAggregation()) == 0 , msg = "there is no result atm available" ) deviceAggregator.sendTask() self.assertTrue( len(deviceAggregator.requestAggregation()) == 2 , msg = "each device should return a result" )