mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1665 - Incorrect query execution metrics for ORM query converted to DTO query via asDto()
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package io.ebean;
|
||||
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaQueryMetric;
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
@@ -19,7 +20,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
@BeforeClass
|
||||
public static void resetStats() {
|
||||
Ebean.getDefaultServer().getMetaInfoManager().resetAllMetrics();
|
||||
DB.getDefault().getMetaInfoManager().resetAllMetrics();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -35,7 +36,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@ForPlatform(Platform.H2)
|
||||
@Test
|
||||
public void testPlanHits() {
|
||||
|
||||
@@ -46,24 +47,23 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
String[] prefix = { "Bl", "B", "Red", "jim" };
|
||||
|
||||
for (String val : prefix) {
|
||||
List<ContactDto> list = Ebean.find(Contact.class)
|
||||
DB.find(Contact.class)
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where()
|
||||
.istartsWith(concat("lastName", ", ", "firstName"), val).orderBy().asc("lastName").setMaxRows(10)
|
||||
.asDto(ContactDto.class).setLabel("prefixLoop").findList();
|
||||
|
||||
System.out.println("List:" + list);
|
||||
}
|
||||
|
||||
BasicMetricVisitor basic = visitMetricsBasic();
|
||||
|
||||
List<MetaQueryMetric> stats = basic.getDtoQueryMetrics();
|
||||
for (MetaQueryMetric stat : stats) {
|
||||
System.out.println(stat);
|
||||
long meanMicros = stat.getMean();
|
||||
assertThat(meanMicros).isLessThan(900_000);
|
||||
}
|
||||
|
||||
assertThat(stats).hasSize(1);
|
||||
assertThat(stats.get(0).getCount()).isEqualTo(3);
|
||||
|
||||
assertThat(stats.get(0).getCount()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +73,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
DtoQuery<ContactDto> query = Ebean.find(Contact.class)
|
||||
DtoQuery<ContactDto> query = DB.find(Contact.class)
|
||||
// we must explicitly add the id property for DTO query (if we want it)
|
||||
.select("id, email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").asDto(ContactDto.class).setLabel("explicitId")
|
||||
@@ -86,7 +86,6 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
for (ContactDto dto : dtos) {
|
||||
assertThat(dto.getEmail()).isNotNull();
|
||||
assertThat(dto.getFullName()).isNotNull();
|
||||
System.out.println(dto);
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
@@ -101,7 +100,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
DtoQuery<ContactDto> query = Ebean.find(Contact.class)
|
||||
DtoQuery<ContactDto> query = DB.find(Contact.class)
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").asDto(ContactDto.class);
|
||||
|
||||
@@ -112,7 +111,6 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
for (ContactDto dto : dtos) {
|
||||
assertThat(dto.getEmail()).isNotNull();
|
||||
assertThat(dto.getFullName()).isNotNull();
|
||||
System.out.println(dto);
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
@@ -127,7 +125,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactDto> contactDtos = Ebean.find(Contact.class).setLabel("emailFullName")
|
||||
List<ContactDto> contactDtos = DB.find(Contact.class).setLabel("emailFullName")
|
||||
.select("email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").setMaxRows(10).asDto(ContactDto.class).findList();
|
||||
|
||||
@@ -136,7 +134,6 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
for (ContactDto dto : contactDtos) {
|
||||
assertThat(dto.getEmail()).isNotNull();
|
||||
assertThat(dto.getFullName()).isNotNull();
|
||||
System.out.println(dto);
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
@@ -158,14 +155,13 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactDto> contactDtos = Ebean.find(Contact.class)
|
||||
List<ContactDto> contactDtos = DB.find(Contact.class)
|
||||
.select("id, email, " + concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("email")
|
||||
.isNotNull("lastName").orderBy().asc("lastName").setMaxRows(10).asDto(ContactDto.class).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
for (ContactDto dto : contactDtos) {
|
||||
System.out.println(dto);
|
||||
assertThat(dto.getId()).isNotNull();
|
||||
assertThat(dto.getFullName()).isNotNull();
|
||||
assertThat(dto.getEmail()).isNotNull();
|
||||
@@ -189,22 +185,20 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactDto> contactDtos = Ebean.find(Contact.class)
|
||||
List<ContactDto> contactDtos = DB.find(Contact.class)
|
||||
.select(concat("lastName", ", ", "firstName") + " as fullName").where().isNotNull("lastName").orderBy()
|
||||
.asc("lastName").asDto(ContactDto.class).setFirstRow(2).setMaxRows(5).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
for (ContactDto dto : contactDtos) {
|
||||
System.out.println(dto);
|
||||
assertThat(dto.getFullName()).isNotNull();
|
||||
assertThat(dto.getId()).isNull();
|
||||
assertThat(dto.getEmail()).isNull();
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0))
|
||||
.contains("select " + concat("t0.last_name", ", ", "t0.first_name") + " fullName from contact t0 where");
|
||||
assertThat(sql.get(0)).contains("select " + concat("t0.last_name", ", ", "t0.first_name") + " fullName from contact t0 where");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,7 +208,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<ContactTotals> contactDtos = Ebean.find(Contact.class).select("lastName, count(*) as totalCount").where()
|
||||
List<ContactTotals> contactDtos = DB.find(Contact.class).select("lastName, count(*) as totalCount").where()
|
||||
.isNotNull("lastName").having().gt("count(*)", 1).orderBy().desc("count(*)").asDto(ContactTotals.class)
|
||||
.findList();
|
||||
|
||||
@@ -226,8 +220,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
assertThat(sql.get(0)).contains(
|
||||
"select t0.last_name, count(*) totalCount from contact t0 where t0.last_name is not null group by t0.last_name having count(*) > ?");
|
||||
assertThat(sql.get(0)).contains("select t0.last_name, count(*) totalCount from contact t0 where t0.last_name is not null group by t0.last_name having count(*) > ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -235,7 +228,7 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<ContactTotals> contactDtos = Ebean.find(Contact.class).select("lastName, count(*) as totalCount").where()
|
||||
List<ContactTotals> contactDtos = DB.find(Contact.class).select("lastName, count(*) as totalCount").where()
|
||||
.isNotNull("lastName").asDto(ContactTotals.class).findList();
|
||||
|
||||
assertThat(contactDtos).isNotEmpty();
|
||||
|
||||
@@ -24,6 +24,7 @@ public class DtoQueryTest extends BaseTestCase {
|
||||
public void dto_findList_constructorMatch() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
resetAllMetrics();
|
||||
|
||||
DtoQuery<DCust> dtoQuery = server().findDto(DCust.class, "select id, name from o_customer");
|
||||
|
||||
@@ -31,6 +32,17 @@ public class DtoQueryTest extends BaseTestCase {
|
||||
|
||||
log.info(list.toString());
|
||||
assertThat(list).isNotEmpty();
|
||||
|
||||
BasicMetricVisitor basic = visitMetricsBasic();
|
||||
|
||||
List<MetaQueryMetric> stats = basic.getDtoQueryMetrics();
|
||||
for (MetaQueryMetric stat : stats) {
|
||||
long meanMicros = stat.getMean();
|
||||
assertThat(meanMicros).isLessThan(900_000);
|
||||
}
|
||||
|
||||
assertThat(stats).hasSize(1);
|
||||
assertThat(stats.get(0).getCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user