Ejemplo n.º 1
0
def test_value_deserialize_missing_magicbyte(employee_schema,
                                             employee_avro_data):
    with patch(SCHEMA_REGISTRY_CLS) as mock:
        sr = _schema_registry_mock(mock)
        avro_serde = AvroKeyValueSerde(sr, TOPIC)
        with pytest.raises(MessageParsingError):
            avro_serde.value.deserialize(employee_avro_data)
Ejemplo n.º 2
0
def test_cached_encoder_success(encoder_mock, employee_schema,
                                employee_avro_wire_format, employee_json_data):
    with patch(SCHEMA_REGISTRY_CLS) as mock:
        schema_id = 45
        sr = _schema_registry_mock(mock, schema_id, employee_schema)
        avro_serde = AvroKeyValueSerde(sr, TOPIC)
        avro_serde.value.serialize(employee_json_data, employee_schema)
        avro_serde.value.serialize(employee_json_data, employee_schema)
        encoder_mock.assert_called_once()
Ejemplo n.º 3
0
def test_value_serialize_incompatible_change(employee_schema,
                                             employee_avro_wire_format,
                                             employee_json_data):
    with patch(SCHEMA_REGISTRY_CLS) as mock:
        sr = _schema_registry_mock(mock)
        sr.register_schema.side_effect = IncompatibleSchemaVersion({})
        avro_serde = AvroKeyValueSerde(sr, TOPIC)
        with pytest.raises(IncompatibleSchemaVersion):
            avro_serde.value.serialize(employee_json_data, employee_schema)
Ejemplo n.º 4
0
def test_value_deserialize_success(employee_schema, employee_avro_wire_format,
                                   employee_json_data):
    with patch(SCHEMA_REGISTRY_CLS) as mock:
        schema_id = 23
        sr = _schema_registry_mock(mock, schema_id, employee_schema)
        avro_serde = AvroKeyValueSerde(sr, TOPIC)
        employee_avro_data = employee_avro_wire_format(schema_id)
        decoded_data = avro_serde.value.deserialize(employee_avro_data)
        assert decoded_data == employee_json_data
Ejemplo n.º 5
0
from pathlib import Path
import time
import random

from kafka import KafkaProducer

from confluent_avro.schema_registry import SchemaRegistry
from confluent_avro.serde import AvroKeyValueSerde

SCHEMA_REGISTRY_URL = "http://localhost:8081"
KAFKA_TOPIC = "telecom_italia_data"
BASE_DIR = Path(__file__).parent

registry_client = SchemaRegistry(SCHEMA_REGISTRY_URL)
avro_serde = AvroKeyValueSerde(registry_client, KAFKA_TOPIC)
kafka_producer = KafkaProducer(bootstrap_servers=["localhost:9092"])

records = [{
    "key": {
        "SquareId": i
    },
    "value": {
        "SquareId": i,
        "TimeInterval": int(time.time()),
        "CountryCode": random.randint(1, 50),
        "SmsInActivity": random.uniform(0.001, 0.09),
        "SmsOutActivity": random.uniform(0.001, 0.09),
        "CallInActivity": None,
        "CallOutActivity": None,
        "InternetTrafficActivity": None
    }