aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/vespa/model/RecentLogFilterTest.java
blob: 2f7e801218776069bebc5dd328d349f34a2c7269 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.LogRecord;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @author hmusum
 */
public class RecentLogFilterTest {

    @Test
    void basic() {
        RecentLogFilter rlf = new RecentLogFilter();
        List<LogRecord> logRecords = new ArrayList<>();
        for (int i = 0; i < RecentLogFilter.maxMessages + 1; i++) {
            logRecords.add(new LogRecord(Level.INFO, "" + i));
        }

        assertTrue(rlf.isLoggable(logRecords.get(0)));
        assertFalse(rlf.isLoggable(logRecords.get(0)));

        for (int i = 1; i < RecentLogFilter.maxMessages + 1; i++) {
            assertTrue(rlf.isLoggable(logRecords.get(i)));
        }

        // Should have filled up maxMessages slots with records 1-maxMessages
        // and pushed the first one out, so the below should return true
        assertTrue(rlf.isLoggable(logRecords.get(0)));
    }

}