def test_search(self):
        self.test_create_messages()

        page = self._persistence.get_page_by_filter(
            None, FilterParams.from_tuples("search", "AA"), None)
        assert 2 == len(page.data)

        page = self._persistence.get_page_by_filter(
            None, FilterParams.from_tuples("search", "23"), None)
        assert 3 == len(page.data)

        page = self._persistence.get_page_by_filter(
            None, FilterParams.from_tuples("search", "rror"), None)
        assert 1 == len(page.data)
    def test_read_write(self):
        from_time = datetime.datetime.utcnow()

        self.test_create_messages()

        page = self._persistence.get_page_by_filter(
            None, FilterParams.from_tuples("search", "AA"), None)
        assert 2 == len(page.data)

        page = self._persistence.get_page_by_filter(
            None, FilterParams.from_tuples("max_level", LogLevel.Info), None)
        assert 2 == len(page.data)

        page = self._persistence.get_page_by_filter(
            None, FilterParams.from_tuples("from_time", from_time), None)
        assert 2 == len(page.data)
Ejemplo n.º 3
0
    def test_crud_operations(self):
        message = self._client.write_message(
            None, LogMessageV1(LogLevel.Info, None, "123", None, "AAA"))
        assert None != message

        message1 = LogMessageV1(LogLevel.Debug, None, "123", None, "BBB")
        message2 = LogMessageV1(
            LogLevel.Error, None, "123",
            ErrorDescriptionFactory.create(Exception('Test error')), "AAB")
        message2.time = datetime.datetime(1975, 1, 1, 0, 0, 0, 0)
        self._client.write_messages(None, [message1, message2])

        page = self._client.read_messages(
            None, FilterParams.from_tuples("search", "AA"), None)
        assert 2 == len(page.data)

        page = self._client.read_errors(None, None, None)
        assert 1 == len(page.data)
    def get_page_by_filter(self, correlation_id, filter, paging):
        filter = filter if filter != None else FilterParams()
        search = filter.get_as_nullable_string("search")
        level = filter.get_as_nullable_integer("level")
        max_level = filter.get_as_nullable_integer("max_level")
        from_time = filter.get_as_nullable_datetime("from_time")
        to_time = filter.get_as_nullable_datetime("to_time")
        errors_only = filter.get_as_boolean_with_default("errors_only", False)

        paging = paging if paging != None else PagingParams()
        skip = paging.get_skip(0)
        take = paging.get_take(self._max_page_size)
        data = []

        self._lock.acquire()
        try:
            messages = self._errors if errors_only else self._messages
            for message in messages:
                message_time = DateTimeConverter.to_utc_datetime(message.time)

                if search != None and not self._message_contains(
                        message, search):
                    continue
                if level != None and level != message.level:
                    continue
                if max_level != None and max_level < message.level:
                    continue
                if from_time != None and from_time > message_time:
                    continue
                if to_time != None and to_time <= message_time:
                    continue

                skip -= 1
                if skip >= 0: continue

                data.append(message)

                take -= 1
                if take <= 0: break
        finally:
            self._lock.release()

        total = len(data)
        return DataPage(data, total)
Ejemplo n.º 5
0
 def read_errors(self, correlation_id, filter, paging):
     if self._read_persistence == None: return DatePage([], 0)
     filter = filter if filter != None else FilterParams()
     filter.set_as_object('errors_only', True)
     return self._read_persistence.get_page_by_filter(correlation_id, filter, paging)
Ejemplo n.º 6
0
 def handler(correlation_id, args):
     filter = FilterParams.from_value(args.get("filter"))
     paging = PagingParams.from_value(args.get("paging"))
     return self._controller.read_errors(correlation_id, filter, paging)