def testPolicy_PERIODIC(self): status = Status.get_status_holder("UnitTest") status.reset() reporter = TestPeriodicStatusReporter("Periodic, 0.4sec", 0.4) status.add_reporter(reporter) i = status.create_status_element("TestInteger") for x in range(0, 5): i.set_value(x) self.assertEquals(reporter.last_value, None) # Not updated yet time.sleep(1) assert reporter.last_value == 4 for x in range(5, 9): self.assertEquals(reporter.last_value, 4) # Not updated yet i.set_value(x) time.sleep(1) self.assertEquals(reporter.last_value, 8) # Clean up status.remove_status_element(i) reporter.stop()
def testInt(self): status = Status.get_status_holder("UnitTest") status.reset() self.assertNotEqual(status, None) i = status.create_status_element("TestInteger") self.assertEquals(i.get_name(), "TestInteger") x = status.get_status_element("TestInteger") self.assertEquals(x, i) # Test set and get values for j in range(0,10): i.set_value(j) self.assertEquals(i.get_value(), j) # Clean up status.remove_status_element(i) try: status.get_status_element("TestInteger") self.fail("Remove does not remove status element 'TestInteger'") except Status.NoSuchElementException, e: # Expected pass
def testBasic(self): status = Status.get_status_holder("UnitTest") status.reset() self.assertNotEqual(status, None) self.assertEquals(status.get_name(), "UnitTest")
def testInvalid(self): status = Status.get_status_holder("UnitTest") status.reset() try: i = status.create_status_element(None) self.fail("Does not throw exception with no name") except AssertionError, e: pass
def report_periodic_vod_stats(self,playing_dslist): #print >>sys.stderr, time.asctime(),'-', "VOD Stats" self.counter += 1 if self.counter%self.interval == 0: event_reporter = Status.get_status_holder("LivingLab") if event_reporter is not None: for ds in playing_dslist: dw = ds.get_download() b64_infohash = b64encode(dw.get_def().get_infohash()) vod_stats = ds.get_vod_stats() #if vod_stats_has_key("prebuf"): event_reporter.add_event(b64_infohash, "prebufp:%d" % vod_stats['prebuf']) # prebuffering time that was needed if vod_stats.has_key("stall"): event_reporter.create_and_add_event("stall", [b64_infohash, vod_stats['stall']]) # time the player stalled if vod_stats.has_key("late"): event_reporter.create_and_add_event("late", [b64_infohash, vod_stats['late']]) # number of pieces arrived after they were due if vod_stats.has_key("dropped"): event_reporter.create_and_add_event("dropped", [b64_infohash, vod_stats['dropped']]) # number of pieces lost if vod_stats.has_key("pos"): event_reporter.create_and_add_event("pos", [b64_infohash, vod_stats['pos']]) # playback position
def testPolicy_ON_CHANGE(self): status = Status.get_status_holder("UnitTest") status.reset() reporter = TestOnChangeStatusReporter("On change") status.add_reporter(reporter) i = status.create_status_element("TestInteger") for x in range(0, 10): i.set_value(x) if x != reporter.value: self.fail("Callback does not work for ON_CHANGE policy") if reporter.name != "TestInteger": self.fail("On_Change callback get's the wrong parameter, got '%s', expected 'TestInteger'"%reporter.name) # Clean up status.remove_status_element(i)
def test_LLReporter_event(self): status = Status.get_status_holder("UnitTest") status.reset() reporter = TestLivingLabPeriodicReporter("Living lab test reporter", 1.0) status.add_reporter(reporter) event = status.create_event("SomeEvent") event.add_value("123") event.add_value("456") status.add_event(event) reporter.wait_for_post(5.0) reporter.stop() time.sleep(1) self.assertEquals(len(reporter.get_errors()), 0) status.remove_event(event)
def test_LLReporter_element(self): status = Status.get_status_holder("UnitTest") status.reset() reporter = TestLivingLabPeriodicReporter("Living lab test reporter", 1.0) status.add_reporter(reporter) i = status.create_status_element("TestInteger") i.set_value(1233) b = status.create_status_element("Binary") b.set_value("".join([chr(n) for n in range(0, 255)])) reporter.wait_for_post(5.0) reporter.stop() time.sleep(1) self.assertEquals(len(reporter.get_errors()), 0) status.remove_status_element(i) status.remove_status_element(b)
def run_bgapp(appname,appversion,i2iport,sessport,httpport,ws_serverport,bt_port, params = None,killonidle=False): """ Set sys.argv[1] to "--nopause" to inform the Core that the player doesn't support VODEVENT_PAUSE, e.g. the SwarmTransport. """ try: if params is None: params = [""] if len(sys.argv) > 1: params = sys.argv[1:] global KILLONIDLE KILLONIDLE = killonidle """ # Create single instance semaphore # Arno: On Linux and wxPython-2.8.1.1 the SingleInstanceChecker appears # to mess up stderr, i.e., I get IOErrors when writing to it via print_exc() # if sys.platform != 'linux2': single_instance_checker = wx.SingleInstanceChecker(appname+"-"+ wx.GetUserId()) else: single_instance_checker = LinuxSingleInstanceChecker(appname) """ # Arno, 2010-03-05: This is a vital print that must not be removed, otherwise # the program will just say "15:29:02: Deleted stale lock file '/home/arno/SwarmPlugin-arno'" # and exit after a restart of the instance :-( # print >>sys.stderr,time.asctime(),'-', "bg: Test if already running" single_instance_checker = wx.SingleInstanceChecker(appname+"-"+ wx.GetUserId()) if single_instance_checker.IsAnotherRunning(): print >>sys.stderr,time.asctime(),'-', "bg: Already running, exit" os._exit(0) arg0 = sys.argv[0].lower() if arg0.endswith('.exe'): installdir = os.path.abspath(os.path.dirname(sys.argv[0])) else: installdir = os.getcwd() # Added for extract base directory result = re.finditer(ur"(.+)/BaseLib/Plugin", installdir) for match in result: if(match.groups()[0]): installdir = match.groups()[0] logdir = get_appstate_dir() logdir = os.path.join(logdir, '.SwarmVideo', 'Log') if not os.path.isdir(logdir): os.makedirs(logdir) # Launch first single instance app = BackgroundApp(logdir, appname, appversion, params, single_instance_checker, installdir, i2iport, sessport, httpport, ws_serverport, bt_port) s = app.s # Enable P2P-Next ULANC logging. if PHONEHOME: status = Status.get_status_holder("LivingLab") id = encodestring(s.get_permid()).replace("\n","") reporter = LivingLabReporter.LivingLabPeriodicReporter("Living lab CS reporter", 300, id) # Report every 5 minutes status.add_reporter(reporter) app.MainLoop() if PHONEHOME: reporter.stop() print >>sys.stderr,time.asctime(),'-', "Sleeping seconds to let other threads finish" time.sleep(2) if not ALLOW_MULTIPLE: del single_instance_checker finally: app.q.put('stop') print >>sys.stderr,time.asctime(),'-', "bg: Sending stopping signal to BtHTTPServer." app.p.join() if os.path.exists(STOP_FILE): os.remove(STOP_FILE) print >>sys.stderr,time.asctime(),'-', "bg: Stop file "+STOP_FILE+" deleted." # Ultimate catchall for hanging popen2's and what not os._exit(0)
def run_bgapp(appname,appversion,i2iport,sessport,httpport, params = None,killonidle=False): """ Set sys.argv[1] to "--nopause" to inform the Core that the player doesn't support VODEVENT_PAUSE, e.g. the SwarmTransport. """ if params is None: params = [""] if len(sys.argv) > 1: params = sys.argv[1:] global KILLONIDLE KILLONIDLE = killonidle """ # Create single instance semaphore # Arno: On Linux and wxPython-2.8.1.1 the SingleInstanceChecker appears # to mess up stderr, i.e., I get IOErrors when writing to it via print_exc() # if sys.platform != 'linux2': single_instance_checker = wx.SingleInstanceChecker(appname+"-"+ wx.GetUserId()) else: single_instance_checker = LinuxSingleInstanceChecker(appname) """ # Arno, 2010-03-05: This is a vital print that must not be removed, otherwise # the program will just say "15:29:02: Deleted stale lock file '/home/arno/SwarmPlugin-arno'" # and exit after a restart of the instance :-( # print >>sys.stderr,"bg: Test if already running" single_instance_checker = wx.SingleInstanceChecker(appname+"-"+ wx.GetUserId()) if single_instance_checker.IsAnotherRunning(): print >>sys.stderr,"bg: Already running, exit" os._exit(0) arg0 = sys.argv[0].lower() if arg0.endswith('.exe'): installdir = os.path.abspath(os.path.dirname(sys.argv[0])) else: installdir = os.getcwd() # Launch first single instance app = BackgroundApp(0, appname, appversion, params, single_instance_checker, installdir, i2iport, sessport, httpport) s = app.s # Enable P2P-Next ULANC logging. if PHONEHOME: status = Status.get_status_holder("LivingLab") id = encodestring(s.get_permid()).replace("\n","") reporter = LivingLabReporter.LivingLabPeriodicReporter("Living lab CS reporter", 300, id) # Report every 5 minutes status.add_reporter(reporter) app.MainLoop() if PHONEHOME: reporter.stop() print >>sys.stderr,"Sleeping seconds to let other threads finish" time.sleep(2) if not ALLOW_MULTIPLE: del single_instance_checker # Ultimate catchall for hanging popen2's and what not os._exit(0)