def on_message_out(self, tp: TP, offset: int, message: Message) -> None: """Call when message is fully acknowledged and can be committed.""" self.messages_active -= 1 time_out = message.time_out = self.time() time_in = message.time_in if time_in is not None: message.time_total = time_out - time_in
def on_message_in(self, tp: TP, offset: int, message: Message) -> None: # WARNING: Sensors must never keep a reference to the Message, # as this means the message won't go out of scope! self.messages_received_total += 1 self.messages_active += 1 self.messages_received_by_topic[tp.topic] += 1 self.tp_read_offsets[tp] = offset message.time_in = self.time()
def test_value_serde(app, topic): v = Person("Unit Test", 0, datetime(1970, 1, 1, 0, 0, 0, 0, timezone.utc)) payload, headers = topic.prepare_value(v, None) message = Message("ut-topic", 0, 0, 0, 0, None, None, payload, None) record = topic.schema.loads_value(app, message) assert_that(v).is_equal_to(record)
def test_key_serde(app, topic): k = Key(1) payload, headers = topic.prepare_key(k, None) message = Message("ut-topic", 0, 0, 0, 0, None, payload, None, None) record = topic.schema.loads_key(app, message) assert_that(k).is_equal_to(record)
def on_message_out(self, tp: TP, offset: int, message: Message) -> None: self.messages_active -= 1 time_out = message.time_out = self.time() time_in = message.time_in if time_in is not None: message.time_total = time_out - time_in
def message(key=None, value=None, *, topic='topic', partition=0, offset=1, checksum=None): return Message( key=key, value=value, topic=topic, partition=partition, offset=offset, timestamp=time(), timestamp_type='epoch', checksum=checksum, )
def message(key=None, value=None, *, topic='topic', partition=0, timestamp=None, headers=None, offset=1, checksum=None): return Message( key=key, value=value, topic=topic, partition=partition, offset=offset, timestamp=timestamp or time(), timestamp_type=1 if timestamp else 0, headers=headers, checksum=checksum, )
def test_garbage(app, topic): message = Message("ut-topic", 0, 0, 0, 0, None, None, b"failure", None) with pytest.raises(ValueDecodeError): topic.schema.loads_value(app, message)