Пример #1
0
    def test_validate(self):
        last_events = {1: 100}
        collector = EventCollector(self.storage, last_events)

        event = {'event': 'event', 'data': {'_tid': 1, '_last_event': 100}}
        result = collector._validate(event)
        self.assertEqual(result, True)

        event['data']['_last_event'] = 50
        result = collector._validate(event)
        self.assertEqual(result, False)

        event['data']['_tid'] = 2
        result = collector._validate(event)
        self.assertEqual(result, False)
Пример #2
0
def _store_events(storage, last_events, events, stats):
    """Store events in GOB

    Only valid events are stored, other events are skipped (with an associated warning)
    The events are added in bulk in the database

    :param storage: GOB (events + entities)
    :param events: the events to process
    :param stats: update statitics for this action
    :return:
    """
    with ActiveGarbageCollection("Store events"), storage.get_session():
        # Use a session to commit all or rollback on any error
        logger.info("Store events")

        with ProgressTicker("Store events", 10000) as progress, \
                EventCollector(storage, last_events) as event_collector:

            for event in events:
                progress.tick()

                if event_collector.collect(event):
                    stats.store_event(event)
                else:
                    stats.skip_event(event)
Пример #3
0
    def test_validate_bulk(self):
        last_events = {1: 100}
        collector = EventCollector(self.storage, last_events)

        event = {
            'event': 'BULKCONFIRM',
            'data': {
                'confirms': [{
                    '_tid': 1,
                    '_last_event': 100
                }]
            }
        }
        result = collector._validate(event)
        self.assertEqual(result, True)

        event['data']['confirms'][0]['_last_event'] = 50
        result = collector._validate(event)
        self.assertEqual(result, False)

        event['data']['confirms'][0]['_tid'] = 2
        result = collector._validate(event)
        self.assertEqual(result, False)
Пример #4
0
 def test_exit(self):
     EventCollector.MAX_CHUNK = 2
     collector = EventCollector(self.storage, {})
     collector.add_event({'event': 'any event'})
     self.assertEqual(collector.events, [{'event': 'any event'}])
     collector.add_event({'event': 'any event'})
     self.assertEqual(collector.events, [])
     self.storage.add_events.assert_called_with([{
         'event': 'any event'
     }, {
         'event': 'any event'
     }])
Пример #5
0
 def test_add_bulk_event(self):
     collector = EventCollector(self.storage, {})
     collector.add_event({'event': 'BULKCONFIRM'})
     self.assertEqual(collector.events, [])
     print(self.storage.mock_calls)
     self.storage.add_events.assert_called_with([{'event': 'BULKCONFIRM'}])
Пример #6
0
 def test_add_regular_event(self):
     collector = EventCollector(self.storage, {})
     collector.add_event({'event': 'any event'})
     self.assertEqual(collector.events, [{'event': 'any event'}])
Пример #7
0
 def test_constructor(self):
     collector = EventCollector(self.storage, {})
     self.assertEqual(collector.events, [])