示例#1
0
	def testThreadSafety(self):
		fc = FlagCollector()
		p1 = FlagCollectorPopulator(fc,10000,10)
		p2 = FlagCollectorPopulator(fc,10000,20)
		p3 = FlagCollectorPopulator(fc,10000,30)
		p4 = FlagCollectorPopulator(fc,10000,30)
		p5 = FlagCollectorPopulator(fc,10000,30)
		
		p1.start()
		p2.start()
		p3.start()
		p4.start()
		p5.start()

		total = 0
		for i in xrange(1000):
			total += len(fc.collect())
			time.sleep(1.0/1000.0)

		p1.join()
		p2.join()
		p3.join()
		p4.join()
		p5.join()

		total += len(fc.collect())		
		self.assertEquals(total,50000)
示例#2
0
    def testThreadSafety(self):
        fc = FlagCollector()
        p1 = FlagCollectorPopulator(fc, 10000, 10)
        p2 = FlagCollectorPopulator(fc, 10000, 20)
        p3 = FlagCollectorPopulator(fc, 10000, 30)
        p4 = FlagCollectorPopulator(fc, 10000, 30)
        p5 = FlagCollectorPopulator(fc, 10000, 30)

        p1.start()
        p2.start()
        p3.start()
        p4.start()
        p5.start()

        total = 0
        for i in xrange(1000):
            total += len(fc.collect())
            time.sleep(1.0 / 1000.0)

        p1.join()
        p2.join()
        p3.join()
        p4.join()
        p5.join()

        total += len(fc.collect())
        self.assertEquals(total, 50000)
示例#3
0
	def testBasicUsage(self):
		fc = FlagCollector()
		f1 = Flag(0,0,0,time.time())
		f2 = Flag(0,1,0,time.time())
		fc.enque(f1)
		fc.enque(f2)

		flags = fc.collect()
		self.assert_(len(flags) == 2)

		flags = fc.collect()
		self.assert_(len(flags) == 0)
示例#4
0
    def testBasicUsage(self):
        fc = FlagCollector()
        f1 = Flag(0, 0, 0, time.time())
        f2 = Flag(0, 1, 0, time.time())
        fc.enque(f1)
        fc.enque(f2)

        flags = fc.collect()
        self.assert_(len(flags) == 2)

        flags = fc.collect()
        self.assert_(len(flags) == 0)
示例#5
0
	def __init__(self,port,conf):
		global FILE_PATH
		global TEAM_DATA
		global FLAG_MANAGER

		HTTPServer.__init__(self,('',port),SubmitHttpHandler)
		
		#will likely move where these shared objects are created
		flag_conf = conf.getSection("FLAG")
		setSharedValidator(FlagValidator(len(conf.teams),flag_conf.duration))
		setSharedCollector(FlagCollector())

		#Get the correct *relative* path from wherever it is being executed
		FILE_PATH = os.path.relpath(os.path.dirname(__file__),sys.path[0])

		for team in conf.teams:
			assert(team.id == len(TEAM_DATA))
			cidr_ip,cidr_mask_txt = team.cidr.split("/")
			team_ip = extractNetworkValue(team.host,int(cidr_mask_txt))
			TEAM_DATA.append((team.id,team_ip,int(cidr_mask_txt)))

		FLAG_MANAGER = conf.buildFlagManager()