Search in sources :

Example 1 with EventSpamFilter

use of io.kubernetes.client.extended.event.legacy.EventSpamFilter in project java by kubernetes-client.

the class EventSpamFilterTest method testSpammingEventFiltering.

@Test
public void testSpammingEventFiltering() {
    int burst = 10;
    EventSpamFilter filter = new EventSpamFilter(100, EventUtils::getSpamKey, burst, Duration.ofDays(1), // never refill
    1);
    CoreV1Event spammingEvent1 = new CoreV1EventBuilder().withMessage("1").withSource(new V1EventSourceBuilder().withComponent("c1").build()).withInvolvedObject(new V1ObjectReference()).build();
    CoreV1Event spammingEvent2 = new CoreV1EventBuilder().withMessage("2").withSource(new V1EventSourceBuilder().withComponent("c1").build()).withInvolvedObject(new V1ObjectReference()).build();
    CoreV1Event spammingEvent3 = new CoreV1EventBuilder().withMessage("3").withSource(new V1EventSourceBuilder().withComponent("c2").build()).withInvolvedObject(new V1ObjectReference()).build();
    for (int i = 0; i < burst; i++) {
        assertEquals(true, filter.filter(spammingEvent1));
    }
    assertEquals(false, filter.filter(spammingEvent1));
    assertEquals(false, filter.filter(spammingEvent2));
    assertEquals(true, filter.filter(spammingEvent3));
}
Also used : V1EventSourceBuilder(io.kubernetes.client.openapi.models.V1EventSourceBuilder) V1ObjectReference(io.kubernetes.client.openapi.models.V1ObjectReference) EventSpamFilter(io.kubernetes.client.extended.event.legacy.EventSpamFilter) EventUtils(io.kubernetes.client.extended.event.legacy.EventUtils) CoreV1EventBuilder(io.kubernetes.client.openapi.models.CoreV1EventBuilder) CoreV1Event(io.kubernetes.client.openapi.models.CoreV1Event) Test(org.junit.Test)

Aggregations

EventSpamFilter (io.kubernetes.client.extended.event.legacy.EventSpamFilter)1 EventUtils (io.kubernetes.client.extended.event.legacy.EventUtils)1 CoreV1Event (io.kubernetes.client.openapi.models.CoreV1Event)1 CoreV1EventBuilder (io.kubernetes.client.openapi.models.CoreV1EventBuilder)1 V1EventSourceBuilder (io.kubernetes.client.openapi.models.V1EventSourceBuilder)1 V1ObjectReference (io.kubernetes.client.openapi.models.V1ObjectReference)1 Test (org.junit.Test)1