def test_chunk_from_lower_layer(self): """test receiving metadata from lower layer""" self.chunkLayer.start_process() n1 = Name("/test/data") re1 = RequestTableEntry(n1) re1.chunked = True chunk1_n = Name("/test/data/c0") chunk2_n = Name("/test/data/c1") chunk1 = Content(chunk1_n, "chunk1") chunk2 = Content(chunk2_n, "chunk2") re1.requested_chunks.append(chunk1_n) re1.requested_chunks.append(chunk2_n) self.chunkLayer._request_table.append(re1) self.chunkLayer.queue_from_lower.put([0, chunk2]) time.sleep(1) self.assertTrue(self.chunkLayer.queue_to_higher.empty()) self.chunkLayer.queue_from_lower.put([0, chunk1]) try: data = self.chunkLayer.queue_to_higher.get(timeout=2.0) except: self.fail() self.assertEqual(data[1].content, "chunk1chunk2")
def test_handle_received_chunk_data(self): """test if received chunk data are handled correctly""" self.chunkLayer.start_process() n1 = Name("/test/data") chunk1_n = Name("/test/data/c0") chunk2_n = Name("/test/data/c1") request_table_entry = RequestTableEntry(n1) request_table_entry.chunked = True request_table_entry.requested_chunks.append(chunk1_n) request_table_entry.requested_chunks.append(chunk2_n) chunk1 = Content(chunk1_n, "chunk1") chunk2 = Content(chunk2_n, "chunk2") request_table_entry = self.chunkLayer.handle_received_chunk_data( 0, chunk1, request_table_entry, self.q1_to_higher) self.assertEqual(request_table_entry.requested_chunks, [chunk2_n]) request_table_entry = self.chunkLayer.handle_received_chunk_data( 0, chunk2, request_table_entry, self.q1_to_higher) self.assertEqual(request_table_entry, None) try: data = self.q1_to_higher.get(timeout=2.0)[1] except: self.fail() self.assertEqual(data.name, n1) self.assertEqual(data.content, "chunk1chunk2") self.assertEqual(len(self.chunkLayer._request_table), 0)