Пример #1
0
    def testApiStatisticAVG(self):
        time.clock()
        row_id = u'*****@*****.**'
        period = 5
        time_from = 1332833464
        time_to = 0
        cf_str = u'cpu'
        scf_str = u'total'
        statistic = STATISTIC.AVERAGE

        m = self.mox
        apiServer = api_server.ApiServer()
        m.StubOutWithMock(apiServer, 'get_data')
        apiServer.get_data(row_id, cf_str, scf_str, \
                time_from, time_to).AndReturn(ApiGetDataMox())
        self.mox.ReplayAll()
        statistic = STATISTIC.AVERAGE
        (rs, count, _) = apiServer.statistic(row_id, cf_str, scf_str, \
                statistic, period, \
                time_from, time_to)
        self.assertEqual(count, 1)
        self.mox.VerifyAll()

        print "%d AVERAGE results, spend %f seconds" % (count, time.clock())
        print "api_statistics AVERAGE test \t\t\t[\033[1;33mOK\033[0m]"
        print '-' * 60
Пример #2
0
    def testParamTypeCheck(self):
        row_id = None
        cf_str = None
        scf_str = None
        period = None
        statistic = None
        apiServer = api_server.ApiServer()
        (rs1, count, _) = apiServer.statistic(None,
                                              None,
                                              None,
                                              None,
                                              period=5,
                                              time_from=0,
                                              time_to=0)
        rs2, count, _ = apiServer.get_by_key(None,
                                             cf_str,
                                             scf_str,
                                             limit=20000)
        rs3, count, _ = apiServer.get_by_instance_id(row_id, cf_str)
        rs4, count, _ = apiServer.get_data(row_id,
                                           cf_str,
                                           scf_str,
                                           time_from=0,
                                           time_to=0)
        rs5 = apiServer.get_instances_list(None)
        rs6 = apiServer.analyize_data(None, period, statistic)
        assert (rs1 is None)
        assert (rs2 is None)
        assert (rs3 is None)
        assert (rs4 is None)
        assert (rs5 is None)
        assert (rs6 is None)

        print "Param type test \t\t\t[\033[1;33mOK\033[0m]"
Пример #3
0
    def testApiBuf(self):
        time.clock()
        row_id = u'*****@*****.**'
        period = 5
        time_from = 1332833464
        time_to = 0
        cf_str = u'cpu'
        scf_str = u'total'
        statistic = 'avg'

        apiServer = api_server.ApiServer()
        self.mox.StubOutWithMock(apiServer, 'get_data')
        apiServer.get_data(row_id, cf_str, scf_str, \
                time_from, time_to).AndReturn(ApiGetDataMox())
        self.mox.ReplayAll()
        statistic = STATISTIC.AVERAGE
        (rs, count, _) = apiServer.statistic(row_id, cf_str, scf_str, \
                statistic, period, \
                time_from, time_to)
        (rs, count, _) = apiServer.statistic(row_id, cf_str, scf_str, \
                statistic, period, \
                time_from, time_to)
        self.assertEqual(count, 1)
        self.mox.VerifyAll()

        self.assertEqual(apiServer.hit_rate, 1)
Пример #4
0
def testApiGetdataBuffer():
    time.clock()
    row_id = u'*****@*****.**'
    time_from = 1332815400
    time_to = 0
    scf_str = u'total'
    cf_str = u'cpu'

    apiServer = api_server.ApiServer()
    rs, count, _ = apiServer.get_data(row_id, cf_str, scf_str, time_from,
                                      time_to)
    print "%d results, spend %f seconds" % (count, time.clock())
    print "ApiGetdataBuf test \t\t\t[\033[1;33mOK\033[0m]"

    rs, count, _ = apiServer.get_data(row_id, cf_str, scf_str, time_from,
                                      time_to)
    print "%d results, spend %f seconds" % (count, time.clock())
    print "ApiGetdataBuf test \t\t\t[\033[1;33mOK\033[0m]"
    print '-' * 60
Пример #5
0
    def testApiGetdata(self):
        time.clock()
        row_id = '*****@*****.**'
        time_from = 1332815400
        time_to = 0
        scf_str = 'total'
        cf_str = 'cpu'
        apiServer = api_server.ApiServer()

        self.mox.StubOutWithMock(apiServer, 'get_data')
        apiServer.get_data(row_id, cf_str, scf_str, \
                time_from, time_to).AndReturn(ApiGetDataMox())
        self.mox.ReplayAll()

        rs, count, _ = apiServer.get_data(row_id, cf_str, scf_str, time_from,
                                          time_to)
        self.mox.VerifyAll()
        print "%d results, spend %f seconds" % (count, time.clock())
        print "ApiGetdata test \t\t\t[\033[1;33mOK\033[0m]"
        print '-' * 60