def test_partition_from_file(tmpdir): partition = Partition( 'topic_name_1', 1, [Message(1, 'Key', 'Message_1', 123456789)]) file_path = os.path.join(tmpdir, 'topic_name_1_1.sqlite3') partition.to_file(file_path) from_file_partition = Partition.from_file(file_path) assert from_file_partition.topic == partition.topic assert from_file_partition.name == partition.name assert from_file_partition.messages == partition.messages
def read( self, topics: Optional[List[str]] = None ) -> Tuple[List[Offset], List[Partition]]: partitions = [] for file_name in os.listdir(self.partition_file_dir): if not file_name.endswith('sqlite3'): continue file_path = os.path.join(self.partition_file_dir, file_name) partition = Partition.from_file(file_path) logger.debug(f'Read {len(partition.messages)} for topic: ' f'{partition.topic} partition: {partition.name} ' 'from disk') # TODO: Consider using filename as filter or Write required # metadata about filename and topic/partition in one main sqlite3 # file. if topics and partition.topic not in topics: continue partitions.append(partition) offset_manager = OffsetManager.from_file(self.offset_file_path) if topics: offsets = [o for o in offset_manager.offsets if o.topic in topics] offsets = offset_manager.offsets return (offsets, partitions)