mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
WIP AutoTune refactor
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
package com.avaje.ebeaninternal.server.querydefn;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
|
||||
public class OrmQueryDetailParserTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testParseBasic() throws Exception {
|
||||
|
||||
|
||||
OrmQueryDetail other = new OrmQueryDetail();
|
||||
other.select("id,name");
|
||||
|
||||
OrmQueryProperties root = other.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select (id,name)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
|
||||
root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEmptySelect() throws Exception {
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select fetch customer (email)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).isNull();
|
||||
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("customer");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("email");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSelectFetch() throws Exception {
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select (id,name) fetch customer (email)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("customer");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("email");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSelectFetchMore() throws Exception {
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select (id,name) fetch customer (email) fetch details.product (sku,description)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("customer");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("email");
|
||||
|
||||
chunk = detail.getChunk("details.product", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("details.product");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("sku","description");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.avaje.ebeaninternal.server.querydefn;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class OrmQueryDetailTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void test_isAutoTuneEqual() {
|
||||
|
||||
OrmQueryDetailParser parser1 = new OrmQueryDetailParser("select order (id,name) fetch customer (name) fetch details (code)");
|
||||
OrmQueryDetail detail1 = parser1.parse();
|
||||
|
||||
OrmQueryDetailParser parser2 = new OrmQueryDetailParser("select order (id,name) fetch details (code) fetch customer (name)");
|
||||
OrmQueryDetail detail2 = parser2.parse();
|
||||
|
||||
assertTrue(detail1.isAutoTuneEqual(detail2));
|
||||
}
|
||||
}
|
||||
@@ -30,8 +30,8 @@ public class TestAutofetchTuneWithJoin extends BaseTestCase {
|
||||
|
||||
Query<Order> q = Ebean.find(Order.class)
|
||||
.setAutofetch(true)
|
||||
.fetch("customer")
|
||||
.fetch("customer.contacts")
|
||||
//.fetch("customer")
|
||||
//.fetch("customer.contacts")
|
||||
.where().lt("id", 3).query();
|
||||
|
||||
List<Order> list = q.findList();
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.avaje.tests.query.autotune;
|
||||
|
||||
import com.avaje.ebean.AdminAutofetch;
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.bean.ObjectGraphNode;
|
||||
import com.avaje.ebean.bean.ObjectGraphOrigin;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.tests.model.basic.Address;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TestAutoTuneProfiling extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
for (int i = 0; i < 1; i++) {
|
||||
execute();
|
||||
}
|
||||
|
||||
|
||||
collectUsage();
|
||||
}
|
||||
|
||||
|
||||
private void execute() {
|
||||
useOrderDate();
|
||||
useOrderDateCustomerName();
|
||||
useLots();
|
||||
}
|
||||
|
||||
|
||||
private Order findById(long id) {
|
||||
return Ebean.find(Order.class)
|
||||
.setAutofetch(true)
|
||||
.setId(id)
|
||||
.findUnique();
|
||||
}
|
||||
|
||||
private void useOrderDate() {
|
||||
Order order = findById(3);
|
||||
order.getStatus();
|
||||
order.getShipDate();
|
||||
}
|
||||
|
||||
private void useOrderDateCustomerName() {
|
||||
Order order = findById(3);
|
||||
order.getOrderDate();
|
||||
order.getCustomer().getName();
|
||||
}
|
||||
|
||||
private void useLots() {
|
||||
|
||||
Order order = findById(3);
|
||||
order.getOrderDate();
|
||||
order.getShipDate();
|
||||
// order.setShipDate(new Date(System.currentTimeMillis()));
|
||||
Customer customer = order.getCustomer();
|
||||
customer.getName();
|
||||
Address shippingAddress = customer.getShippingAddress();
|
||||
if (shippingAddress != null) {
|
||||
shippingAddress.getLine1();
|
||||
shippingAddress.getCity();
|
||||
}
|
||||
}
|
||||
|
||||
private static void collectUsage() {
|
||||
|
||||
AdminAutofetch adminAutofetch = Ebean.getServer(null).getAdminAutofetch();
|
||||
adminAutofetch.collectUsageViaGC();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user