示例#1
0
def list_event_stream(draw):
    stream = ListEventStream(draw(some_events(min_size=1)))

    # Get some timestamps stats
    events = stream.events
    min_ts = min(ev.timestamp for ev in events)
    max_ts = max(ev.timestamp for ev in events)
    duration = max_ts - min_ts

    # Add some random out of order events
    start_ts = min_ts - duration
    max_size = MAX_EVENTS_SIZE // 5
    max_interval = 3 * duration // max_size  # So that events are generated in range [min_ts-duration, max_ts+duration]
    more_events = draw(
        some_events(min_size=1,
                    max_size=max_size,
                    min_interval=max_interval // 5,
                    max_interval=max_interval,
                    start_ts=start_ts))
    shuffle(more_events)
    stream.extend(more_events)

    # Generate events
    input = stream.events
    events = draw(sim_event_stream(stream, max_size=MAX_EVENTS_SIZE))
    return input, events
示例#2
0
class RandomErrorModel(SimModel):
    def __init__(self):
        self.processed_events = []
        self._events = st.one_of(st.just(ErrorEvent(reason="random")),
                                 some_event())
        self._outbox = ListEventStream()
        self._error_status = None

    def process(self, draw, event: SimEvent):
        self.processed_events.append(event)
        if isinstance(event.payload, ErrorEvent):
            self._error_status = 'Has error'
        ts = event.timestamp
        delays = draw(st.lists(elements=st.integers(min_value=1, max_value=1000)))
        self._outbox.extend(SimEvent(timestamp=ts + delay, payload=draw(self._events)) for delay in delays)

    def outbox(self):
        return self._outbox

    def error_status(self) -> Optional[str]:
        pass