def seq1(keys, values, repeat):
    if PRINT_SEQUENCES:
        print(
            "--- SEQUENCE 1 repeat %-3s -----------------------------------------------------"
            % repeat)
    kv_pairs = []
    for key in keys:
        for value in values:
            kv_pairs.append(memlib.kv_pair(key, value, "EFBEADDE", 42))

    requests = []
    responses = []
    for kv_pair in kv_pairs:
        if PRINT_SEQUENCES:
            print("Set [%d -> %d]: %s -> %s" %
                  (len(kv_pair['key']), len(
                      kv_pair['value']), kv_pair['key'], kv_pair['value']))
        requests.append(memlib.binarySetRequest(kv_pair, "00000000"))
        responses.append(memlib.binarySetResponse(kv_pair, "00000000"))

        for _ in range(repeat):
            if PRINT_SEQUENCES:
                print("Get [%d -> %d]: %s -> %s" %
                      (len(kv_pair['key']), len(
                          kv_pair['value']), kv_pair['key'], kv_pair['value']))
            requests.append(memlib.binaryGetRequest(kv_pair, "00000000"))
            responses.append(memlib.binaryGetResponse(kv_pair, "00000000"))

    return (requests, responses)
def seq2(keys, values):
	if PRINT_SEQUENCES:
		print "--- SEQUENCE 2 -----------------------------------------------------------------"
	requests = []
	responses = []
	for _ in range(len(values)):
		# for more keys than values, duplicate use of values
		values_used = values
		if len(keys) > len(values):
			while(len(keys) > len(values_used)):
				values_used = values_used + values
			values_used = values_used[0:len(keys)]

		# requests
		kv_pairs = map(pair2kvpair, zip(keys, values_used))
		for kv_pair in kv_pairs:
			if PRINT_SEQUENCES:
				print "Set [%d -> %d]: %s -> %s" % (len(kv_pair['key']), len(kv_pair['value']), kv_pair['key'], kv_pair['value'])
			requests.append( memlib.binarySetRequest(kv_pair, "00000000") )
			responses.append( memlib.binarySetResponse(kv_pair, "00000000") )
		for kv_pair in kv_pairs:
			if PRINT_SEQUENCES:
				print "Get [%d -> %d]: %s -> %s" % (len(kv_pair['key']), len(kv_pair['value']), kv_pair['key'], kv_pair['value'])
			requests.append( memlib.binaryGetRequest(kv_pair, "00000000") )
			responses.append( memlib.binaryGetResponse(kv_pair, "00000000") )

		# rotation
		values = values[1:] + values[0:1]
	
	return (requests, responses)
示例#3
0
def seq2(keys, values):
    if PRINT_SEQUENCES:
        print "--- SEQUENCE 2 -----------------------------------------------------------------"
    requests = []
    responses = []
    for _ in range(len(values)):
        # for more keys than values, duplicate use of values
        values_used = values
        if len(keys) > len(values):
            while (len(keys) > len(values_used)):
                values_used = values_used + values
            values_used = values_used[0:len(keys)]

        # requests
        kv_pairs = map(pair2kvpair, zip(keys, values_used))
        for kv_pair in kv_pairs:
            if PRINT_SEQUENCES:
                print "Set [%d -> %d]: %s -> %s" % (len(
                    kv_pair['key']), len(
                        kv_pair['value']), kv_pair['key'], kv_pair['value'])
            requests.append(memlib.binarySetRequest(kv_pair, "00000000"))
            responses.append(memlib.binarySetResponse(kv_pair, "00000000"))
        for kv_pair in kv_pairs:
            if PRINT_SEQUENCES:
                print "Get [%d -> %d]: %s -> %s" % (len(
                    kv_pair['key']), len(
                        kv_pair['value']), kv_pair['key'], kv_pair['value'])
            requests.append(memlib.binaryGetRequest(kv_pair, "00000000"))
            responses.append(memlib.binaryGetResponse(kv_pair, "00000000"))

        # rotation
        values = values[1:] + values[0:1]

    return (requests, responses)
示例#4
0
def generateMemcached(cfg):
    """Generate a memcached request and resonse."""
    request = ""
    response = ""

    if cfg['type'] == "set":
        if cfg['protocol'] == "binary":
            request = memlib.binarySetRequest(cfg, cfg['opaque'])
            response = memlib.binarySetResponse(cfg, cfg['opaque'])
        else:
            request = memlib.textSetRequest(cfg)
            response = memlib.textSetResponse(cfg)

    elif cfg['type'] == "get":
        if cfg['protocol'] == "binary":
            request = memlib.binaryGetRequest(cfg, cfg['opaque'])
            if cfg['success'] == "yes":
                response = memlib.binaryGetResponse(cfg, cfg['opaque'])
            else:
                response = memlib.binaryFailedGetResponse(cfg['opaque'])
        else:
            request = memlib.textGetRequest(cfg)
            if cfg['success'] == "yes":
                response = memlib.textGetResponse(cfg)
            else:
                response = memlib.textFailedGetResponse()

    elif cfg['type'] == "delete":
        if cfg['protocol'] == "binary":
            request = memlib.binaryDeleteRequest(cfg, cfg['opaque'])
            if cfg['success'] == "yes":
                response = memlib.binaryDeleteResponse(cfg, cfg['opaque'])
            else:
                response = memlib.binaryFailedDeleteResponse(
                    cfg, cfg['opaque'])
        else:
            request = memlib.textDeleteRequest(cfg)
            if cfg['success'] == "yes":
                response = memlib.textDeleteResponse(cfg)
            else:
                response = memlib.textFailedDeleteResponse(cfg)

    elif cfg['type'] == "flush":
        if cfg['protocol'] == "binary":
            request = memlib.binaryFlushRequest(opaque=cfg['opaque'])
            response = memlib.binaryFlushResponse(cfg['opaque'])
        else:
            request = memlib.textFlushRequest()
            response = memlib.textFlushResponse()

    if cfg['protocol'] == "mixed":
        request = memlib.text2mixed(request, cfg['request-id'])
        response = memlib.text2mixed(response, cfg['request-id'])

    return (request.decode('hex'), response.decode('hex'))
def generateMemcached(cfg):
	"""Generate a memcached request and resonse."""
	request  = ""
	response = ""

	if cfg['type'] == "set":
		if cfg['protocol'] == "binary":
			request  = memlib.binarySetRequest(cfg, cfg['opaque'])
			response = memlib.binarySetResponse(cfg, cfg['opaque'])
		else:
			request  = memlib.textSetRequest(cfg)
			response = memlib.textSetResponse(cfg)

	elif cfg['type'] == "get":
		if cfg['protocol'] == "binary":
			request  = memlib.binaryGetRequest(cfg, cfg['opaque'])
			if cfg['success'] == "yes":
				response = memlib.binaryGetResponse(cfg, cfg['opaque'])
			else:
				response = memlib.binaryFailedGetResponse(cfg['opaque'])
		else:
			request  = memlib.textGetRequest(cfg)
			if cfg['success'] == "yes":
				response = memlib.textGetResponse(cfg)
			else:
				response = memlib.textFailedGetResponse()

	elif cfg['type'] == "delete":
		if cfg['protocol'] == "binary":
			request  = memlib.binaryDeleteRequest(cfg, cfg['opaque'])
			if cfg['success'] == "yes":
				response = memlib.binaryDeleteResponse(cfg, cfg['opaque'])
			else:
				response = memlib.binaryFailedDeleteResponse(cfg, cfg['opaque'])
		else:
			request  = memlib.textDeleteRequest(cfg)
			if cfg['success'] == "yes":
				response = memlib.textDeleteResponse(cfg)
			else:
				response = memlib.textFailedDeleteResponse(cfg)

	elif cfg['type'] == "flush":
		if cfg['protocol'] == "binary":
			request  = memlib.binaryFlushRequest(opaque=cfg['opaque'])
			response = memlib.binaryFlushResponse(cfg['opaque'])
		else:
			request  = memlib.textFlushRequest()
			response = memlib.textFlushResponse()

	if cfg['protocol'] == "mixed":
		request  = memlib.text2mixed(request, cfg['request-id'])
		response = memlib.text2mixed(response, cfg['request-id'])
	
	return (request.decode('hex'), response.decode('hex'))
def seq1(keys, values, repeat):
	if PRINT_SEQUENCES:
		print "--- SEQUENCE 1 repeat %-3s -----------------------------------------------------" % repeat
	kv_pairs = []
	for key in keys:
		for value in values:
			kv_pairs.append( memlib.kv_pair(key, value, "EFBEADDE", 42) )

	requests = []
	responses = []
	for kv_pair in kv_pairs:
		if PRINT_SEQUENCES:
			print "Set [%d -> %d]: %s -> %s" % (len(kv_pair['key']), len(kv_pair['value']), kv_pair['key'], kv_pair['value'])
		requests.append( memlib.binarySetRequest( kv_pair , "00000000" ) )
		responses.append( memlib.binarySetResponse( kv_pair, "00000000" ) )

		for _ in range(repeat):
			if PRINT_SEQUENCES:
				print "Get [%d -> %d]: %s -> %s" % (len(kv_pair['key']), len(kv_pair['value']), kv_pair['key'], kv_pair['value'])
			requests.append( memlib.binaryGetRequest( kv_pair , "00000000"  ) )
			responses.append( memlib.binaryGetResponse( kv_pair , "00000000" ) )

	return (requests, responses)
示例#7
0
ShortTest = memlib.kv_pair("k", "v", "DEADBEEF", 42)

# V2
Integration1 = {
    "key":
    "this-is-the-key-that-i'll-be-using-for-the-next-time-to-test-the-longest-of-all-keys",
    "value":
    "aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhhiiiiiiiijjjjjjjjkkkkkkkkllllllllmmmmmmmmnnnnnnnnooooooooppppppppqqqqqqqqrrrrrrrrssssssssttttttttuuuuuuuuvvvvvvvvwwwwwwwwxxxxxxxxyyyyyyyyzzzzzzzz",
    "flags": "0000002a",  # 32bit, hex-encoded
    "expiration": 13
}

## CREATING SINGLE REQUESTS ####################################################

print "Binary Set Request"
rq = memlib.binarySetRequest(Integration1, "aabbccdd")
print memlib.simulationInput(rq)

print "Binary Set Response"
rq = memlib.binarySetResponse(Integration1, "aabbccdd")
print memlib.simulationOutput(rq)

print "Binary Get Request"
rq = memlib.binaryGetRequest(Integration1, "aabbccdd")
print memlib.simulationInput(rq)

print "2 Binary Get Request w/o delay"
print memlib.simulationInput(rq,
                             False),  # the ',' avoids the newline after print.
print memlib.simulationInput(rq)