Example #1
0
    def test_reader_handler__parse_error(self, memc_class):
        _, filename = tempfile.mkstemp()

        fd = gzip.open(filename, 'wb')
        fd.write(b'\tdev_b\t1\t1\t1')
        fd.close()

        reader_queue = queue.Queue()
        memc_load.reader_handler(filename, {'dev_a': memc_load.MemcachedLoader('127.0.0.1:8000')}, reader_queue)
        os.remove(filename)

        message = reader_queue.get_nowait()
        self.assertEqual(len(message), 3)
        self.assertEqual(message[0], filename)
        self.assertEqual(message[1], 0)
        self.assertEqual(message[2], 1)
Example #2
0
    def test_reader_handler__unknown_device(self, memc_class):
        _, filename = tempfile.mkstemp()

        fd = gzip.open(filename, 'wb')
        fd.write(b'dev_a\tdev_a\t1\t1\t1\t')
        fd.close()

        reader_queue = queue.Queue()
        memc_load.reader_handler(filename, {'dev_b': memc_load.MemcachedLoader('127.0.0.1:8000')}, reader_queue)
        os.remove(filename)

        message = reader_queue.get_nowait()
        self.assertEqual(len(message), 3)
        self.assertEqual(message[0], filename)
        self.assertEqual(message[1], 0, "Wrong number of processed")
        self.assertEqual(message[2], 1, "Wrong number of errors")
        print(message)
Example #3
0
 def test_reconnect(self, memc_class):
     memc_class.side_effect = [Exception(), Exception(), mock.Mock()]
     memc_load.MemcachedLoader('address')
     self.assertTrue(memc_class.call_count, 3)
Example #4
0
 def test_success_load(self):
     loader = memc_load.MemcachedLoader('127.0.0.1:44551')
     apps = memc_load.AppsInstalled('1234', '1234', 1, 2, [1234])
     loader.load(apps)
Example #5
0
 def test_success_connect(self):
     loader = memc_load.MemcachedLoader('127.0.0.1:44551')
Example #6
0
 def test_unsuccess_connect(self, memc_class):
     memc_class.side_effect = Exception
     with self.assertRaises(memc_load.MemcachedConnectionError):
         memc_load.MemcachedLoader('address')
Example #7
0
 def test_dry_run(self, memc_class):
     memc_class.side_effect = Exception()
     loader = memc_load.MemcachedLoader('address', True)
     apps = memc_load.AppsInstalled('1234', '1234', 1, 2, [1234])
     loader.load(apps)
     self.assertTrue(memc_class.call_count == 0)