Merge pull request #1350 from jpbempel/jpbempel/improveJFRMessage
Add fix suggestion when JFR API not found
This commit is contained in:
commit
176b9c0121
|
@ -49,8 +49,28 @@ public final class ControllerFactory {
|
||||||
| InstantiationException
|
| InstantiationException
|
||||||
| IllegalAccessException
|
| IllegalAccessException
|
||||||
| InvocationTargetException e) {
|
| InvocationTargetException e) {
|
||||||
throw new UnsupportedEnvironmentException(
|
String exMsg =
|
||||||
"The JFR controller could not find a supported JFR API", e);
|
"The JFR controller could not find a supported JFR API" + getFixProposalMessage();
|
||||||
|
throw new UnsupportedEnvironmentException(exMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFixProposalMessage() {
|
||||||
|
try {
|
||||||
|
String javaVersion = System.getProperty("java.version");
|
||||||
|
if (javaVersion == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String javaVendor = System.getProperty("java.vendor", "");
|
||||||
|
if (javaVersion.startsWith("1.8")) {
|
||||||
|
if (javaVendor.startsWith("Azul Systems")) {
|
||||||
|
return ", use Azul zulu version 1.8.0_212+";
|
||||||
|
}
|
||||||
|
// TODO Add version minimum once JFR backported into OpenJDK distros
|
||||||
|
}
|
||||||
|
return ", use OpenJDK 11+ or Azul zulu version 1.8.0_212+";
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.datadog.profiling.controller;
|
package com.datadog.profiling.controller;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.condition.JRE.JAVA_8;
|
import static org.junit.jupiter.api.condition.JRE.JAVA_8;
|
||||||
|
|
||||||
|
@ -19,10 +20,18 @@ public class ControllerFactoryTest {
|
||||||
@Test
|
@Test
|
||||||
@EnabledOnJre({JAVA_8})
|
@EnabledOnJre({JAVA_8})
|
||||||
public void testCreateControllerJava8() {
|
public void testCreateControllerJava8() {
|
||||||
assertThrows(
|
UnsupportedEnvironmentException unsupportedEnvironmentException =
|
||||||
UnsupportedEnvironmentException.class,
|
assertThrows(
|
||||||
() -> {
|
UnsupportedEnvironmentException.class,
|
||||||
ControllerFactory.createController(config);
|
() -> {
|
||||||
});
|
ControllerFactory.createController(config);
|
||||||
|
});
|
||||||
|
String expected =
|
||||||
|
"The JFR controller could not find a supported JFR API, use OpenJDK 11+ or Azul zulu version 1.8.0_212+";
|
||||||
|
if ("Azul Systems, Inc.".equals(System.getProperty("java.vendor"))) {
|
||||||
|
expected =
|
||||||
|
"The JFR controller could not find a supported JFR API, use Azul zulu version 1.8.0_212+";
|
||||||
|
}
|
||||||
|
assertEquals(expected, unsupportedEnvironmentException.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue