Beispiel #1
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        config = {
            'servers': ['127.0.0.1:11211'],
        }
        self.mc = mc_from_config(config)
        self.cache = VersionedLocalCached(self.mc)
Beispiel #2
0
 def test_get_should_return_from_mc_when_cached_version_mismatches(self):
     self.cache.set('key', 1)
     c2 = VersionedLocalCached(self.mc)
     c2.set('key', 2)
     self.assertEqual(self.cache.dataset['key'][0], 1)
     r = self.cache.get('key')
     self.assertEqual(r, 2)
     self.assertEqual(self.cache.dataset['key'][0], 2)
     self.assertEqual(self.cache.dataset['key'][1], self.mc.get('key:VER2'))
Beispiel #3
0
 def test_get_should_return_from_mc_when_cached_version_mismatches(self):
     self.cache.set('key', 1)
     c2 = VersionedLocalCached(self.mc)
     c2.set('key', 2)
     self.assertEqual(self.cache.dataset['key'][0], 1)
     r = self.cache.get('key')
     self.assertEqual(r, 2)
     self.assertEqual(self.cache.dataset['key'][0], 2)
     self.assertEqual(self.cache.dataset['key'][1], self.mc.get('key:VER2'))
Beispiel #4
0
    def setUp(self):
        unittest.TestCase.setUp(self)

        config = {
            'servers': ['127.0.0.1:11211'],
        }
        self.mc = mc_from_config(config)
        self.cache = VersionedLocalCached(self.mc)
Beispiel #5
0
 def test_get_should_return_value_when_another_process_set_it(self):
     c2 = VersionedLocalCached(self.mc)
     c2.set('key', 1)
     r = self.cache.get('key')
     self.assertEqual(r, 1)
Beispiel #6
0
class VersionedLocalCachedTestCase(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)

        config = {
            'servers': ['127.0.0.1:11211'],
        }
        self.mc = mc_from_config(config)
        self.cache = VersionedLocalCached(self.mc)

    def test_get_should_return_None_when_not_exists_in_mc(self):
        r = self.cache.get('test')
        self.assertEqual(r, None)

    def test_get_should_return_None_when_only_version_exists(self):
        self.mc.set('key:VER2', '1234567890')
        r = self.cache.get('key')
        self.assertEqual(r, None)

    def test_get_should_return_None_when_no_version_exists(self):
        self.mc.delete('key:VER2')
        self.mc.set('key:V:1234567890', 1)
        r = self.cache.get('key')
        self.assertEqual(r, None)

    def test_get_should_return_value_after_set(self):
        self.cache.set('key', 1)
        r = self.cache.get('key')
        self.assertEqual(r, 1)

    def test_get_should_return_value_when_another_process_set_it(self):
        c2 = VersionedLocalCached(self.mc)
        c2.set('key', 1)
        r = self.cache.get('key')
        self.assertEqual(r, 1)

    def test_set_should_set_local_cache(self):
        self.cache.set('key', 1)
        self.assertTrue('key' in self.cache.dataset)

    def test_get_should_return_from_local_cache_when_version_matches(self):
        self.cache.set('key', 1)
        # change local cache for comparation
        value, version = self.cache.dataset['key']
        self.cache.dataset['key'] = (2, version)
        r = self.cache.get('key')
        self.assertEqual(r, 2)

    def test_get_should_return_from_mc_when_cached_version_mismatches(self):
        self.cache.set('key', 1)
        c2 = VersionedLocalCached(self.mc)
        c2.set('key', 2)
        self.assertEqual(self.cache.dataset['key'][0], 1)
        r = self.cache.get('key')
        self.assertEqual(r, 2)
        self.assertEqual(self.cache.dataset['key'][0], 2)
        self.assertEqual(self.cache.dataset['key'][1], self.mc.get('key:VER2'))

    def test_get_multi_should_work(self):
        self.cache.set('key1', 1)
        self.cache.set('key2', 2)
        r = self.cache.get_multi(['key1', 'key2'])
        self.assertEqual(r, {'key1': 1, 'key2': 2})

    def test_get_list_should_work(self):
        self.cache.set('key1', 1)
        self.cache.set('key2', 2)
        r = self.cache.get_list(['key1', 'key2'])
        self.assertEqual(r, [1, 2])

    def test_delete_should_work(self):
        self.cache.set('key1', 1)
        self.cache.delete('key1')
        r = self.cache.get('key1')
        self.assertEqual(r, None)

    def test_version_should_be_consistent_for_same_value(self):
        self.cache.set('key1', 1)
        ver = self.mc.get('key1:VER2')
        self.cache.delete('key1')
        self.cache.set('key1', 1)
        ver2 = self.mc.get('key1:VER2')
        self.assertEqual(ver, ver2)
Beispiel #7
0
 def test_get_should_return_value_when_another_process_set_it(self):
     c2 = VersionedLocalCached(self.mc)
     c2.set('key', 1)
     r = self.cache.get('key')
     self.assertEqual(r, 1)
Beispiel #8
0
class VersionedLocalCachedTestCase(unittest.TestCase):
    def setUp(self):
        unittest.TestCase.setUp(self)

        config = {
            'servers': ['127.0.0.1:11211'],
        }
        self.mc = mc_from_config(config)
        self.cache = VersionedLocalCached(self.mc)

    def test_get_should_return_None_when_not_exists_in_mc(self):
        r = self.cache.get('test')
        self.assertEqual(r, None)

    def test_get_should_return_None_when_only_version_exists(self):
        self.mc.set('key:VER2', '1234567890')
        r = self.cache.get('key')
        self.assertEqual(r, None)

    def test_get_should_return_None_when_no_version_exists(self):
        self.mc.delete('key:VER2')
        self.mc.set('key:V:1234567890', 1)
        r = self.cache.get('key')
        self.assertEqual(r, None)

    def test_get_should_return_value_after_set(self):
        self.cache.set('key', 1)
        r = self.cache.get('key')
        self.assertEqual(r, 1)

    def test_get_should_return_value_when_another_process_set_it(self):
        c2 = VersionedLocalCached(self.mc)
        c2.set('key', 1)
        r = self.cache.get('key')
        self.assertEqual(r, 1)

    def test_set_should_set_local_cache(self):
        self.cache.set('key', 1)
        self.assertTrue('key' in self.cache.dataset)

    def test_get_should_return_from_local_cache_when_version_matches(self):
        self.cache.set('key', 1)
        # change local cache for comparation
        value, version = self.cache.dataset['key']
        self.cache.dataset['key'] = (2, version)
        r = self.cache.get('key')
        self.assertEqual(r, 2)

    def test_get_should_return_from_mc_when_cached_version_mismatches(self):
        self.cache.set('key', 1)
        c2 = VersionedLocalCached(self.mc)
        c2.set('key', 2)
        self.assertEqual(self.cache.dataset['key'][0], 1)
        r = self.cache.get('key')
        self.assertEqual(r, 2)
        self.assertEqual(self.cache.dataset['key'][0], 2)
        self.assertEqual(self.cache.dataset['key'][1], self.mc.get('key:VER2'))

    def test_get_multi_should_work(self):
        self.cache.set('key1', 1)
        self.cache.set('key2', 2)
        r = self.cache.get_multi(['key1', 'key2'])
        self.assertEqual(r, {'key1': 1, 'key2': 2})

    def test_get_list_should_work(self):
        self.cache.set('key1', 1)
        self.cache.set('key2', 2)
        r = self.cache.get_list(['key1', 'key2'])
        self.assertEqual(r, [1, 2])

    def test_delete_should_work(self):
        self.cache.set('key1', 1)
        self.cache.delete('key1')
        r = self.cache.get('key1')
        self.assertEqual(r, None)

    def test_version_should_be_consistent_for_same_value(self):
        self.cache.set('key1', 1)
        ver = self.mc.get('key1:VER2')
        self.cache.delete('key1')
        self.cache.set('key1', 1)
        ver2 = self.mc.get('key1:VER2')
        self.assertEqual(ver, ver2)