Beispiel #1
0
 def test_queue_full_hook_properties(self, mocker):
     """Test queue_full_hook is executed when the queue is full regarding properties."""
     storage = InMemoryEventStorage(200)
     queue_full_hook = mocker.Mock()
     storage.set_queue_full_hook(queue_full_hook)
     events = [EventWrapper(event=Event('key%d' % i, 'user', 'purchase', 12.5, 1, None),  size=32768) for i in range(160)]
     storage.put(events)
     assert queue_full_hook.mock_calls == [mocker.call()]
Beispiel #2
0
 def test_queue_full_hook(self, mocker):
     """Test queue_full_hook is executed when the queue is full."""
     storage = InMemoryEventStorage(100)
     queue_full_hook = mocker.Mock()
     storage.set_queue_full_hook(queue_full_hook)
     events = [EventWrapper(event=Event('key%d' % i, 'user', 'purchase', 12.5, 321654, None),  size=1024) for i in range(0, 101)]
     storage.put(events)
     assert queue_full_hook.mock_calls == [mocker.call()]
    def test_clear(self):
        """Test clear method."""
        storage = InMemoryEventStorage(100)
        storage.put([
            EventWrapper(
                event=Event('key1', 'user', 'purchase', 3.5, 123456, None),
                size=1024,
            )
        ])

        assert storage._events.qsize() == 1
        storage.clear()
        assert storage._events.qsize() == 0
    def test_push_pop_events(self):
        """Test pushing and retrieving events."""
        storage = InMemoryEventStorage(100)
        storage.put([
            EventWrapper(
                event=Event('key1', 'user', 'purchase', 3.5, 123456, None),
                size=1024,
            )
        ])
        storage.put([
            EventWrapper(
                event=Event('key2', 'user', 'purchase', 3.5, 123456, None),
                size=1024,
            )
        ])
        storage.put([
            EventWrapper(
                event=Event('key3', 'user', 'purchase', 3.5, 123456, None),
                size=1024,
            )
        ])

        # Assert impressions are retrieved in the same order they are inserted.
        assert storage.pop_many(1) == [
            Event('key1', 'user', 'purchase', 3.5, 123456, None)
        ]
        assert storage.pop_many(1) == [
            Event('key2', 'user', 'purchase', 3.5, 123456, None)
        ]
        assert storage.pop_many(1) == [
            Event('key3', 'user', 'purchase', 3.5, 123456, None)
        ]

        # Assert inserting multiple impressions at once works and maintains order.
        events = [
            EventWrapper(
                event=Event('key1', 'user', 'purchase', 3.5, 123456, None),
                size=1024,
            ),
            EventWrapper(
                event=Event('key2', 'user', 'purchase', 3.5, 123456, None),
                size=1024,
            ),
            EventWrapper(
                event=Event('key3', 'user', 'purchase', 3.5, 123456, None),
                size=1024,
            ),
        ]
        assert storage.put(events)

        # Assert events are retrieved in the same order they are inserted.
        assert storage.pop_many(1) == [
            Event('key1', 'user', 'purchase', 3.5, 123456, None)
        ]
        assert storage.pop_many(1) == [
            Event('key2', 'user', 'purchase', 3.5, 123456, None)
        ]
        assert storage.pop_many(1) == [
            Event('key3', 'user', 'purchase', 3.5, 123456, None)
        ]