// it should be already reported, but we report with INFO just in case
StringBuildermessage=newStringBuilder("There was a problem reporting unmarshalling field errors");
Levellevel=Level.WARNING;
if(tinstanceofIllegalStateException&&t.getMessage().contains("Expected 1 instance of "+OldDataMonitor.class.getName())){
message.append(". Make sure this code is executed after InitMilestone.EXTENSIONS_AUGMENTED stage, for example in Plugin#postInitialize instead of Plugin#start");
level=Level.INFO;// it was reported when getting the singleton for OldDataMonitor
}
// it should be already reported, but we report with INFO just in case
// Only one class miss gathered with two occurrences
// Only one class miss gathered
assertEquals(1,eventsGathered.size());
assertEquals(1,eventsGathered.size());
// 2 log entries
assertEquals("Two missing class should be printed out in the log",2,logging.getRecords().stream().filter(r->r.getMessage().contains(NON_EXISTING_CLASS)||
// The stack trace of these CNFE are different but we only look at class names when printing on logs, so
// just one log entry
assertEquals("Single missing class should be printed out in the log",1,logging.getRecords().stream().filter(r->r.getMessage().contains(NON_EXISTING_CLASS)).count());
}
}
/**
/**
...
@@ -120,7 +132,7 @@ public class MissingClassTelemetryFasterTest {
...
@@ -120,7 +132,7 @@ public class MissingClassTelemetryFasterTest {
for(inti=0;i<2;i++){
for(inti=0;i<2;i++){
try{
try{
//Exceptions thrown at the same line, with the same stack trace become occurrences of just one event
//Exceptions thrown at the same line, with the same stack trace become occurrences of just one event
cl.loadClass("sun.java.MyNonExistentJavaClass");
cl.loadClass(NON_EXISTING_CLASS);
}catch(ClassNotFoundExceptionignored){
}catch(ClassNotFoundExceptionignored){
}
}
}
}
...
@@ -132,6 +144,9 @@ public class MissingClassTelemetryFasterTest {
...
@@ -132,6 +144,9 @@ public class MissingClassTelemetryFasterTest {
// Only one class miss gathered with two occurrences
// Only one class miss gathered with two occurrences
// The class name and also the stack trace of these CNFEs are the same, so 1 log event
assertEquals("Just one missing class should be printed out in the log",1,logging.getRecords().stream().filter(r->r.getMessage().contains(NON_EXISTING_CLASS)).count());
}
}
/**
/**
...
@@ -152,31 +167,42 @@ public class MissingClassTelemetryFasterTest {
...
@@ -152,31 +167,42 @@ public class MissingClassTelemetryFasterTest {
// No events gathered
// No events gathered
assertEquals(0,eventsGathered.size());
assertEquals(0,eventsGathered.size());
// No log
assertEquals("No log if the class is not a java one",0,logging.getRecords().stream().filter(r->r.getMessage().contains(NON_EXISTING_CLASS)).count());
}
}
/**
/**
* Only a max number of events is gathered. In this test, just one wit two occurrences
* Only a max number of events is gathered. In this test, just one with two occurrences
*/
*/
@Test
@Test
publicvoidmaxEventsLimitedSameStackTrace(){
publicvoidmaxEventsLimitedSameStackTrace(){
Assume.assumeTrue("The telemetry should be enabled",MissingClassTelemetry.enabled());
Assume.assumeTrue("The telemetry should be enabled",MissingClassTelemetry.enabled());