Pr/add tests (#1103)

* ADD: Testcase for Sqlserver-6.2.0 driver

* CHG: Removed Row-limit - so we need no special handling when sqlserver-platform generates a "select top 100" statement

* ADD: additional asserts to TestQueryCache

* CHG: Ignore test for sqlserver
This commit is contained in:
Roland Praml
2017-09-01 20:17:56 +12:00
committed by Rob Bygrave
parent 96e3f4138f
commit e908d16ba8
4 changed files with 112 additions and 23 deletions
+46
View File
@@ -83,6 +83,17 @@ public class TestQueryCache extends BaseTestCase {
.findSingleAttributeList();
assertThat(colA_Second).isNotSameAs(colA_NotDistinct);
// ensure that findCount & findSingleAttribute use different
// slots in cache. If not a "Cannot cast List to int" should happen.
int count = Ebean.getServer(null)
.find(EColAB.class)
.setUseQueryCache(true)
.select("columnA")
.where()
.eq("columnB", "SingleAttribute")
.findCount();
assertThat(count).isEqualTo(2);
}
@Test
@@ -109,8 +120,43 @@ public class TestQueryCache extends BaseTestCase {
assertThat(count0).isEqualTo(count1);
assertThat(sql).hasSize(1);
// and now, ensure that we hit the database
LoggedSqlCollector.start();
int count2 = Ebean.find(EColAB.class)
.setUseQueryCache(false)
.where()
.eq("columnB", "count")
.findCount();
assertThat(count2).isEqualTo(count1);
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
}
@Test
public void findCountDifferentQueries() {
LoggedSqlCollector.start();
int count0 = Ebean.find(EColAB.class)
.setUseQueryCache(true)
.where()
.eq("columnB", "abc")
.findCount();
int count1 = Ebean.find(EColAB.class)
.setUseQueryCache(true)
.where()
.eq("columnB", "def")
.findCount();
List<String> sql = LoggedSqlCollector.stop();
assertThat(count0).isEqualTo(count1);
assertThat(sql).hasSize(2); // different queries
}
@Test
@SuppressWarnings("unchecked")
public void test() {
@@ -21,7 +21,7 @@ public class TestManyToOneAsOne extends BaseTestCase {
}
private void runInserts() {
if (isSqlServer()) return; // probably due the use of sequences - Empl has already an ID and Addr refers to it.
Addr junk = new Addr();
junk.setName("junk");
Ebean.save(junk);
@@ -62,11 +62,10 @@ public class TestQuerySingleAttribute extends BaseTestCase {
.setDistinct(true)
.select("name")
.where().eq("status", Customer.Status.NEW)
.orderBy().asc("name")
.setMaxRows(100);
.orderBy().asc("name");
query.findSingleAttributeList();
assertThat(sqlOf(query)).contains("select distinct t0.name from o_customer t0 where t0.status = ? order by t0.name ");
assertThat(sqlOf(query)).contains("select distinct t0.name from o_customer t0 where t0.status = ? order by t0.name");
}
@Test
@@ -155,8 +154,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
Query<Customer> query = Ebean.find(Customer.class)
.setDistinct(true)
.fetch("billingAddress","city")
.setMaxRows(100);
.fetch("billingAddress","city");
List<String> cities = query.findSingleAttributeList();
@@ -185,11 +183,10 @@ public class TestQuerySingleAttribute extends BaseTestCase {
Query<ChildA> query = Ebean.find(ChildA.class)
.setDistinct(true)
.select("more")
.setMaxRows(100);
.select("more");
query.findSingleAttributeList();
assertThat(sqlOf(query)).contains("select distinct t0.more from rawinherit_parent t0 where t0.type = 'A' limit 100");
assertThat(sqlOf(query)).contains("select distinct t0.more from rawinherit_parent t0 where t0.type = 'A' ");
}
@@ -200,12 +197,11 @@ public class TestQuerySingleAttribute extends BaseTestCase {
Query<EUncle> query = Ebean.find(EUncle.class)
.setDistinct(true)
.fetch("parent","more")
.setMaxRows(100);
.fetch("parent","more");
query.findSingleAttributeList();
assertThat(sqlOf(query)).contains("select distinct t1.more from rawinherit_uncle t0 join rawinherit_parent t1 on t1.id = t0.parent_id and t1.type in ('A','B')");
assertThat(sqlOf(query)).contains("select distinct t1.more from rawinherit_uncle t0 join rawinherit_parent t1 on t1.id = t0.parent_id");
}
@@ -231,8 +227,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
ResetBasicData.reset();
Query<Customer> query = Ebean.find(Customer.class)
.fetch("billingAddress","city")
.setMaxRows(100);
.fetch("billingAddress","city");
List<String> cities = query.findSingleAttributeList();
@@ -246,11 +241,10 @@ public class TestQuerySingleAttribute extends BaseTestCase {
ResetBasicData.reset();
Query<ChildA> query = Ebean.find(ChildA.class)
.select("more")
.setMaxRows(100);
.select("more");
query.findSingleAttributeList();
assertThat(sqlOf(query)).contains("select t0.more from rawinherit_parent t0 where t0.type = 'A' limit 100");
assertThat(sqlOf(query)).contains("select t0.more from rawinherit_parent t0 where t0.type = 'A'");
}
@@ -260,12 +254,11 @@ public class TestQuerySingleAttribute extends BaseTestCase {
ResetBasicData.reset();
Query<EUncle> query = Ebean.find(EUncle.class)
.fetch("parent","more")
.setMaxRows(100);
.fetch("parent","more");
query.findSingleAttributeList();
assertThat(sqlOf(query)).contains("select t1.more from rawinherit_uncle t0 join rawinherit_parent t1 on t1.id = t0.parent_id and t1.type in ('A','B')");
assertThat(sqlOf(query)).contains("select t1.more from rawinherit_uncle t0 join rawinherit_parent t1 on t1.id = t0.parent_id");
}
@Test
@@ -274,12 +267,11 @@ public class TestQuerySingleAttribute extends BaseTestCase {
ResetBasicData.reset();
Query<EUncle> query = Ebean.find(EUncle.class)
.fetch("parent","more")
.setMaxRows(100);
.fetch("parent","more");
Ebean.getDefaultServer().findSingleAttributeList(query, null);
assertThat(sqlOf(query)).contains("select t1.more from rawinherit_uncle t0 join rawinherit_parent t1 on t1.id = t0.parent_id and t1.type in ('A','B')");
assertThat(sqlOf(query)).contains("select t1.more from rawinherit_uncle t0 join rawinherit_parent t1 on t1.id = t0.parent_id");
}
@Test
@@ -0,0 +1,51 @@
package org.tests.transaction;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Transaction;
import org.junit.Test;
import org.tests.model.basic.ESimple;
/**
* This test tests a strange bug in the 6.2.0. sqlserver JDBC driver.
* (Version 6.1.7.jre8-preview works)
*
* https://github.com/Microsoft/mssql-jdbc/pull/374
*
* @author Roland Praml, FOCONIS AG
*/
public class TestSqlServerBatch extends BaseTestCase {
@Test
public void testAggressiveBatch() throws InterruptedException {
Transaction txn = Ebean.beginTransaction();
try {
txn.setBatchMode(true);
txn.setBatchSize(3);
// control flushing when mixing save and queries
txn.setBatchFlushOnQuery(false);
// for large batch insert processing when we do not
// ... need the generatedKeys, don't get them
txn.setBatchGetGeneratedKeys(false);
// explicitly flush the JDBC batch buffer
txn.flushBatch();
for (int i = 0; i < 10; i++) {
ESimple model = new ESimple();
model.setName(i % 2 == 0 ? null:"foobar");
Ebean.save(model);
}
// do not commit
} finally {
txn.end();
}
}
}