make ObjectID pickleable

This commit is contained in:
Philipp Moritz committed 2017-07-19 10:06:32 -07:00
1 parent dd5a7d8895
commit 3021d596da
2 files changed
+17 -1

No files matched your search

+9 -1
View File
@@ -45,7 +45,9 @@ cdef extern from "plasma/common.h" nogil:
c_bool operator==(const CUniqueID& rhs) const
c_string hex()
c_string hex() const
c_string binary() const
cdef extern from "plasma/plasma.h":
cdef int64_t kDigestSize" plasma::kDigestSize"
@@ -87,6 +89,9 @@ cdef extern from "plasma/client.h" nogil:
int64_t metadata_size
uint8_t* metadata
def make_object_id(object_id):
return ObjectID(object_id)
cdef class ObjectID:
cdef:
@@ -102,6 +107,9 @@ cdef class ObjectID:
def __repr__(self):
return "ObjectID(" + self.data.hex().decode() + ")"
def __reduce__(self):
return (make_object_id, (self.data.binary(),))
cdef class PlasmaBuffer(Buffer):
"""This is the type of objects returned by calls to get with a PlasmaClient.
+8
View File
@@ -250,6 +250,14 @@ class TestPlasmaClient(unittest.TestCase):
else:
self.assertIsNone(results[i])
def test_pickle_object_ids(self):
# This can be used for sharing object IDs between processes.
import pickle
object_id = random_object_id()
data = pickle.dumps(object_id)
object_id2 = pickle.loads(data)
self.assertEqual(object_id, object_id2)
def test_store_full(self):
# The store is started with 1GB, so make sure that create throws an
# exception when it is full.