def test_gen_queue_number(self):
     # tuples of (input, expected).
     # 0x3fc00000 is the priority mask.
     # pylint: disable=bad-whitespace
     data = [
         # Priorities.
         ((1, '1970-01-01 00:00:00.000', 0), (0x92cc0300, 75)),
         ((1, '1970-01-01 00:00:00.000', 1), (0x930c0300, 76)),
         ((1, '1970-01-01 00:00:00.000', 2), (0x934c0300, 77)),
         ((1, '1970-01-01 00:00:00.000', 3), (0x938c0300, 78)),
         ((1, '1970-01-01 00:00:00.000', 255), (0xd28c0300, 330)),
         # Largest hash.
         ((0xffffffff, '1970-01-01 00:00:00.000', 255), (0x7fffffffd28c0300,
                                                         330)),
         # Time resolution.
         ((1, '1970-01-01 00:00:00.040', 0), (0x92cc0300, 75)),
         ((1, '1970-01-01 00:00:00.050', 0), (0x92cc0300, 75)),
         ((1, '1970-01-01 00:00:00.100', 0), (0x92cc02ff, 75)),
         ((1, '1970-01-01 00:00:00.900', 0), (0x92cc02f7, 75)),
         ((1, '1970-01-01 00:00:01.000', 0), (0x92cc02f6, 75)),  # 10
         ((1, '2010-01-02 03:04:05.060', 0), (0x92bd248d, 74)),
         ((1, '2010-01-02 03:04:05.060', 1), (0x92fd248d, 75)),
         ((1, '2010-12-31 23:59:59.999', 0), (0x80000000, 0)),
         ((1, '2010-12-31 23:59:59.999', 1), (0x80400000, 1)),
         ((1, '2010-12-31 23:59:59.999', 2), (0x80800000, 2)),
         ((1, '2010-12-31 23:59:59.999', 255), (0xbfc00000, 255)),
         # It's the end of the world as we know it...
         ((1, '9998-12-31 23:59:59.999', 0), (0x80000000, 0)),
         ((1, '9998-12-31 23:59:59.999', 1), (0x80400000, 1)),
         ((1, '9998-12-31 23:59:59.999', 255), (0xbfc00000, 255)),
     ]
     # pylint: enable=bad-whitespace
     for i, ((dimensions_hash, timestamp, priority),
             (expected_v, expected_p)) in enumerate(data):
         d = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S.%f')
         actual = task_to_run._gen_queue_number(dimensions_hash, d,
                                                priority)
         self.assertEqual((i, '0x%016x' % expected_v),
                          (i, '0x%016x' % actual))
         # Ensure we can extract the priority back. That said, it is corrupted by
         # time.
         v = task_to_run.TaskToRun(queue_number=actual)
         self.assertEqual((i, expected_p),
                          (i, task_to_run._queue_number_priority(v)))
Esempio n. 2
0
 def test_gen_queue_number(self):
   # tuples of (input, expected).
   # 2**47 / 365 / 24 / 60 / 60 / 1000. = 4462.756
   data = [
     (('1970-01-01 00:00:00.000',   0), '0x0000000000000000'),
     (('1970-01-01 00:00:00.000', 255), '0x001c91dd87cc2000'),
     (('1970-01-01 00:00:00.040',   0), '0x0000000000009c40'),
     (('1970-01-01 00:00:00.050',   0), '0x000000000000c350'),
     (('1970-01-01 00:00:00.100',   0), '0x00000000000186a0'),
     (('1970-01-01 00:00:00.900',   0), '0x00000000000dbba0'),
     (('1970-01-01 00:00:01.000',   0), '0x00000000000f4240'),
     (('1970-01-01 00:00:00.000',   1), '0x00001cae8c13e000'),
     (('1970-01-01 00:00:00.000',   2), '0x0000395d1827c000'),
     (('2010-01-02 03:04:05.060',   0), '0x00047c25bdb25da0'),
     (('2010-01-02 03:04:05.060',   1), '0x000498d449c63da0'),
     # It's the end of the world as we know it...
     (('9999-12-31 23:59:59.999',   0), '0x0384440ccc735c20'),
     (('9999-12-31 23:59:59.999', 255), '0x03a0d5ea543f7c20'),
     (('9999-12-31 23:59:59.999', 255), '0x03a0d5ea543f7c20'),
   ]
   for i, ((timestamp, priority), expected) in enumerate(data):
     d = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S.%f')
     actual = '0x%016x' % task_to_run._gen_queue_number(d, priority)
     self.assertEquals((i, expected), (i, actual))
Esempio n. 3
0
 def test_gen_queue_number(self):
     # tuples of (input, expected).
     # 2**47 / 365 / 24 / 60 / 60 / 1000. = 4462.756
     data = [
         (('1970-01-01 00:00:00.000', 0), '0x0000000000000000'),
         (('1970-01-01 00:00:00.000', 255), '0x001c91dd87cc2000'),
         (('1970-01-01 00:00:00.040', 0), '0x0000000000009c40'),
         (('1970-01-01 00:00:00.050', 0), '0x000000000000c350'),
         (('1970-01-01 00:00:00.100', 0), '0x00000000000186a0'),
         (('1970-01-01 00:00:00.900', 0), '0x00000000000dbba0'),
         (('1970-01-01 00:00:01.000', 0), '0x00000000000f4240'),
         (('1970-01-01 00:00:00.000', 1), '0x00001cae8c13e000'),
         (('1970-01-01 00:00:00.000', 2), '0x0000395d1827c000'),
         (('2010-01-02 03:04:05.060', 0), '0x00047c25bdb25da0'),
         (('2010-01-02 03:04:05.060', 1), '0x000498d449c63da0'),
         # It's the end of the world as we know it...
         (('9999-12-31 23:59:59.999', 0), '0x0384440ccc735c20'),
         (('9999-12-31 23:59:59.999', 255), '0x03a0d5ea543f7c20'),
         (('9999-12-31 23:59:59.999', 255), '0x03a0d5ea543f7c20'),
     ]
     for i, ((timestamp, priority), expected) in enumerate(data):
         d = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S.%f')
         actual = '0x%016x' % task_to_run._gen_queue_number(d, priority)
         self.assertEquals((i, expected), (i, actual))