Ejemplo n.º 1
0
    def test_createfunc(self):
        cache = Cache('test', **self.CACHE_ARGS)

        def createfunc():
            createfunc.count += 1
            return createfunc.count
        createfunc.count = 0

        def keepitlocked():
            lock = cache.namespace.get_creation_lock('test')
            lock.acquire()
            time.sleep(1.0)
            lock.release()

        v0 = cache.get_value('test', createfunc=createfunc)
        self.assertEqual(v0, 1)

        v0 = cache.get_value('test', createfunc=createfunc)
        self.assertEqual(v0, 1)

        cache.remove_value('test')

        begin = datetime.datetime.utcnow()
        t = threading.Thread(target=keepitlocked)
        t.start()

        v0 = cache.get_value('test', createfunc=createfunc)
        self.assertEqual(v0, 2)

        # Ensure that the `get_value` was blocked by the concurrent thread.
        assert datetime.datetime.utcnow() - begin > datetime.timedelta(seconds=1)

        t.join()
Ejemplo n.º 2
0
def test_spaces_in_unicode_keys():
    cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached')
    o = object()
    cache.set_value(u_('hi ŏ'), o)
    assert u_('hi ŏ') in cache
    assert u_('hŏa') not in cache
    cache.remove_value(u_('hi ŏ'))
    assert u_('hi ŏ') not in cache
Ejemplo n.º 3
0
def test_spaces_in_unicode_keys():
    cache = Cache("test", data_dir="./cache", url=mc_url, type="ext:memcached")
    o = object()
    cache.set_value(u"hi ŏ", o)
    assert u"hi ŏ" in cache
    assert u"hŏa" not in cache
    cache.remove_value(u"hi ŏ")
    assert u"hi ŏ" not in cache
Ejemplo n.º 4
0
def test_unicode_keys():    
    cache = Cache('test', data_dir='./cache', type='dbm')
    o = object()
    cache.set_value(u'hiŏ', o)
    assert u'hiŏ' in cache
    assert u'hŏa' not in cache
    cache.remove_value(u'hiŏ')
    assert u'hiŏ' not in cache
Ejemplo n.º 5
0
def test_has_key_multicache():
    cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database')
    o = object()
    cache.set_value("test", o)
    assert "test" in cache
    cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database')
    assert "test" in cache
    cache.remove_value('test')
Ejemplo n.º 6
0
def test_spaces_in_unicode_keys():
    cache = Cache("test", data_dir="./cache", url=mc_url, type="ext:memcached")
    o = object()
    cache.set_value(u_("hi ŏ"), o)
    assert u_("hi ŏ") in cache
    assert u_("hŏa") not in cache
    cache.remove_value(u_("hi ŏ"))
    assert u_("hi ŏ") not in cache
Ejemplo n.º 7
0
def test_unicode_keys():
    cache = Cache("test", data_dir="./cache", type="dbm")
    o = object()
    cache.set_value(u_("hiŏ"), o)
    assert u_("hiŏ") in cache
    assert u_("hŏa") not in cache
    cache.remove_value(u_("hiŏ"))
    assert u_("hiŏ") not in cache
Ejemplo n.º 8
0
def test_unicode_keys():
    cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database')
    o = object()
    cache.set_value(u_('hiŏ'), o)
    assert u_('hiŏ') in cache
    assert u_('hŏa') not in cache
    cache.remove_value(u_('hiŏ'))
    assert u_('hiŏ') not in cache
Ejemplo n.º 9
0
def test_long_unicode_keys():
    cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached')
    o = object()
    long_str = u_('Очень длинная строка, которая не влезает в сто двадцать восемь байт и поэтому не проходит ограничение в check_key, что очень прискорбно, не правда ли, друзья? Давайте же скорее исправим это досадное недоразумение!')
    cache.set_value(long_str, o)
    assert long_str in cache
    cache.remove_value(long_str)
    assert long_str not in cache
Ejemplo n.º 10
0
def test_unicode_keys():
    cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database')
    o = object()
    cache.set_value(u_('hiŏ'), o)
    assert u_('hiŏ') in cache
    assert u_('hŏa') not in cache
    cache.remove_value(u_('hiŏ'))
    assert u_('hiŏ') not in cache
Ejemplo n.º 11
0
 def test_spaces_in_unicode_keys(self):
     cache = Cache("test", **self.CACHE_ARGS)
     o = object()
     cache.set_value(u_("hi ŏ"), o)
     assert u_("hi ŏ") in cache
     assert u_("hŏa") not in cache
     cache.remove_value(u_("hi ŏ"))
     assert u_("hi ŏ") not in cache
Ejemplo n.º 12
0
 def test_spaces_in_unicode_keys(self):
     cache = Cache('test', **self.CACHE_ARGS)
     o = object()
     cache.set_value(u_('hi ŏ'), o)
     assert u_('hi ŏ') in cache
     assert u_('hŏa') not in cache
     cache.remove_value(u_('hi ŏ'))
     assert u_('hi ŏ') not in cache
Ejemplo n.º 13
0
def test_unicode_keys():
    cache = Cache("test", data_dir="./cache", url=db_url, type="ext:database")
    o = object()
    cache.set_value(u"hiŏ", o)
    assert u"hiŏ" in cache
    assert u"hŏa" not in cache
    cache.remove_value(u"hiŏ")
    assert u"hiŏ" not in cache
Ejemplo n.º 14
0
def test_spaces_in_unicode_keys():
    cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached')
    o = object()
    cache.set_value(u_('hi ŏ'), o)
    assert u_('hi ŏ') in cache
    assert u_('hŏa') not in cache
    cache.remove_value(u_('hi ŏ'))
    assert u_('hi ŏ') not in cache
Ejemplo n.º 15
0
def test_has_key():
    cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached')
    o = object()
    cache.set_value("test", o)
    assert "test" in cache
    assert "foo" not in cache
    cache.remove_value("test")
    assert "test" not in cache
Ejemplo n.º 16
0
def test_unicode_keys():
    cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached')
    o = object()
    cache.set_value(u'hiŏ', o)
    assert u'hiŏ' in cache
    assert u'hŏa' not in cache
    cache.remove_value(u'hiŏ')
    assert u'hiŏ' not in cache
Ejemplo n.º 17
0
def test_unicode_keys():
    cache = Cache('test', data_dir='./cache', url=uri, type='mongodb', sparse_collection=True)
    o = object()
    cache.set_value(u'hiŏ', o)
    assert u'hiŏ' in cache
    assert u'hŏa' not in cache
    cache.remove_value(u'hiŏ')
    assert u'hiŏ' not in cache
Ejemplo n.º 18
0
def test_unicode_keys():
    cache = Cache('test', url=db_url, type=db_type, database=db_name)
    o = object()
    cache.set_value('hiŏ', o)
    assert 'hiŏ' in cache
    assert 'hŏa' not in cache
    cache.remove_value('hiŏ')
    assert 'hiŏ' not in cache
Ejemplo n.º 19
0
def test_spaces_in_unicode_keys():
    cache = Cache('test', data_dir='./cache', url=uri, type='mongodb')
    o = object()
    cache.set_value(u'hi ŏ', o)
    assert u'hi ŏ' in cache
    assert u'hŏa' not in cache
    cache.remove_value(u'hi ŏ')
    assert u'hi ŏ' not in cache
Ejemplo n.º 20
0
def test_spaces_in_unicode_keys():
    cache = Cache('test', data_dir='./cache', url=uri, type='mongodb')
    o = object()
    cache.set_value(u'hi ŏ', o)
    assert u'hi ŏ' in cache
    assert u'hŏa' not in cache
    cache.remove_value(u'hi ŏ')
    assert u'hi ŏ' not in cache
Ejemplo n.º 21
0
def test_unicode_keys():
    cache = Cache('test', url=db_url, type=db_type, database=db_name)
    o = object()
    cache.set_value(u'hiŏ', o)
    assert u'hiŏ' in cache
    assert u'hŏa' not in cache
    cache.remove_value(u'hiŏ')
    assert u'hiŏ' not in cache
Ejemplo n.º 22
0
 def test_spaces_in_unicode_keys(self):
     cache = Cache('test', **self.CACHE_ARGS)
     o = object()
     cache.set_value(u_('hi ŏ'), o)
     assert u_('hi ŏ') in cache
     assert u_('hŏa') not in cache
     cache.remove_value(u_('hi ŏ'))
     assert u_('hi ŏ') not in cache
Ejemplo n.º 23
0
 def test_client(self):
     cache = Cache('test', data_dir='./cache', url=mc_url, type="ext:memcached", 
                   protocol='binary')
     o = object()
     cache.set_value("test", o)
     assert "test" in cache
     assert "foo" not in cache
     cache.remove_value("test")
     assert "test" not in cache
Ejemplo n.º 24
0
def test_has_key_multicache():
    cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database')
    o = object()
    cache.set_value("test", o)
    assert "test" in cache
    assert "test" in cache
    cache = Cache('test', data_dir='./cache', url=db_url, type='ext:database')
    assert "test" in cache
    cache.remove_value('test')
Ejemplo n.º 25
0
def test_long_unicode_keys():
    cache = Cache("test", data_dir="./cache", url=mc_url, type="ext:memcached")
    o = object()
    for i in range(0, 260):
        long_str = u"Ы" * i
        cache.set_value(long_str, o)
        assert long_str in cache
        cache.remove_value(long_str)
        assert long_str not in cache
Ejemplo n.º 26
0
def test_has_key_multicache():
    cache = Cache('test', url=db_url, type=db_type, database=db_name)
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    assert "test" in cache
    cache = Cache('test', url=db_url, type=db_type, database=db_name)
    assert cache.has_key("test")
    cache.remove_value('test')
Ejemplo n.º 27
0
def test_has_key_multicache():
    cache = Cache('test', url=db_url, type=db_type, database=db_name)
    o = object()
    cache.set_value("test", o)
    assert "test" in cache
    assert "test" in cache
    cache = Cache('test', url=db_url, type=db_type, database=db_name)
    assert "test" in cache
    cache.remove_value('test')
Ejemplo n.º 28
0
def test_has_key_multicache():
    cache = Cache("test", data_dir="./cache", url=db_url, type="ext:database")
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    assert "test" in cache
    cache = Cache("test", data_dir="./cache", url=db_url, type="ext:database")
    assert cache.has_key("test")
    cache.remove_value("test")
Ejemplo n.º 29
0
def test_has_key():
    cache = Cache("test", data_dir="./cache", type="dbm")
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    assert "test" in cache
    assert not cache.has_key("foo")
    assert "foo" not in cache
    cache.remove_value("test")
    assert not cache.has_key("test")
Ejemplo n.º 30
0
 def test_client(self):
     cache = Cache("test", data_dir="./cache", url=mc_url, type="ext:memcached", protocol="binary")
     o = object()
     cache.set_value("test", o)
     assert cache.has_key("test")
     assert "test" in cache
     assert not cache.has_key("foo")
     assert "foo" not in cache
     cache.remove_value("test")
     assert not cache.has_key("test")
Ejemplo n.º 31
0
 def test_client(self):
     cache = Cache('test', data_dir='./cache', url=uri, type="mongodb", sparse_collection=True, skip_pickle=True)
     o = object()
     cache.set_value("test", o)
     assert cache.has_key("test")
     assert "test" in cache
     assert not cache.has_key("foo")
     assert "foo" not in cache
     cache.remove_value("test")
     assert not cache.has_key("test")
Ejemplo n.º 32
0
def test_has_key():
    cache = Cache('test', data_dir='./cache', url=uri, type='mongodb', sparse_collection=True)
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    assert "test" in cache
    assert not cache.has_key("foo")
    assert "foo" not in cache
    cache.remove_value("test")
    assert not cache.has_key("test")
Ejemplo n.º 33
0
def test_has_key():
    cache = Cache('test', url=db_url, type=db_type, database=db_name)
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    assert "test" in cache
    assert not cache.has_key("foo")
    assert "foo" not in cache
    cache.remove_value("test")
    assert not cache.has_key("test")
Ejemplo n.º 34
0
def test_has_key():
    cache = Cache('test', data_dir='./cache', url=uri, type='mongodb')
    o = object()
    cache.set_value("test", o)
    assert "test" in cache
    assert "test" in cache
    assert "foo" not in cache
    assert "foo" not in cache
    cache.remove_value("test")
    assert "test" not in cache
Ejemplo n.º 35
0
 def test_has_key(self):
     cache = Cache('test', **self.CACHE_ARGS)
     o = object()
     cache.set_value("test", o)
     assert cache.has_key("test")
     assert "test" in cache
     assert not cache.has_key("foo")
     assert "foo" not in cache
     cache.remove_value("test")
     assert not cache.has_key("test")
Ejemplo n.º 36
0
 def test_long_unicode_keys(self):
     cache = Cache('test', **self.CACHE_ARGS)
     o = object()
     long_str = u_(
         'Очень длинная строка, которая не влезает в сто двадцать восемь байт и поэтому не проходит ограничение в check_key, что очень прискорбно, не правда ли, друзья? Давайте же скорее исправим это досадное недоразумение!'
     )
     cache.set_value(long_str, o)
     assert long_str in cache
     cache.remove_value(long_str)
     assert long_str not in cache
Ejemplo n.º 37
0
def test_has_key():
    cache = Cache('test', data_dir='./cache', url=uri, type='mongodb_gridfs')
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    assert "test" in cache
    assert not cache.has_key("foo")
    assert "foo" not in cache
    cache.remove_value("test")
    assert not cache.has_key("test")
Ejemplo n.º 38
0
def test_has_key():
    cache = Cache("test", data_dir="./cache", url=db_url, type="ext:database")
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    assert "test" in cache
    assert not cache.has_key("foo")
    assert "foo" not in cache
    cache.remove_value("test")
    assert not cache.has_key("test")
Ejemplo n.º 39
0
 def test_client(self):
     cache = Cache('test', data_dir='./cache', url=uri, type="mongodb")
     o = object()
     cache.set_value("test", o)
     assert cache.has_key("test")
     assert "test" in cache
     assert not cache.has_key("foo")
     assert "foo" not in cache
     cache.remove_value("test")
     assert not cache.has_key("test")
Ejemplo n.º 40
0
 def test_client(self):
     cache = Cache('test', data_dir='./cache', url=uri, type="mongodb")
     o = object()
     cache.set_value("test", o)
     assert cache.has_key("test")
     assert "test" in cache
     assert not cache.has_key("foo")
     assert "foo" not in cache
     cache.remove_value("test")
     assert not cache.has_key("test")
Ejemplo n.º 41
0
def test_has_key():
    cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached')
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    assert "test" in cache
    assert not cache.has_key("foo")
    assert "foo" not in cache
    cache.remove_value("test")
    assert not cache.has_key("test")
Ejemplo n.º 42
0
def test_long_unicode_keys():
    cache = Cache('test', data_dir='./cache', url=mc_url, type='ext:memcached')
    o = object()
    long_str = u_(
        'Очень длинная строка, которая не влезает в сто двадцать восемь байт и поэтому не проходит ограничение в check_key, что очень прискорбно, не правда ли, друзья? Давайте же скорее исправим это досадное недоразумение!'
    )
    cache.set_value(long_str, o)
    assert long_str in cache
    cache.remove_value(long_str)
    assert long_str not in cache
Ejemplo n.º 43
0
 def test_has_key(self):
     cache = Cache('test', **self.CACHE_ARGS)
     o = object()
     cache.set_value("test", o)
     assert cache.has_key("test")
     assert "test" in cache
     assert not cache.has_key("foo")
     assert "foo" not in cache
     cache.remove_value("test")
     assert not cache.has_key("test")
Ejemplo n.º 44
0
 def test_long_unicode_keys(self):
     cache = Cache('test', **self.CACHE_ARGS)
     o = object()
     long_str = u_(
         'Очень длинная строка, которая не влезает в сто двадцать восемь байт и поэтому не проходит ограничение в check_key, что очень прискорбно, не правда ли, друзья? Давайте же скорее исправим это досадное недоразумение!'
     )
     cache.set_value(long_str, o)
     assert long_str in cache
     cache.remove_value(long_str)
     assert long_str not in cache
Ejemplo n.º 45
0
def test_has_key():
    cache = Cache('test', data_dir='./cache', type='dbm')
    o = object()
    cache.set_value("test", o)
    assert cache.has_key("test")
    assert "test" in cache
    assert not cache.has_key("foo")
    assert "foo" not in cache
    cache.remove_value("test")
    assert not cache.has_key("test")
Ejemplo n.º 46
0
def test_unicode_keys():
    cache = Cache('test',
                  data_dir='./cache',
                  url=uri,
                  type='mongodb',
                  sparse_collection=True)
    o = object()
    cache.set_value(u'hiŏ', o)
    assert u'hiŏ' in cache
    assert u'hŏa' not in cache
    cache.remove_value(u'hiŏ')
    assert u'hiŏ' not in cache
Ejemplo n.º 47
0
 def test_client(self):
     cache = Cache('test',
                   data_dir='./cache',
                   url=mc_url,
                   type="ext:memcached",
                   protocol='binary')
     o = object()
     cache.set_value("test", o)
     assert cache.has_key("test")
     assert "test" in cache
     assert not cache.has_key("foo")
     assert "foo" not in cache
     cache.remove_value("test")
     assert not cache.has_key("test")
Ejemplo n.º 48
0
def test_remove_stale():
    """test that remove_value() removes even if the value is expired."""

    cache = Cache('test', type='memory')
    o = object()
    cache.namespace[b'key'] = (time.time() - 60, 5, o)
    container = cache._get_value('key')
    assert not container.has_current_value()
    assert b'key' in container.namespace
    cache.remove_value('key')
    assert b'key' not in container.namespace

    # safe to call again
    cache.remove_value('key')
Ejemplo n.º 49
0
def test_remove_stale():
    """test that remove_value() removes even if the value is expired."""

    cache = Cache('test', type='memory')
    o = object()
    cache.namespace[b'key'] = (time.time() - 60, 5, o)
    container = cache._get_value('key')
    assert not container.has_current_value()
    assert b'key' in container.namespace
    cache.remove_value('key')
    assert b'key' not in container.namespace

    # safe to call again
    cache.remove_value('key')
Ejemplo n.º 50
0
def test_remove_stale():
    """test that remove_value() removes even if the value is expired."""

    cache = Cache("test", type="memory")
    o = object()
    cache.namespace[b"key"] = (time.time() - 60, 5, o)
    container = cache._get_value("key")
    assert not container.has_current_value()
    assert b"key" in container.namespace
    cache.remove_value("key")
    assert b"key" not in container.namespace

    # safe to call again
    cache.remove_value("key")
Ejemplo n.º 51
0
def test_remove_stale():
    """test that remove_value() removes even if the value is expired."""

    cache = Cache("test", type="memory")
    o = object()
    cache.namespace["key"] = (time.time() - 30, 10, o)
    container = cache._get_value("key")
    assert not container.has_current_value()
    assert "key" in container.namespace
    cache.remove_value("key")
    assert "key" not in container.namespace

    # safe to call again
    cache.remove_value("key")
Ejemplo n.º 52
0
 def test_client(self):
     cache = Cache('test',
                   data_dir='./cache',
                   url=uri,
                   type="mongodb",
                   sparse_collection=True,
                   skip_pickle=True)
     o = object()
     cache.set_value("test", o)
     assert cache.has_key("test")
     assert "test" in cache
     assert not cache.has_key("foo")
     assert "foo" not in cache
     cache.remove_value("test")
     assert not cache.has_key("test")
Ejemplo n.º 53
0
def test_fresh_createfunc():
    cache = Cache('test_foo', data_dir='./cache', type='dbm')
    x = cache.get_value('test', createfunc=lambda: 10, expiretime=2)
    assert x == 10
    x = cache.get_value('test', createfunc=lambda: 12, expiretime=2)
    assert x == 10
    x = cache.get_value('test', createfunc=lambda: 14, expiretime=2)
    assert x == 10
    time.sleep(2)
    x = cache.get_value('test', createfunc=lambda: 16, expiretime=2)
    assert x == 16
    x = cache.get_value('test', createfunc=lambda: 18, expiretime=2)
    assert x == 16

    cache.remove_value('test')
    assert not cache.has_key('test')
    x = cache.get_value('test', createfunc=lambda: 20, expiretime=2)
    assert x == 20
Ejemplo n.º 54
0
def test_fresh_createfunc():
    cache = Cache("test_foo", data_dir="./cache", type="dbm")
    x = cache.get_value("test", createfunc=lambda: 10, expiretime=2)
    assert x == 10
    x = cache.get_value("test", createfunc=lambda: 12, expiretime=2)
    assert x == 10
    x = cache.get_value("test", createfunc=lambda: 14, expiretime=2)
    assert x == 10
    time.sleep(2)
    x = cache.get_value("test", createfunc=lambda: 16, expiretime=2)
    assert x == 16
    x = cache.get_value("test", createfunc=lambda: 18, expiretime=2)
    assert x == 16

    cache.remove_value("test")
    assert not cache.has_key("test")
    x = cache.get_value("test", createfunc=lambda: 20, expiretime=2)
    assert x == 20
Ejemplo n.º 55
0
def test_fresh_createfunc():
    cache = Cache("test_foo", data_dir="./cache", type="dbm")
    x = cache.get_value("test", createfunc=lambda: 10, expiretime=2)
    assert x == 10
    x = cache.get_value("test", createfunc=lambda: 12, expiretime=2)
    assert x == 10
    x = cache.get_value("test", createfunc=lambda: 14, expiretime=2)
    assert x == 10
    time.sleep(2)
    x = cache.get_value("test", createfunc=lambda: 16, expiretime=2)
    assert x == 16
    x = cache.get_value("test", createfunc=lambda: 18, expiretime=2)
    assert x == 16

    cache.remove_value("test")
    assert not cache.has_key("test")
    x = cache.get_value("test", createfunc=lambda: 20, expiretime=2)
    assert x == 20
Ejemplo n.º 56
0
def test_fresh_createfunc():
    cache = Cache('test', data_dir='./cache', type='dbm')
    x = cache.get_value('test', createfunc=lambda: 10, expiretime=2)
    assert x == 10
    x = cache.get_value('test', createfunc=lambda: 12, expiretime=2)
    assert x == 10
    x = cache.get_value('test', createfunc=lambda: 14, expiretime=2)
    assert x == 10
    time.sleep(2)
    x = cache.get_value('test', createfunc=lambda: 16, expiretime=2)
    assert x == 16
    x = cache.get_value('test', createfunc=lambda: 18, expiretime=2)
    assert x == 16
    
    cache.remove_value('test')
    assert not cache.has_key('test')
    x = cache.get_value('test', createfunc=lambda: 20, expiretime=2)
    assert x == 20
Ejemplo n.º 57
0
    def test_createfunc(self):
        cache = Cache("test", **self.CACHE_ARGS)

        def createfunc():
            createfunc.count += 1
            return createfunc.count

        createfunc.count = 0

        def keepitlocked():
            lock = cache.namespace.get_creation_lock("test")
            lock.acquire()
            keepitlocked.acquired = True
            time.sleep(1.0)
            lock.release()

        keepitlocked.acquired = False

        v0 = cache.get_value("test", createfunc=createfunc)
        self.assertEqual(v0, 1)

        v0 = cache.get_value("test", createfunc=createfunc)
        self.assertEqual(v0, 1)

        cache.remove_value("test")

        begin = datetime.datetime.utcnow()
        t = threading.Thread(target=keepitlocked)
        t.start()
        while not keepitlocked.acquired:
            # Wait for the thread that should lock the cache to start.
            time.sleep(0.001)

        v0 = cache.get_value("test", createfunc=createfunc)
        self.assertEqual(v0, 2)

        # Ensure that the `get_value` was blocked by the concurrent thread.
        assert datetime.datetime.utcnow() - begin > datetime.timedelta(seconds=1)

        t.join()
Ejemplo n.º 58
0
def test_legacy_cache():
    cache = Cache("newtests", data_dir="./cache", type="dbm")

    cache.set_value("x", "1")
    assert cache.get_value("x") == "1"

    cache.set_value("x", "2", type="file", data_dir="./cache")
    assert cache.get_value("x") == "1"
    assert cache.get_value("x", type="file", data_dir="./cache") == "2"

    cache.remove_value("x")
    cache.remove_value("x", type="file", data_dir="./cache")

    assert cache.get_value("x", expiretime=1, createfunc=lambda: "5") == "5"
    assert cache.get_value("x", expiretime=1, createfunc=lambda: "6", type="file", data_dir="./cache") == "6"
    assert cache.get_value("x", expiretime=1, createfunc=lambda: "7") == "5"
    assert cache.get_value("x", expiretime=1, createfunc=lambda: "8", type="file", data_dir="./cache") == "6"
    time.sleep(1)
    assert cache.get_value("x", expiretime=1, createfunc=lambda: "9") == "9"
    assert cache.get_value("x", expiretime=1, createfunc=lambda: "10", type="file", data_dir="./cache") == "10"
    assert cache.get_value("x", expiretime=1, createfunc=lambda: "11") == "9"
    assert cache.get_value("x", expiretime=1, createfunc=lambda: "12", type="file", data_dir="./cache") == "10"
Ejemplo n.º 59
0
def test_legacy_cache():
    cache = Cache('newtests', data_dir='./cache', type='dbm')

    cache.set_value('x', '1')
    assert cache.get_value('x') == '1'

    cache.set_value('x', '2', type='file', data_dir='./cache')
    assert cache.get_value('x') == '1'
    assert cache.get_value('x', type='file', data_dir='./cache') == '2'

    cache.remove_value('x')
    cache.remove_value('x', type='file', data_dir='./cache')

    assert cache.get_value('x', expiretime=1, createfunc=lambda: '5') == '5'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '6', type='file', data_dir='./cache') == '6'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '7') == '5'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '8', type='file', data_dir='./cache') == '6'
    time.sleep(1)
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '9') == '9'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '10', type='file', data_dir='./cache') == '10'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '11') == '9'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '12', type='file', data_dir='./cache') == '10'
Ejemplo n.º 60
0
def test_legacy_cache():
    cache = Cache('newtests', data_dir='./cache', type='dbm')

    cache.set_value('x', '1')
    assert cache.get_value('x') == '1'

    cache.set_value('x', '2', type='file', data_dir='./cache')
    assert cache.get_value('x') == '1'
    assert cache.get_value('x', type='file', data_dir='./cache') == '2'

    cache.remove_value('x')
    cache.remove_value('x', type='file', data_dir='./cache')

    assert cache.get_value('x', expiretime=1, createfunc=lambda: '5') == '5'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '6', type='file', data_dir='./cache') == '6'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '7') == '5'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '8', type='file', data_dir='./cache') == '6'
    time.sleep(1)
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '9') == '9'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '10', type='file', data_dir='./cache') == '10'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '11') == '9'
    assert cache.get_value('x', expiretime=1, createfunc=lambda: '12', type='file', data_dir='./cache') == '10'