def testCreate(self): addr = 'foo' port = 678 client = MockRPCClient(addr, port, None) name = 'xyz' daqId = 515 MockMoni.setRPCClient(name, daqId, client) moniPath = 'x' appender = MockAppender('log') appender.addExpectedExact( ('Creating moni output file %s/%s-%d.moni' + ' (remote is %s:%d)') % (moniPath, name, daqId, addr, port)) compId = 1 MockMoni(DAQLog(appender), moniPath, (compId, ), { compId: name, }, { compId: daqId, }, { compId: addr, }, { compId: port, }) appender.checkStatus(10)
def testCreateWatchdog(self): idList = [] compNameDict = {} compIdDict = {} addrDict = {} portDict = {} dataDict = {} nextId = 1 for comp in ('stringHub#0', 'stringHub#10', 'inIceTrigger#0', 'simpleTrigger#0', 'iceTopTrigger#0', 'amandaTrigger#0', 'globalTrigger#0', 'eventBuilder#0', 'secondaryBuilders#0'): pound = comp.find('#') compName = comp[:pound] compId = int(comp[pound + 1:]) mbeans = self.__buildBeans(TestRunWatchdog.COMP_BEANS, comp) if compName == 'eventBuilder': self.__setStatic(mbeans, 'dispatch', 'backEnd', 'NumEventsSent') client = MockRPCClient(mbeans) id = nextId nextId += 1 idList.append(id) compNameDict[id] = compName compIdDict[id] = compId addrDict[id] = 'localhost' portDict[id] = 100 + id dataDict[id] = MockData(id, compName, compId, None, None, client) appender = MockAppender('log') wd = MockWatchdog(DAQLog(appender), 60.0, idList, compNameDict, compIdDict, addrDict, portDict, dataDict) self.failIf(wd.inProgress(), 'Watchdog should not be in progress') self.failIf(wd.isDone(), 'Watchdog should not be done') self.failIf(wd.isHealthy(), 'Watchdog should not be healthy') self.failIf(wd.caughtError(), 'Watchdog should not have error') appender.checkStatus(10) self.__runThread(wd, appender) for id in dataDict: dataDict[id].updateMBeanData() appender.addExpectedRegexp(r'\*\* Run watchdog reports stagnant' + r' components:.*') self.__runThread(wd, appender)
def testSingleBean(self): mbeans = {'abean': {'a': 1, 'b': 2}} addr = 'foo' port = 678 client = MockRPCClient(addr, port, mbeans) name = 'xyz' daqId = 515 MockMoni.setRPCClient(name, daqId, client) moniPath = 'x' appender = MockAppender('log') appender.addExpectedExact( ('Creating moni output file %s/%s-%d.moni' + ' (remote is %s)') % (moniPath, name, daqId, str(client))) compId = 1 moni = MockMoni(DAQLog(appender), moniPath, (compId, ), { compId: name, }, { compId: daqId, }, { compId: addr, }, { compId: port, }) appender.checkStatus(10) badId = compId + 1 badBean = 'xxx' badFld = 'yyy' try: moni.getSingleBeanField(badId, badBean, badFld) self.fail('Should have failed due to bogus ID') except BeanFieldNotFoundException, e: self.assertEquals(str(e), 'Component %d not found' % badId, 'Unexpected error: ' + str(e))
def testCreateWatchdogBadComp(self): id = 43 name = 'foo' compId = 83 idList = [ id, ] compNameDict = {id: name} compIdDict = {id: compId} addrDict = {id: 'xxx'} portDict = {id: 543} dataDict = {id: None} appender = MockAppender('log') appender.addExpectedExact("Couldn't create watcher for unknown" + ' component #%d type %s#%d' % (id, name, compId)) wd = MockWatchdog(DAQLog(appender), None, idList, compNameDict, compIdDict, addrDict, portDict, dataDict)
def testCreateWatchdogBadBean(self): id = 43 name = 'eventBuilder' compId = 83 comp = '%s#%d' % (name, compId) mbeans = self.__buildBeans({name: []}, comp) idList = [ id, ] compNameDict = {id: name} compIdDict = {id: compId} addrDict = {id: 'xxx'} portDict = {id: 543} dataDict = {id: None} appender = MockAppender('log') appender.addExpectedRegexp(r"Couldn't create watcher for component" + r' #%d type %s#%d: .*' % (id, name, compId)) wd = MockWatchdog(DAQLog(appender), None, idList, compNameDict, compIdDict, addrDict, portDict, dataDict)
def testDoMoni(self): mbeans = {'abean': {'a': 1, 'b': 2}} addr = 'foo' port = 678 client = MockRPCClient(addr, port, mbeans) name = 'xyz' daqId = 515 MockMoni.setRPCClient(name, daqId, client) moniPath = 'x' appender = MockAppender('log') appender.addExpectedExact( ('Creating moni output file %s/%s-%d.moni' + ' (remote is %s)') % (moniPath, name, daqId, str(client))) compId = 1 moni = MockMoni(DAQLog(appender), moniPath, (compId, ), { compId: name, }, { compId: daqId, }, { compId: addr, }, { compId: port, }) appender.checkStatus(10) moni.doMoni() tries = 0 while moni.isActive() and tries < 10: time.sleep(0.1) tries += 1 md = MockMoni.getMockData(name, daqId) lines = md.getOutputLines() self.failUnless(len(lines) > 0, "doMoni didn't print anything") self.failUnless(len(lines[0]) > 0, "doMoni printed a blank line") self.assertEquals(':', lines[0][-1], 'No colon at end of "%s"' % lines[0]) bean = mbeans.keys()[0] prefix = lines[0][0:len(bean) + 2] self.assertEquals( bean + ': ', prefix, 'Expected "%s: " at front of "%s"' % (bean, lines[0])) expLines = self.__buildLines(mbeans, lines[0][len(prefix):-1]) self.assertEquals( len(expLines), len(lines), 'Expected %d lines, not %s' % (len(expLines), len(lines))) for i in range(len(expLines)): self.assertEquals( expLines[i], lines[i], 'Expected line#%d "%s", not "%s"' % (i, expLines[i], lines[i])) appender.checkStatus(10)