Пример #1
0
    def test_dont_dump_bad_config(self):
        """
        Ensures that mcrouter do not dump invalid configs.
        """
        # first, copy valid config to a temp file, as we need to modify it later
        base_dir = BaseDirectory('McConfigs')
        config_path = self._get_valid_config(base_dir)

        # create mcrouter with a valid config (mcrouter will dump it to disk).
        mcrouter = self.get_mcrouter(config_path)
        self.assertTrue(self._is_mcrouter_running(mcrouter))

        # replace config file with an invalid one.
        # Mcrouter should not dump config this time, because it's invalid.
        self._replace_with_invalid_config(config_path)

        # shutdown mcrouter
        mcrouter.shutdown()
        mcrouter.terminate()

        # check if the last config dumped is the valid config.
        dumped_config_root = self._get_dumped_config_root()
        dumped_config_files = os.listdir(dumped_config_root)
        self.assertEqual(1, len(dumped_config_files))
        dumped_config_file = '{}/{}'.format(
            dumped_config_root, dumped_config_files[0])
        with open(self.valid_config) as original_file:
            with open(dumped_config_file) as dumped_file:
                self.assertEqual(original_file.read(), dumped_file.read())
Пример #2
0
    def test_dumped_config_too_old(self):
        """
        Test if mcrouter fails to configure if dumped config is too old
        to be trusted.
        """
        # first, copy valid config to a temp file, as we need to modify it later
        base_dir = BaseDirectory('McConfigs')
        config_path = self._get_valid_config(base_dir)

        # create mcrouter with a valid config (mcrouter will dump it to disk).
        mcrouter = self.get_mcrouter(config_path)
        self.assertTrue(self._is_mcrouter_running(mcrouter))

        # shutdown mcrouter
        mcrouter.shutdown()
        mcrouter.terminate()

        # replace config file with an invalid one
        self._replace_with_invalid_config(config_path)

        # sleep for 2 seconds and forbid mcrouter from using backup configs
        # that were dumped more than 1 second ago.
        time.sleep(2)
        mcrouter = self.get_mcrouter(config_path,
                                     ['--max-dumped-config-age', '1'])

        # Mcrouter should not be running this time
        self.assertFalse(self._is_mcrouter_running(mcrouter))
Пример #3
0
    def test_use_dumped_config(self):
        """
        Test if mcrouter can successfully reconfigure from dumped configs
        when a bad config file if pushed.
        """
        # first, copy valid config to a temp file, as we need to modify it later
        base_dir = BaseDirectory('McConfigs')
        config_path = self._get_valid_config(base_dir)

        # create mcrouter with a valid config (mcrouter will dump it to disk).
        mcrouter = self.get_mcrouter(config_path)
        self.assertTrue(self._is_mcrouter_running(mcrouter))

        # shutdown mcrouter
        mcrouter.shutdown()
        mcrouter.terminate()

        # replace config file with an invalid one
        self._replace_with_invalid_config(config_path)

        # check if mcrouter configured correctly.
        mcrouter = self.get_mcrouter(config_path)
        self.assertTrue(self._is_mcrouter_running(mcrouter))
Пример #4
0
 def setUp(self):
     self.config_dump_root = BaseDirectory('config_dump')
Пример #5
0
class TestMcpiper(McrouterTestCase):
    mcrouter_ascii_config = './mcrouter/test/mcrouter_test_basic_1_1_1.json'
    mcrouter_ascii_extra_args = [
        '--debug-fifo-root',
        BaseDirectory('mcrouter_ascii').path
    ]

    mcrouter_umbrella_config = './mcrouter/test/test_umbrella_server.json'
    mcrouter_umbrella_extra_args = [
        '--debug-fifo-root',
        BaseDirectory('mcrouter_umbrella').path
    ]

    mcrouter_caret_config = './mcrouter/test/test_caret_server.json'
    mcrouter_caret_extra_args = [
        '--debug-fifo-root',
        BaseDirectory('mcrouter_caret').path
    ]

    def setUp(self):
        self.memcached = self.add_server(Memcached())
        self.mcrouter_ascii = self.add_mcrouter(
            self.mcrouter_ascii_config,
            extra_args=self.mcrouter_ascii_extra_args,
            bg_mcrouter=True)
        self.mcrouter_umbrella = self.add_mcrouter(
            self.mcrouter_umbrella_config,
            extra_args=self.mcrouter_umbrella_extra_args)
        self.mcrouter_caret = self.add_mcrouter(
            self.mcrouter_caret_config,
            extra_args=self.mcrouter_caret_extra_args)

    def get_mcpiper(self, mcrouter, raw):
        args = []
        if raw:
            args.append('--raw')
        mcpiper = Mcpiper(mcrouter.debug_fifo_root, args)

        # Make sure mcrouter creates fifos and start replicating data to them.
        mcrouter.set('abc', '123')
        mcrouter.delete('abc')
        time.sleep(3)

        return mcpiper

    def do_get_test(self, mcrouter, raw, special_symbol):
        # Prepare data
        self.assertTrue(self.memcached.set('key_hit', 'value_hit'))

        mcpiper = self.get_mcpiper(mcrouter, raw)

        self.assertEquals('value_hit', mcrouter.get('key_hit'))
        self.assertFalse(mcrouter.get('key_miss'))

        # wait for data to arrive in mcpiper
        time.sleep(2)

        self.assertTrue(mcpiper.contains('value_hit'))
        if raw:
            self.assertTrue(mcpiper.contains(special_symbol))
            self.assertTrue(mcpiper.contains('key_miss'))
            self.assertTrue(mcpiper.contains('key_hit'))
        else:
            self.assertTrue(mcpiper.contains('mc_res_found'))
            self.assertTrue(mcpiper.contains('mc_res_notfound'))
            self.assertTrue(mcpiper.contains('get key_miss'))
            self.assertTrue(mcpiper.contains('get key_hit'))

    def do_set_test(self, mcrouter, raw, special_symbol):

        mcpiper = self.get_mcpiper(mcrouter, raw)

        self.assertTrue(mcrouter.set('key', 'value2'))

        # wait for data to arrive in mcpiper
        time.sleep(2)
        self.assertTrue(mcpiper.contains('value2'))
        if raw:
            self.assertTrue(mcpiper.contains(special_symbol))
            self.assertTrue(mcpiper.contains('key'))
        else:
            self.assertTrue(mcpiper.contains('set key'))

    def do_delete_test(self, mcrouter, raw, special_symbol):
        # Prepare data
        self.assertTrue(self.memcached.set('key_del', 'value_to_del'))

        mcpiper = self.get_mcpiper(mcrouter, raw)

        self.assertTrue(mcrouter.delete('key_del'))
        self.assertFalse(mcrouter.delete('key_not_found'))

        # wait for data to arrive in mcpiper
        time.sleep(2)

        if raw:
            self.assertTrue(mcpiper.contains(special_symbol))
            self.assertTrue(mcpiper.contains('key_del'))
            self.assertTrue(mcpiper.contains('key_not_found'))
        else:
            self.assertTrue(mcpiper.contains('mc_res_notfound'))
            self.assertTrue(mcpiper.contains('deleted'))
            self.assertTrue(mcpiper.contains('delete key_del'))
            self.assertTrue(mcpiper.contains('delete key_not_found'))

    def test_get_ascii(self):
        self.do_get_test(self.mcrouter_ascii, False, '')

    def test_set_ascii(self):
        self.do_set_test(self.mcrouter_ascii, False, '')

    def test_delete_ascii(self):
        self.do_delete_test(self.mcrouter_ascii, False, '')

    def test_get_umbrella(self):
        self.do_get_test(self.mcrouter_umbrella, False, '}')

    def test_set_umbrella(self):
        self.do_set_test(self.mcrouter_umbrella, False, '}')

    def test_delete_umbrella(self):
        self.do_delete_test(self.mcrouter_umbrella, False, '}')

    def test_get_caret(self):
        self.do_get_test(self.mcrouter_caret, False, '^')

    def test_set_caret(self):
        self.do_set_test(self.mcrouter_caret, False, '^')

    def test_delete_caret(self):
        self.do_delete_test(self.mcrouter_caret, False, '^')

    def test_get_umbrella_raw(self):
        self.do_get_test(self.mcrouter_umbrella, True, '}')

    def test_set_umbrella_raw(self):
        self.do_set_test(self.mcrouter_umbrella, True, '}')

    def test_delete_umbrella_raw(self):
        self.do_delete_test(self.mcrouter_umbrella, True, '}')

    def test_get_caret_raw(self):
        self.do_get_test(self.mcrouter_caret, True, '^')

    def test_set_caret_raw(self):
        self.do_set_test(self.mcrouter_caret, True, '^')

    def test_delete_caret_raw(self):
        self.do_delete_test(self.mcrouter_caret, True, '^')