mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Use StackWalker for ProfileLocation and CallOrigin
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
package io.ebeaninternal.server.core;
|
||||
|
||||
/**
|
||||
* Make DefaultCallOriginFactory accessible to tests.
|
||||
*/
|
||||
public class HelpDefaultCallOriginFactory {
|
||||
|
||||
public static CallOriginFactory create(int maxStack) {
|
||||
return new DefaultCallOriginFactory(maxStack);
|
||||
}
|
||||
}
|
||||
+3
-14
@@ -54,21 +54,10 @@ class BasicProfileLocationTest {
|
||||
void obtain() {
|
||||
DProfileLocation loc = new DTimedProfileLocation(12, "foo", MetricFactory.get().createTimedMetric("junk"));
|
||||
|
||||
String javaVersion = System.getProperty("java.version");
|
||||
assertThat(loc.obtain()).isTrue();
|
||||
if (javaVersion.startsWith("1.8")) {
|
||||
assertThat(loc.fullLocation()).endsWith("invoke0(Native Method:12)");
|
||||
assertThat(loc.location()).isEqualTo("sun.reflect.NativeMethodAccessorImpl.invoke0");
|
||||
assertThat(loc.label()).isEqualTo("NativeMethodAccessorImpl.invoke0");
|
||||
} else if (javaVersion.startsWith("18") || javaVersion.startsWith("19") || javaVersion.startsWith("20")){
|
||||
assertThat(loc.fullLocation()).endsWith("jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)");
|
||||
assertThat(loc.location()).isEqualTo("java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke");
|
||||
assertThat(loc.label()).isEqualTo("DirectMethodHandleAccessor.invoke");
|
||||
} else if (javaVersion.startsWith("11") || javaVersion.startsWith("17")) {
|
||||
assertThat(loc.fullLocation()).endsWith("jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method:12)");
|
||||
assertThat(loc.location()).isEqualTo("java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0");
|
||||
assertThat(loc.label()).isEqualTo("NativeMethodAccessorImpl.invoke0");
|
||||
}
|
||||
assertThat(loc.fullLocation()).endsWith("org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)");
|
||||
assertThat(loc.location()).isEqualTo("org.junit.platform.commons.util.ReflectionUtils.invokeMethod");
|
||||
assertThat(loc.label()).isEqualTo("ReflectionUtils.invokeMethod");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.tests.server;
|
||||
|
||||
import io.ebean.bean.CallOrigin;
|
||||
import io.ebeaninternal.server.core.CallOriginFactory;
|
||||
import io.ebeaninternal.server.core.HelpDefaultCallOriginFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class TestDefaultCallOriginFactory {
|
||||
|
||||
private final CallOriginFactory factory = HelpDefaultCallOriginFactory.create(2);
|
||||
|
||||
@Test
|
||||
void createCallOrigin() {
|
||||
CallOrigin callOrigin = inner();
|
||||
String topElement = callOrigin.getTopElement();
|
||||
assertThat(topElement).contains("org.tests.server.TestDefaultCallOriginFactory.inner(TestDefaultCallOriginFactory.java:23)");
|
||||
assertThat(callOrigin.getFullDescription()).contains("TestDefaultCallOriginFactory.java:16");
|
||||
}
|
||||
|
||||
private CallOrigin inner() {
|
||||
return factory.createCallOrigin();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user