|
|
|
|
|
from random import random |
|
|
|
from petrel_client.client import Client |
|
from petrel_client.fake_client import FakeClient |
|
|
|
|
|
def customized_get(self, *args, **kwargs): |
|
|
|
if self.type == 's3': |
|
|
|
cluster, bucket, key = args |
|
else: |
|
|
|
cluster, bucket, key = 'unknow', 'unknow', args[0] |
|
|
|
if self.type == 'mc' and random() < 0.5: |
|
|
|
return None |
|
else: |
|
return b'x' * 1024 |
|
|
|
|
|
def customized_put(self, *args, **kwargs): |
|
if self.type == 's3': |
|
|
|
cluster, bucket, key, body = args |
|
else: |
|
|
|
cluster, bucket, (key, body) = 'unknow', 'unknow', args |
|
|
|
return len(body) |
|
|
|
|
|
FakeClient.customized_get = customized_get |
|
FakeClient.customized_put = customized_put |
|
|
|
client = Client("~/fake_client.conf") |
|
|
|
urls = [ |
|
'cluster1:s3://my-bucket/object.1', |
|
'cluster2:s3://my-bucket/object.2', |
|
's3://my-bucket/object.3', |
|
'file://tmp/xxx', |
|
'/tmp/xxx', |
|
] |
|
|
|
for _ in range(1000): |
|
for url in urls: |
|
client.get(url) |
|
|