mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2290 - Add MetaTimedMetric locationHash() which is a crc32 checksum of package + type + method (excludes line number)
This commit is contained in:
@@ -8,8 +8,14 @@ public class UtilLocationTest {
|
||||
|
||||
@Test
|
||||
public void label() {
|
||||
|
||||
assertThat(UtilLocation.label("foo")).isEqualTo("foo");
|
||||
assertThat(UtilLocation.label("ProfileLocationTest$Other.<init>(ProfileLocationTest.java:47)")).isEqualTo("ProfileLocationTest$Other.init");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hash() {
|
||||
assertThat(UtilLocation.hash("org.foo.MyFoo.doIt(MyFoo.java:12)")).isEqualTo(396279222L);
|
||||
assertThat(UtilLocation.hash("org.foo.MyFoo.doIt(MyFoo.java:13)")).isEqualTo(396279222L);
|
||||
assertThat(UtilLocation.hash("org.foo.MyFoo.doIt(MyFoo.java:945)")).isEqualTo(396279222L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ public class CustomerFinder extends Finder<Integer, Customer> {
|
||||
}
|
||||
|
||||
public List<Customer> byNameStatus(String nameStartsWith, Customer.Status status) {
|
||||
|
||||
return query("where status = :status and name istartsWith :name order by name")
|
||||
.setParameter("status", status)
|
||||
.setParameter("name", nameStartsWith)
|
||||
@@ -45,7 +44,6 @@ public class CustomerFinder extends Finder<Integer, Customer> {
|
||||
}
|
||||
|
||||
public List<String> namesStartingWith(String name) {
|
||||
|
||||
return nativeSql("select name from o_customer where name like ? order by name")
|
||||
.setParameter(name + "%")
|
||||
.findSingleAttributeList();
|
||||
|
||||
@@ -7,20 +7,28 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ProfileLocationTest {
|
||||
|
||||
private static ProfileLocation loc = ProfileLocation.create(12, "foo");
|
||||
|
||||
private static ProfileLocation loc2 = ProfileLocation.create();
|
||||
private static final ProfileLocation loc = ProfileLocation.create(12, "foo");
|
||||
private static final ProfileLocation locB = ProfileLocation.create();
|
||||
private static final ProfileLocation loc2 = ProfileLocation.create();
|
||||
|
||||
private boolean doIt() {
|
||||
locB.obtain(); // simulate a location moving by line number only
|
||||
return loc.obtain();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_obtain() {
|
||||
assertThat(doIt()).isTrue();
|
||||
assertThat(loc.fullLocation()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:15)");
|
||||
assertThat(loc.location()).isEqualTo("ProfileLocationTest.doIt(ProfileLocationTest.java:15)");
|
||||
assertThat(loc.fullLocation()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:16)");
|
||||
assertThat(loc.location()).isEqualTo("ProfileLocationTest.doIt(ProfileLocationTest.java:16)");
|
||||
assertThat(loc.label()).isEqualTo("ProfileLocationTest.doIt");
|
||||
assertThat(loc.hash()).isEqualTo(1867926812L);
|
||||
|
||||
// same hash even when the line number has changed
|
||||
assertThat(locB.fullLocation()).isEqualTo("org.tests.profile.ProfileLocationTest.doIt(ProfileLocationTest.java:15)");
|
||||
assertThat(locB.location()).isEqualTo("ProfileLocationTest.doIt(ProfileLocationTest.java:15)");
|
||||
assertThat(locB.label()).isEqualTo("ProfileLocationTest.doIt");
|
||||
assertThat(locB.hash()).isEqualTo(1867926812L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -35,7 +43,7 @@ public class ProfileLocationTest {
|
||||
other.hashCode();
|
||||
|
||||
assertThat(loc2.label()).isEqualTo("ProfileLocationTest$Other.init");
|
||||
assertThat(loc2.location()).isEqualTo("ProfileLocationTest$Other.<init>(ProfileLocationTest.java:44)");
|
||||
assertThat(loc2.location()).isEqualTo("ProfileLocationTest$Other.<init>(ProfileLocationTest.java:52)");
|
||||
}
|
||||
|
||||
static class Other {
|
||||
|
||||
@@ -242,7 +242,8 @@ public class TestCustomerFinder extends BaseTestCase {
|
||||
|
||||
assertThat(metricsJson).contains("\"name\":\"txn.main\"");
|
||||
assertThat(metricsJson).contains("\"name\":\"orm.Customer.findList\"");
|
||||
assertThat(metricsJson).contains("\"loc\":\"CustomerFinder.byNameStatus(CustomerFinder.java:44)\"");
|
||||
assertThat(metricsJson).contains("\"locHash\":3254522637");
|
||||
assertThat(metricsJson).contains("\"loc\":\"CustomerFinder.byNameStatus(CustomerFinder.java:43)\"");
|
||||
if (isH2() || isPostgres()) {
|
||||
assertThat(metricsJson).contains("\"sqlHash\":3634991469");
|
||||
assertThat(metricsJson).contains("\"sql\":\"select t0.id, t0.status,");
|
||||
|
||||
Reference in New Issue
Block a user