def instantiateAggregator(self, task): """! Instantiate DeviceAggregator. Check in create_needed_childAggregators if the aggregator has enough capacity for the amount of Device, if not create childAggregators recursively. Add task and devices to aggregator @param numDevices amount of devices """ choosen_devices = self.getDevicesForAggregator(task) aggregator = DeviceAggregator( devices=choosen_devices, task=task, maxSizeDeviceHolder=self._maxSizeDeviceHolder, maxNumDeviceHolder=self._maxNumDeviceHolder, maxNumChildAggregators=self._maxNumChildAggregators, logServer=None) self.logger.log().info("max # devices in aggregator: " + str(aggregator.get_max_number_devices())) self.addAggregator(aggregator) return aggregator
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 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" )
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" )