def option_parser_for_serial_mix(): op = memcached_workload_common.option_parser_for_memcache() op["keysize"] = IntFlag("--keysize", 250) op["valuesize"] = IntFlag("--valuesize", 10000) op["thorough"] = BoolFlag("--thorough") def int_or_forever_parser(string): if string == "forever": return "forever" else: try: return int(string) except ValueError: raise OptError("expected 'forever' or integer, got %r" % string) op["duration"] = ValueFlag("--duration", converter = int_or_forever_parser, default = 10) return op
#!/usr/bin/python # Copyright 2010-2012 RethinkDB, all rights reserved. from random import shuffle import sys, os sys.path.append( os.path.abspath( os.path.join(os.path.dirname(__file__), os.path.pardir, 'common'))) import memcached_workload_common from vcoptparse import * op = memcached_workload_common.option_parser_for_memcache() del op["mclib"] # No longer optional; we only work with memcache. op["num_ints"] = IntFlag("--num-ints", 10) opts = op.parse(sys.argv) opts["mclib"] = "memcache" with memcached_workload_common.make_memcache_connection(opts) as mc: print "Shuffling numbers" ints = range(0, opts["num_ints"]) shuffle(ints) # flag values are: # - 0 for strings # - 2 for ints print "Testing with flags" for i in ints: print "Inserting %d" % i if i % 2: val = str(i) else: val = i
typical_test(mc, "b", t, 1, 4) print " Done absolute_test." # Tests a relative timestamp 5 seconds from now. def basic_test(mc): print "basic_test..." typical_test(mc, "a", 5, 1, 4) print " Done basic_test." # Tests an expiration time that's already in the past. def past_test(mc): print "past_test..." expect(mc.set("p", "aaa", time=int(time.time()) - 5) == 1, "Set failed") print " Make sure we can't get the element back." expect(mc.get("p") == None, "Wait, we got a value?!") print " Done past_test." op = memcached_workload_common.option_parser_for_memcache() opts = op.parse(sys.argv) with memcached_workload_common.make_memcache_connection(opts) as mc: zero_test(mc) basic_test(mc) absolute_test(mc) past_test(mc) print "Done"