def __init__(self): self.client = Client(config.get("aws", "access_key_id"), config.get("aws", "secret_access_key")) self.key = hashlib.md5("CloudCacheTest").hexdigest() self.tests = defaultdict(list) self.test_types = ("put", "get") self.timings = defaultdict(tuple) self.__collect_tests()
def __init__(self): self.client = Client(config.get('aws','access_key_id'), config.get('aws','secret_access_key') )
class TestCloudCache: def __init__(self): self.client = Client(config.get('aws','access_key_id'), config.get('aws','secret_access_key') ) def rand_data(self,count=100): return "".join([chr(random.randint(48,122)) for i in lrange(count)]) def rand_name(self): return hashlib.md5("%s"%time.time()).hexdigest() def get_key(self,key,data_in): data_out = self.client.get(key) assert data_out == data_in def test_string(self): "Test put/get string" for size in (0,1,2,3,4,5,10,15,20): data_in = self.rand_data(2**size) key = self.rand_name() assert self.client.put(key,data_in,60,True) == True yield self.get_key, key, data_in def test_int(self): "Test put/get int" data_in = random.randint(0,2**32) key = self.rand_name() assert self.client.put(key,data_in,60,True) == True yield self.get_key, key, data_in def test_long(self): "Test put/get for long" data_in = random.randint(2**32,2**64) key = self.rand_name() assert self.client.put(key,data_in,60,True) == True yield self.get_key, key, data_in def test_dict(self): "Test put/get for dictionary" data_in = {} for i in range(10): data_in[self.rand_name()] = self.rand_data(512) key = self.rand_name() assert self.client.put(key,data_in,60,True) == True yield self.get_key, key, data_in def test_unicode(self): "Test put/get for unicode string" data_in = "¡Ünîcø∂é, bítçh!" key = self.rand_name() assert self.client.put(key,data_in,60,True) == True yield self.get_key, key, data_in def test_timeout(self): "Test timeout" data_in = "Some Awesome Data" key = self.rand_name() assert self.client.put(key,data_in,1,True) == True time.sleep(2) data_out = self.client.get(key) assert data_out == None def test_replace_false(self): "Test replace of key" data_in = "Some Awesome Data" key = self.rand_name() assert self.client.put(key,data_in,60,True) == True data_in1 = "Some other data" assert self.client.put(key,data_in1,60,False) == True data_out = self.client.get(key) assert data_out == data_in def test_replace_true(self): "Test replace of key" data_in = "Some Awesome Data" key = self.rand_name() assert self.client.put(key,data_in,60,True) == True data_in1 = "Some other data" assert self.client.put(key,data_in1,60,True) == True data_out = self.client.get(key) assert data_out == data_in1
class CloudCacheBenchmark: """ Test runner for CloudCached benchmarks Test should be named 'test_%method_%name' where the method is one of get, put, delete, update. Any custom methods should be added to self.test_types and can be run manually with the run_tests method. """ def __init__(self): self.client = Client(config.get("aws", "access_key_id"), config.get("aws", "secret_access_key")) self.key = hashlib.md5("CloudCacheTest").hexdigest() self.tests = defaultdict(list) self.test_types = ("put", "get") self.timings = defaultdict(tuple) self.__collect_tests() def __collect_tests(self): # Collect tests for method in dir(self): if method[0:5] == "test_": match = re.match(r"test_(\w+?)_.*", method) if match and match.group(1) in self.test_types: self.tests[match.group(1)] += [method] def __run_test(self, test, n): test_base = test[test.find("_", 5) + 1 :] print "Running %s (%s iterations)" % (test, n), t1 = time.time() for i in range(n): print ".", key = "%s_%s_%s" % (self.key, test_base, i) getattr(self, test)(key) t2 = time.time() print "" self.timings[test] = ((t2 - t1) / n, (t2 - t1)) def run_tests(self, method=None, n=10): if method: for test in self.tests[method]: self.__run_test(test, n) # Run PUT tests first for test in self.tests["put"]: self.__run_test(test, n) # Then GETs for test in self.tests["get"]: self.__run_test(test, n) def test_put_small_string(self, key): data = "1" * 32 self.client.put(key, data, 3600, True) # def test_put_large_string(self,key): # data = "1"*524288 # self.client.put(key,data,3600,True) def test_put_int(self, key): data = random.randint(0, 2 ** 30) self.client.put(key, data, 3600, True) def test_get_small_string(self, key): self.client.get(key) # def test_get_large_string(self,key): # self.client.get(key) def test_get_int(self, key): self.client.get(key)