public void testEventReportMaxPerSource() {
ResourceType resourceType = new ResourceType("foo", "foo", ResourceCategory.PLATFORM, null);
Resource resource = new Resource(1);
EventDefinition eventDefinition = new EventDefinition(resourceType, "foo");
EventSource eventSource = new EventSource("foo", eventDefinition, resource);
EventReport report = new EventReport(1, 10);
// add the first
addEvent(report, "foo", "first", eventSource);
report.addLimitWarningEvents(); // should do nothing
Map<EventSource, Set<Event>> allEvents = report.getEvents();
assert allEvents.size() == 1; // only one event source still!
assert allEvents.get(eventSource).size() == 1;
// add the second (this is over the max)
addEvent(report, "foo", "second", eventSource); // OVER MAX SO THIS NEVER MAKES IT!
report.addLimitWarningEvents();
allEvents = report.getEvents();
assert allEvents.size() == 1; // only one event source still!
assert allEvents.get(eventSource).size() == 2; // the second one is our "over the max" message
int foo_count = 0;
int limit_count = 0;
for (Event e : allEvents.get(eventSource)) {
if (e.getDetail().startsWith("foo-")) {
foo_count++;
continue;
}
if (e.getDetail().contains("Event Report Limit Reached:")) {
limit_count++;
continue;
}
assert false : "this event was unexpected: " + e;
}
assert foo_count == 1 : "there should have only been one of our events in the report: " + foo_count;
assert limit_count == 1 : "there should have been an event warning of the limit breach: " + limit_count;
// add the third (this is over the max)
report = stripLimitWarningEvents(report);
addEvent(report, "foo", "second", eventSource); // OVER MAX SO THIS NEVER MAKES IT!
addEvent(report, "foo", "third", eventSource); // STILL OVER MAX SO THIS NEVER MAKES IT EITHER!
report.addLimitWarningEvents();
allEvents = report.getEvents();
assert allEvents.size() == 1; // only one event source still!
assert allEvents.get(eventSource).size() == 2; // no others have been added, this includes our "over the max" event
foo_count = 0;
limit_count = 0;
for (Event e : allEvents.get(eventSource)) {
if (e.getDetail().startsWith("foo-")) {
foo_count++;
continue;
}
if (e.getDetail().contains("Event Report Limit Reached:")) {
limit_count++;
continue;
}
assert false : "this event was unexpected: " + e;
}
// use a second event source - since we didn't hit our max total, this should work
EventSource eventSource2 = new EventSource("bar", eventDefinition, resource);
report = stripLimitWarningEvents(report);
addEvent(report, "foo", "second", eventSource); // OVER MAX SO THIS NEVER MAKES IT!
addEvent(report, "foo", "third", eventSource); // STILL OVER MAX SO THIS NEVER MAKES IT EITHER!
addEvent(report, "bar", "first", eventSource2);
report.addLimitWarningEvents();
allEvents = report.getEvents();
assert allEvents.size() == 2;
assert allEvents.get(eventSource).size() == 2; // the original one plus a warning event
assert allEvents.get(eventSource2).size() == 1; // our new one (no warning events here)
// make sure they are the ones we expect