Exemplo n.º 1
0
 def test_generate_enum_payload(self):
   self.tm.create_all_metrics(1)
   thread = ingestenum.EnumIngestThread(0)
   payload = json.loads(thread.generate_payload(1, [[2, 1], [2, 2]]))
   valid_payload = [{u'timestamp': 1,
                     u'tenantId': u'2',
                     u'enums': [{u'value': u'e_g_1_0', u'name': utils.generate_enum_metric_name(1)}]},
                    {u'timestamp': 1,
                     u'tenantId': u'2',
                     u'enums': [{u'value': u'e_g_2_0', u'name': utils.generate_enum_metric_name(2)}]}
                   ]
   self.assertEqual(payload, valid_payload)
Exemplo n.º 2
0
    def test_ingest_enum_make_request(self):
        global sleep_time
        thread = ingestenum.EnumIngestThread(0)
        thread.slice = [[[2, 0], [2, 1]]]
        thread.position = 0
        thread.finish_time = 10000
        valid_payload = [{
            'tenantId':
            '2',
            'timestamp':
            1000,
            'enums': [{
                'value': 'e_g_0_0',
                'name': utils.generate_enum_metric_name(0)
            }]
        }, {
            'tenantId':
            '2',
            'timestamp':
            1000,
            'enums': [{
                'value': 'e_g_1_0',
                'name': utils.generate_enum_metric_name(1)
            }]
        }]

        url, payload = thread.make_request(pp)
        # confirm request generates proper URL and payload
        self.assertEqual(
            url,
            'http://qe01.metrics-ingest.api.rackspacecloud.com/v2.0/tenantId/ingest/aggregated/multi'
        )
        self.assertEqual(eval(payload), valid_payload)

        # confirm request increments position if not at end of report interval
        self.assertEqual(thread.position, 1)
        self.assertEqual(thread.finish_time, 10000)
        thread.position = 2
        thread.make_request(pp)
        # confirm request resets position at end of report interval
        self.assertEqual(sleep_time, 9000)
        self.assertEqual(thread.position, 1)
        self.assertEqual(thread.finish_time, 16000)
Exemplo n.º 3
0
  def test_ingest_enum_make_request(self):
      global sleep_time
      thread = ingestenum.EnumIngestThread(0)
      thread.slice = [[[2, 0], [2, 1]]]
      thread.position = 0
      thread.finish_time = 10000
      valid_payload = [{'tenantId': '2', 'timestamp': 1000, 'enums': [{'value': 'e_g_0_0', 'name': utils.generate_enum_metric_name(0)}]}, {'tenantId': '2', 'timestamp': 1000, 'enums': [{'value': 'e_g_1_0', 'name': utils.generate_enum_metric_name(1)}]}]

      url, payload = thread.make_request(pp)
      #confirm request generates proper URL and payload
      self.assertEqual(url,
                       'http://qe01.metrics-ingest.api.rackspacecloud.com/v2.0/tenantId/ingest/aggregated/multi')
      self.assertEqual(eval(payload), valid_payload)

      #confirm request increments position if not at end of report interval
      self.assertEqual(thread.position, 1)
      self.assertEqual(thread.finish_time, 10000)
      thread.position = 2
      thread.make_request(pp)
      #confirm request resets position at end of report interval
      self.assertEqual(sleep_time, 9000)
      self.assertEqual(thread.position, 1)
      self.assertEqual(thread.finish_time, 16000)