def test_delayed_start(self): num_objects = 10 # Create some objects using one client. object_ids = [random_object_id() for _ in range(num_objects)] for i in range(10): create_object_with_id(self.client, object_ids[i], 2000, 2000) # Wait until the objects have been sealed in the store. ready, waiting = self.client.wait(object_ids, num_returns=num_objects) self.assertEqual(set(ready), set(object_ids)) self.assertEqual(waiting, []) # Start a second plasma manager attached to the same store. manager_name, self.p5, self.port2 = plasma.start_plasma_manager(self.store_name, self.redis_address, use_valgrind=USE_VALGRIND) self.processes_to_kill.append(self.p5) # Check that the second manager knows about existing objects. client2 = plasma.PlasmaClient(self.store_name, manager_name) ready, waiting = [], object_ids while True: ready, waiting = client2.wait(object_ids, num_returns=num_objects, timeout=0) if len(ready) == len(object_ids): break self.assertEqual(set(ready), set(object_ids)) self.assertEqual(waiting, [])
def test_fetch(self): for _ in range(10): # Create an object. object_id1, memory_buffer1, metadata1 = create_object( self.client1, 2000, 2000) self.client1.fetch([object_id1]) self.assertEqual(self.client1.contains(object_id1), True) self.assertEqual(self.client2.contains(object_id1), False) # Fetch the object from the other plasma manager. # TODO(rkn): Right now we must wait for the object table to be updated. while not self.client2.contains(object_id1): self.client2.fetch([object_id1]) # Compare the two buffers. assert_get_object_equal(self, self.client1, self.client2, object_id1, memory_buffer=memory_buffer1, metadata=metadata1) # Test that we can call fetch on object IDs that don't exist yet. object_id2 = random_object_id() self.client1.fetch([object_id2]) self.assertEqual(self.client1.contains(object_id2), False) memory_buffer2, metadata2 = create_object_with_id( self.client2, object_id2, 2000, 2000) # # Check that the object has been fetched. # self.assertEqual(self.client1.contains(object_id2), True) # Compare the two buffers. # assert_get_object_equal(self, self.client1, self.client2, object_id2, # memory_buffer=memory_buffer2, metadata=metadata2) # Test calling the same fetch request a bunch of times. object_id3 = random_object_id() self.assertEqual(self.client1.contains(object_id3), False) self.assertEqual(self.client2.contains(object_id3), False) for _ in range(10): self.client1.fetch([object_id3]) self.client2.fetch([object_id3]) memory_buffer3, metadata3 = create_object_with_id( self.client1, object_id3, 2000, 2000) for _ in range(10): self.client1.fetch([object_id3]) self.client2.fetch([object_id3]) #TODO(rkn): Right now we must wait for the object table to be updated. while not self.client2.contains(object_id3): self.client2.fetch([object_id3]) assert_get_object_equal(self, self.client1, self.client2, object_id3, memory_buffer=memory_buffer3, metadata=metadata3)
def test_get(self): num_object_ids = 100 # Test timing out of get with various timeouts. for timeout in [0, 10, 100, 1000]: object_ids = [random_object_id() for _ in range(num_object_ids)] results = self.plasma_client.get(object_ids, timeout_ms=timeout) self.assertEqual(results, num_object_ids * [None]) data_buffers = [] metadata_buffers = [] for i in range(num_object_ids): if i % 2 == 0: data_buffer, metadata_buffer = create_object_with_id(self.plasma_client, object_ids[i], 2000, 2000) data_buffers.append(data_buffer) metadata_buffers.append(metadata_buffer) # Test timing out from some but not all get calls with various timeouts. for timeout in [0, 10, 100, 1000]: data_results = self.plasma_client.get(object_ids, timeout_ms=timeout) metadata_results = self.plasma_client.get(object_ids, timeout_ms=timeout) for i in range(num_object_ids): if i % 2 == 0: self.assertTrue(plasma.buffers_equal(data_buffers[i // 2], data_results[i])) # TODO(rkn): We should compare the metadata as well. But currently the # types are different (e.g., memoryview versus bytearray). # self.assertTrue(plasma.buffers_equal(metadata_buffers[i // 2], metadata_results[i])) else: self.assertIsNone(results[i])
def test_wait(self): # Test timeout. obj_id0 = random_object_id() self.client1.wait([obj_id0], timeout=100, num_returns=1) # If we get here, the test worked. # Test wait if local objects available. obj_id1 = random_object_id() self.client1.create(obj_id1, 1000) self.client1.seal(obj_id1) ready, waiting = self.client1.wait([obj_id1], timeout=100, num_returns=1) self.assertEqual(set(ready), set([obj_id1])) self.assertEqual(waiting, []) # Test wait if only one object available and only one object waited for. obj_id2 = random_object_id() self.client1.create(obj_id2, 1000) # Don't seal. ready, waiting = self.client1.wait([obj_id2, obj_id1], timeout=100, num_returns=1) self.assertEqual(set(ready), set([obj_id1])) self.assertEqual(set(waiting), set([obj_id2])) # Test wait if object is sealed later. obj_id3 = random_object_id() def finish(): self.client2.create(obj_id3, 1000) self.client2.seal(obj_id3) t = threading.Timer(0.1, finish) t.start() ready, waiting = self.client1.wait([obj_id3, obj_id2, obj_id1], timeout=1000, num_returns=2) self.assertEqual(set(ready), set([obj_id1, obj_id3])) self.assertEqual(set(waiting), set([obj_id2])) # Test if the appropriate number of objects is shown if some objects are not ready ready, waiting = self.client1.wait([obj_id3, obj_id2, obj_id1], 100, 3) self.assertEqual(set(ready), set([obj_id1, obj_id3])) self.assertEqual(set(waiting), set([obj_id2])) # Don't forget to seal obj_id2. self.client1.seal(obj_id2) # Test calling wait a bunch of times. object_ids = [] # TODO(rkn): Increasing n to 100 (or larger) will cause failures. The # problem appears to be that the number of timers added to the manager event # loop slow down the manager so much that some of the asynchronous Redis # commands timeout triggering fatal failure callbacks. n = 40 for i in range(n * (n + 1) // 2): if i % 2 == 0: object_id, _, _ = create_object(self.client1, 200, 200) else: object_id, _, _ = create_object(self.client2, 200, 200) object_ids.append(object_id) # Try waiting for all of the object IDs on the first client. waiting = object_ids retrieved = [] for i in range(1, n + 1): ready, waiting = self.client1.wait(waiting, timeout=1000, num_returns=i) self.assertEqual(len(ready), i) retrieved += ready self.assertEqual(set(retrieved), set(object_ids)) ready, waiting = self.client1.wait(object_ids, timeout=1000, num_returns=len(object_ids)) self.assertEqual(set(ready), set(object_ids)) self.assertEqual(waiting, []) # Try waiting for all of the object IDs on the second client. waiting = object_ids retrieved = [] for i in range(1, n + 1): ready, waiting = self.client2.wait(waiting, timeout=1000, num_returns=i) self.assertEqual(len(ready), i) retrieved += ready self.assertEqual(set(retrieved), set(object_ids)) ready, waiting = self.client2.wait(object_ids, timeout=1000, num_returns=len(object_ids)) self.assertEqual(set(ready), set(object_ids)) self.assertEqual(waiting, []) # Make sure that wait returns when the requested number of object IDs are # available and does not wait for all object IDs to be available. object_ids = [random_object_id() for _ in range(9)] + [20 * b'\x00'] object_ids_perm = object_ids[:] random.shuffle(object_ids_perm) for i in range(10): if i % 2 == 0: create_object_with_id(self.client1, object_ids_perm[i], 2000, 2000) else: create_object_with_id(self.client2, object_ids_perm[i], 2000, 2000) ready, waiting = self.client1.wait(object_ids, num_returns=(i + 1)) self.assertEqual(set(ready), set(object_ids_perm[:(i + 1)])) self.assertEqual(set(waiting), set(object_ids_perm[(i + 1):]))