Example #1
0
    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)
Example #2
0
    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))
Example #3
0
    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)
Example #4
0
    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)