コード例 #1
0
    def test_read(self):
        recorder = SQLiteProcessRecorder(SQLiteDatastore(":memory:"))
        recorder.create_table()

        # Construct notification log.
        notification_log = LocalNotificationLog(recorder, section_size=5)
        reader = NotificationLogReader(notification_log, section_size=10)
        notifications = list(reader.read(start=1))
        self.assertEqual(len(notifications), 0)

        # Write 5 events.
        originator_id = uuid4()
        for i in range(5):
            stored_event = StoredEvent(
                originator_id=originator_id,
                originator_version=i,
                topic="topic",
                state=b"state",
            )
            recorder.insert_events(
                [stored_event],
            )

        notifications = list(reader.read(start=1))
        self.assertEqual(len(notifications), 5)

        # Write 4 events.
        originator_id = uuid4()
        for i in range(4):
            stored_event = StoredEvent(
                originator_id=originator_id,
                originator_version=i,
                topic="topic",
                state=b"state",
            )
            recorder.insert_events([stored_event])

        notifications = list(reader.read(start=1))
        self.assertEqual(len(notifications), 9)

        notifications = list(reader.read(start=2))
        self.assertEqual(len(notifications), 8)

        notifications = list(reader.read(start=3))
        self.assertEqual(len(notifications), 7)

        notifications = list(reader.read(start=4))
        self.assertEqual(len(notifications), 6)

        notifications = list(reader.read(start=8))
        self.assertEqual(len(notifications), 2)

        notifications = list(reader.read(start=9))
        self.assertEqual(len(notifications), 1)

        notifications = list(reader.read(start=10))
        self.assertEqual(len(notifications), 0)
コード例 #2
0
def main():
    record = Record()
    ben = record.create_person()
    record.deal_with_life(ben, 'school')
    record.deal_with_life(ben, 'friend')
    assert record.view_life(ben) == ['school', 'friend']

    alex = record.create_person()
    assert alex != ben
    record.deal_with_life(alex, 'girl')
    assert record.view_life(alex) == ['girl']

    # Create event notification
    reader = NotificationLogReader(record.log)
    notifications = list(reader.read(start=1))
    assert len(notifications) == 5
    print(notifications)
    for notification in notifications:
        print(notification_to_table(notification))