import time
import unittest
from memcache_hybrid import DistributedObjectStore
import acl
acl.init()
count, ret = acl.rt.get_device_count()
print("设备数量:", acl.rt.get_device_count())
ret = acl.rt.set_device(count - 1)
print("set_device returned: {}".format(ret))
class TestExample(unittest.TestCase):
key_1 = "key_1"
original_data = b"some data!"
def setUp(self):
self._distributed_object_store = DistributedObjectStore()
res = self._distributed_object_store.init(count - 1)
self.assertEqual(res, 0)
def test_1(self):
exist_res = self._distributed_object_store.is_exist(self.key_1)
self.assertEqual(exist_res, 0)
put_res = self._distributed_object_store.put(self.key_1, self.original_data)
self.assertEqual(put_res, 0)
exist_res = self._distributed_object_store.is_exist(self.key_1)
self.assertEqual(exist_res, 1)
key_info = self._distributed_object_store.get_key_info(self.key_1)
print(key_info)
retrieved_data = self._distributed_object_store.get(self.key_1)
print(retrieved_data)
self.assertEqual(retrieved_data, self.original_data)
time.sleep(3)
rm_res = self._distributed_object_store.remove(self.key_1)
self.assertEqual(rm_res, 0)
exist_res = self._distributed_object_store.is_exist(self.key_1)
self.assertEqual(exist_res, 0)
def tearDown(self):
self._distributed_object_store.close()
print("object store destroyed")
if __name__ == '__main__':
unittest.main()