class TestIngest(unittest.TestCase): def setUp(self) -> None: self.env = simpy.Environment() self.cluster = Cluster(env=self.env, spec=CLUSTER_CONFIG) self.observation = Observation( 'planner_observation', OBS_START_TME, OBS_DURATION, OBS_DEMAND, OBS_WORKFLOW, type=None, data_rate=None ) def testClusterCheckIngest(self): retval = self.cluster.check_ingest_capacity(pipeline_demand=5) self.assertTrue(retval) def testClusterProvisionIngest(self): duration = self.observation.duration pipeline_demand = 5 self.env.process(self.cluster.run()) peek = self.env.peek() self.env.process(self.cluster.provision_ingest_resources( pipeline_demand, duration) ) self.env.run(until=1) self.assertEqual(1, self.env.now) # self.process(self.run_ingest(duration,pipeline_demand)) # for task in self.cluster.running_tasks: # self.assertEqual(TaskStatus.RUNNING, task.task_status) self.assertEqual(5, len(self.cluster.available_resources)) self.assertEqual(5, len(self.cluster.running_tasks)) self.env.run(until=10) self.assertEqual(5, len(self.cluster.available_resources)) self.env.run(until=20) self.assertEqual(10,len(self.cluster.available_resources)) self.assertEqual(20,self.env.now) def run_ingest(self, duration,demand): retval = self.cluster.provision_ingest_resources( demand, duration ) for task in self.cluster.running_tasks: self.assertEqual(TaskStatus.SCHEDULED, task.task_status)
class TestIngest(unittest.TestCase): def setUp(self) -> None: """ Setup a cluster and a simulation environment to test ingest pipelines """ self.env = simpy.Environment() config = Config(CONFIG) self.cluster = Cluster(env=self.env, config=config) self.telescope = Telescope(self.env, config, planner=None, scheduler=None) self.observation = self.telescope.observations[0] def testClusterCheckIngest(self): """ Need to determine that the cluster is able to deal with the pipeline requirement in addition, need to check that we are not going over the maximum number of resources that can be feasibly allocated to ingest. Returns ------- """ max_ingest = 5 retval = self.cluster.check_ingest_capacity(5, max_ingest) self.assertTrue(retval) def testClusterProvisionIngest(self): """ Notes: When we run this test, we have the simulation run 'until time 10'. AS Far as the simulation is concerned, we this occurs 'before' 10 seconds in simtime; however, the rest of the simulation is operating AT time = 10, which is when the tasks are "Due" to finish. Here we are running the tasks for "1 -timestep less" than is necessary, but within the simulation time this allows us to run "on time". I.e. at time = 10 (in the simulation), there _will_ be 10 resources available, because it's the time period in which all ingest tasks will finish. However, in real terms, these tasks technically finished one timestep earlier. Returns ------- """ pipeline_demand = 5 self.env.process(self.cluster.run()) peek = self.env.peek() self.env.process( self.cluster.provision_ingest_resources(pipeline_demand, self.observation)) self.env.run(until=1) self.assertEqual(1, self.env.now) self.assertEqual(5, len(self.cluster._resources['available'])) self.assertEqual(5, len(self.cluster._tasks['running'])) self.assertEqual(5, len(self.cluster._resources['available'])) self.env.run(until=11) self.assertEqual(10, len(self.cluster._resources['available'])) def test_ingest_capacity_check(self): """ Given a pipeline demand that is too great, return 'false' to ensure that we do not attempt to run observations. """ pipeline_demand = 11 max_ingest = 5 self.assertFalse( self.cluster.check_ingest_capacity(pipeline_demand, max_ingest)) def test_ingest_demand_exceeds_cluster_capacity_runtime(self): """ If we have a pipeline that requests too many ingest pipelines then we need to reject its observation. If - for some unknown reasons - we do not call this check, make sure the simulation fails at runtime. Returns ------- """ pipeline_demand = 11 self.env.process( self.cluster.provision_ingest_resources(pipeline_demand, self.observation)) self.assertRaises(RuntimeError, self.env.run, until=1)
class TestBatchSchedulerAllocation(unittest.TestCase): def setUp(self): self.algorithm = BatchProcessing self.env = simpy.Environment() config = Config(CONFIG) self.cluster = Cluster(self.env, config=config) self.buffer = Buffer(self.env, self.cluster, config) self.scheduler = Scheduler(self.env, self.buffer, self.cluster, DynamicAlgorithmFromPlan()) self.algorithm = BatchProcessing() self.model = BatchPlanning('batch') self.planner = Planner( self.env, 'heft', self.cluster, self.model, ) self.telescope = Telescope(self.env, config, self.planner, self.scheduler) def test_resource_provision(self): """ Given a max_resource_split of 2, and total machines of 10, we should provision a maximum of 5 machines within the cluster ( max_resource_split being the number of parallel provision ings we can make). Returns ------- """ self.assertEqual(10, len(self.cluster.get_available_resources())) def test_max_resource_provision(self): obs = self.telescope.observations[0] self.env.process(self.cluster.provision_ingest_resources(5, obs)) self.env.run(until=1) self.assertEqual(5, len(self.cluster.get_available_resources())) self.assertEqual(5, self.algorithm._max_resource_provision(self.cluster)) # TODO The algorithm must provision resources if they are not already # provisioned. plan = self.planner.run(obs, self.buffer, self.telescope.max_ingest) self.algorithm._provision_resources(self.cluster, plan) self.assertEqual(5, len(self.cluster.get_idle_resources(obs.name))) self.assertEqual(0, self.algorithm._max_resource_provision(self.cluster)) # self.planner.run(obs, ) def test_algorithm_allocation(self): obs = self.telescope.observations[0] obs.plan = self.planner.run(obs, self.buffer, self.telescope.max_ingest) # Replicate the Scheduler allocate_task() methods existing_schedule = {} existing_schedule, status = self.algorithm.run(self.cluster, self.env.now, obs.plan, existing_schedule) self.assertTrue(obs.plan.tasks[0] in existing_schedule) def test_observation_queue(self): """