示例#1
0
class MemcachedTestCase(unittest.TestCase):
    def setUp(self):
        self.mc = Client()
        LOCK.identifier = "SINGLE_BEAT_MEMCACHED_SERVER"
        LOCK.mc = self.mc

    def test_acquire_lock(self):
        LOCK.acquire_lock()
        value = "%s:%s" % (HOST_IDENTIFIER, '0')
        self.assertEqual(self.mc.get(LOCK.lock_key), value)

    def test_refreshlock(self):
        LOCK.refresh_lock(777)
        value = "%s:%s" % (HOST_IDENTIFIER, 777)
        self.assertEqual(self.mc.get(LOCK.lock_key), value)
示例#2
0
def invalidate_cached_object(instance, is_test=False):
    """
        Removes cached objects for all users based on the class name of the
        instance passed.

        Ex: Given a DataSet instance, all possible cached objects holding
        DataSets will be deleted to represent the saving, updating,
        deletion, or perms change that was performed upon it.

        If the is_test flag is set, a new instance of a mockcache Client
        will be returned
    """
    if not is_test:
        try:
            cache.delete_many([
                '{}-{}'.format(user.id, instance.__class__.__name__)
                for user in User.objects.all()
            ])

        except Exception as e:
            logger.debug(
                "Could not delete %s from cache" % instance.__class__.__name__,
                e)
    else:
        from mockcache import Client
        mc = Client()
        return mc
示例#3
0
class MemcachedTestCase(unittest.TestCase):

	def setUp(self):
		self.mc = Client()
		LOCK.identifier = "SINGLE_BEAT_MEMCACHED_SERVER"
		LOCK.mc = self.mc

	def test_acquire_lock(self):
		LOCK.acquire_lock()
		value = "%s:%s" % (HOST_IDENTIFIER, '0')
		self.assertEqual(self.mc.get(LOCK.lock_key),value)

	def test_refreshlock(self):
		LOCK.refresh_lock(777)
		value = "%s:%s" % (HOST_IDENTIFIER, 777)
		self.assertEqual(self.mc.get(LOCK.lock_key),value)
示例#4
0
    def setUp(self):
        config.tf_server = tf.train.Server.create_local_server()
        config.mc = Client()
        self.model = Model()
        self.model.data = {
            "x": [0, 0.1, 0.2, 0.3],
            "x2": [5, -2, 3, 10],
            "output_y": [1, 2, 3, 4]
        }
        self.model.norms = {"x": [0, 0.3], "x2": [-2, 10], "output_y": [1, 4]}
        self.model.types = {"x": "float", "x2": "float"}
        self.model.model_path = "/tmp/mymodel"

        self.model2 = Model()
        self.model2.data = {
            "x0": [0, 0.1, 0.2, 0.3],
            "class": ["a", "a", "c", "k"],
            "output_y": [1, 2, 3, 4]
        }
        self.model2.norms = {"x0": [0, 0.3], "class": [], "output_y": [1, 4]}
        self.model2.types = {"x0": "float", "class": "str"}
        self.model2.model_path = "/tmp/mymodel2"
示例#5
0
 def setUp(self):
     self.mc = Client()
     LOCK.identifier = "SINGLE_BEAT_MEMCACHED_SERVER"
     LOCK.mc = self.mc
示例#6
0
	def setUp(self):
		self.mc = Client()
		LOCK.identifier = "SINGLE_BEAT_MEMCACHED_SERVER"
		LOCK.mc = self.mc
示例#7
0
 def setUp(self):
     config.mc = Client()