1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.turbo;
15
16 import ch.qos.logback.core.spi.FilterReply;
17 import org.junit.jupiter.api.Test;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20
21 public class DuplicateMessageFilterTest {
22
23 @Test
24 public void smoke() {
25 DuplicateMessageFilter dmf = new DuplicateMessageFilter();
26 dmf.setAllowedRepetitions(0);
27 dmf.start();
28 assertEquals(FilterReply.NEUTRAL, dmf.decide(null, null, null, "x", null, null));
29 assertEquals(FilterReply.NEUTRAL, dmf.decide(null, null, null, "y", null, null));
30 assertEquals(FilterReply.DENY, dmf.decide(null, null, null, "x", null, null));
31 assertEquals(FilterReply.DENY, dmf.decide(null, null, null, "y", null, null));
32 }
33
34 @Test
35 public void memoryLoss() {
36 DuplicateMessageFilter dmf = new DuplicateMessageFilter();
37 dmf.setAllowedRepetitions(1);
38 dmf.setCacheSize(1);
39 dmf.start();
40 assertEquals(FilterReply.NEUTRAL, dmf.decide(null, null, null, "a", null, null));
41 assertEquals(FilterReply.NEUTRAL, dmf.decide(null, null, null, "b", null, null));
42 assertEquals(FilterReply.NEUTRAL, dmf.decide(null, null, null, "a", null, null));
43 }
44
45 @Test
46 public void many() {
47 DuplicateMessageFilter dmf = new DuplicateMessageFilter();
48 dmf.setAllowedRepetitions(0);
49 int cacheSize = 10;
50 int margin = 2;
51 dmf.setCacheSize(cacheSize);
52 dmf.start();
53 for (int i = 0; i < cacheSize + margin; i++) {
54 assertEquals(FilterReply.NEUTRAL, dmf.decide(null, null, null, "a" + i, null, null));
55 }
56 for (int i = cacheSize - 1; i >= margin; i--) {
57 assertEquals(FilterReply.DENY, dmf.decide(null, null, null, "a" + i, null, null));
58 }
59 for (int i = margin - 1; i >= 0; i--) {
60 assertEquals(FilterReply.NEUTRAL, dmf.decide(null, null, null, "a" + i, null, null));
61 }
62 }
63
64 @Test
65
66
67 public void nullFormat() {
68 DuplicateMessageFilter dmf = new DuplicateMessageFilter();
69 dmf.setAllowedRepetitions(0);
70 dmf.setCacheSize(10);
71 dmf.start();
72 assertEquals(FilterReply.NEUTRAL, dmf.decide(null, null, null, null, null, null));
73 assertEquals(FilterReply.NEUTRAL, dmf.decide(null, null, null, null, null, null));
74 }
75
76 }