Exemplo n.º 1
0
	def testUpdateRoundOne(self):
		factory = ServiceTaskFactory(self.conf,True)

		#Clear prev flag
		task = factory.build(0,0,42)
		task.start()

		#Round 1 should be ok, even if the prev_flag is invalid		
		task = factory.build(0,0,1)
		task.start()
		self.assertEquals(task.status(),ServiceTask.OK)
		factory.update(task,0,0,1)	
		self.assertEquals(task.status(),ServiceTask.OK)
Exemplo n.º 2
0
    def testUpdateRoundOne(self):
        factory = ServiceTaskFactory(self.conf, True)

        #Clear prev flag
        task = factory.build(0, 0, 42)
        task.start()

        #Round 1 should be ok, even if the prev_flag is invalid
        task = factory.build(0, 0, 1)
        task.start()
        self.assertEquals(task.status(), ServiceTask.OK)
        factory.update(task, 0, 0, 1)
        self.assertEquals(task.status(), ServiceTask.OK)
Exemplo n.º 3
0
	def testFlagUpdate(self):	
		factory = ServiceTaskFactory(self.conf,True)

		#Simulate the service being down - prev flag should be invalid
		task = factory.build(0,0,6)
		task.start()
		self.assert_(task.status() == ServiceTask.OK)
		factory.update(task,0,0,6)	
		self.assert_(task.status() == ServiceTask.INVALID_FLAG)

		#Simulate a round passing - prev flag should be valid	
		task = factory.build(0,0,7)
		task.start()
		factory.update(task,0,0,7)	
		self.assert_(task.status() == ServiceTask.OK)
Exemplo n.º 4
0
    def testFlagUpdate(self):
        factory = ServiceTaskFactory(self.conf, True)

        #Simulate the service being down - prev flag should be invalid
        task = factory.build(0, 0, 6)
        task.start()
        self.assert_(task.status() == ServiceTask.OK)
        factory.update(task, 0, 0, 6)
        self.assert_(task.status() == ServiceTask.INVALID_FLAG)

        #Simulate a round passing - prev flag should be valid
        task = factory.build(0, 0, 7)
        task.start()
        factory.update(task, 0, 0, 7)
        self.assert_(task.status() == ServiceTask.OK)
Exemplo n.º 5
0
	def testStorePersistance(self):
		factory = ServiceTaskFactory(self.conf,True)
		
		tasks = [
			factory.build(0,1,0),
			factory.build(1,1,0),
		]

		for task in tasks:
			task.start()
		
		factory.update(tasks[0],0,1,1)
		factory.update(tasks[1],1,1,1)

		task = factory.build(1,1,0)
		task.start()
		self.assert_(task.store() == "Worked")
Exemplo n.º 6
0
    def testStorePersistance(self):
        factory = ServiceTaskFactory(self.conf, True)

        tasks = [
            factory.build(0, 1, 0),
            factory.build(1, 1, 0),
        ]

        for task in tasks:
            task.start()

        factory.update(tasks[0], 0, 1, 1)
        factory.update(tasks[1], 1, 1, 1)

        task = factory.build(1, 1, 0)
        task.start()
        self.assert_(task.store() == "Worked")
Exemplo n.º 7
0
class ServiceTaskScheduler:

	def __init__(self,conf,init=False):
		self.conf = conf
		self.servicebot_conf = self.conf.getSection("SERVICE_BOT")
		self.factory = ServiceTaskFactory(conf,init)
		self.runner = ServiceTaskRunner(conf)
		self.runner.start()

	def execute(self,round):
		tasks = []	
		heap = []

		for teamId in range(0,self.conf.numTeams()):
			tasks.append([])
			for serviceId in range(0,self.servicebot_conf.numServices()):
				task = self.factory.build(teamId,serviceId,round)
				tasks[teamId].append(task)

		round_length = random.randint(
			self.servicebot_conf.getRoundLengthMin(),
			self.servicebot_conf.getRoundLengthMax())

		for teamId in range(0,self.conf.numTeams()):
			for serviceId in range(0,self.servicebot_conf.numServices()):
				timeout = self.servicebot_conf.getServiceInfoById(serviceId).timeout
				wait_max = round_length - timeout
				wait = random.randint(0,wait_max)
				heapq.heappush(heap,(wait,tasks[teamId][serviceId],teamId,serviceId))

		total = 0
		while(len(heap) > 0):
			wait,task,teamId,serviceId = heapq.heappop(heap)
			if(total == wait):
				self.runner.insert(task,teamId,serviceId)
			else:
				time.sleep(wait-total)
				total = wait
				self.runner.insert(task,teamId,serviceId)
				
		time.sleep(round_length - (total+1))
		
		for teamId in range(0,self.conf.numTeams()):
			for serviceId in range(0,self.servicebot_conf.numServices()):
				task = tasks[teamId][serviceId]
				self.factory.update(task,teamId,serviceId,round)
	
		return tasks

	def terminateAtRoundEnd(self):
		self.runner.terminateOnEmpty()

	def terminate(self):
		self.runner.terminate()
Exemplo n.º 8
0
	def testSave(self):
		factory = ServiceTaskFactory(self.conf,True)
		
		tasks = [
			factory.build(0,1,1),
			factory.build(1,1,1),
		]

		for task in tasks:
			task.start()

		factory.update(tasks[0],0,1,0)
		factory.update(tasks[1],1,1,0)

		#Test a "crash recovery" by building a new factory
		factory.save()
		new_factory = ServiceTaskFactory(self.conf,False)
		
		task = new_factory.build(1,1,0)
		task.start()
		self.assert_(task.store() == "Worked")
Exemplo n.º 9
0
    def testSave(self):
        factory = ServiceTaskFactory(self.conf, True)

        tasks = [
            factory.build(0, 1, 1),
            factory.build(1, 1, 1),
        ]

        for task in tasks:
            task.start()

        factory.update(tasks[0], 0, 1, 0)
        factory.update(tasks[1], 1, 1, 0)

        #Test a "crash recovery" by building a new factory
        factory.save()
        new_factory = ServiceTaskFactory(self.conf, False)

        task = new_factory.build(1, 1, 0)
        task.start()
        self.assert_(task.store() == "Worked")
Exemplo n.º 10
0
	def testBuildSimple(self):
		factory = ServiceTaskFactory(self.conf,True)
		task = factory.build(0,0,0)
		task.start()
		self.assert_(task.status() == ServiceTask.OK)
Exemplo n.º 11
0
 def testBuildSimple(self):
     factory = ServiceTaskFactory(self.conf, True)
     task = factory.build(0, 0, 0)
     task.start()
     self.assert_(task.status() == ServiceTask.OK)