Modify tests to use isPostgresCompatible() (to effectively include Yugabyte)

This commit is contained in:
Rob Bygrave
2022-02-02 23:25:13 +13:00
parent 4899f23773
commit 389f2bcd2f
25 changed files with 37 additions and 49 deletions
@@ -195,6 +195,10 @@ public abstract class BaseTestCase {
return Platform.DB2 == platform();
}
public boolean isPostgresCompatible() {
return isPostgres() || isYugabyte();
}
public boolean isPostgres() {
return Platform.POSTGRES == platform().base();
}
@@ -117,7 +117,7 @@ public class UpdateQueryTest extends BaseTestCase {
assertThat(sql).hasSize(1);
assertThat(rows).isEqualTo(0);
if (isPostgres()) {
if (isPostgresCompatible()) {
assertSql(sql.get(0)).contains("update o_customer set status = ? where id = any(?)");
} else {
assertSql(sql.get(0)).contains("update o_customer set status = ? where id in (?,?,?,?,?)"); // bind padding to 5
@@ -207,13 +207,9 @@ public class TestRawSqlBuilder extends BaseTestCase {
assertEquals(5, columnMapping.getIndexPosition("dataMonth"));
}
@ForPlatform(Platform.POSTGRES)
@Test
public void postgres_parse_withDateTruncCaseHaving() {
if (!isPostgres()) {
return;
}
ResetBasicData.reset();
String sql = "select DATE_TRUNC('DAY', d.order_date) as day," +
@@ -34,8 +34,6 @@ public class TestQueryForUpdate extends BaseTestCase {
if (isSqlServer()) {
assertThat(sqlOf(query)).contains("with (updlock)");
} else if (isPostgres()) {
assertThat(sqlOf(query)).contains("for update");
} else {
assertThat(sqlOf(query)).contains("for update");
}
@@ -134,14 +132,10 @@ public class TestQueryForUpdate extends BaseTestCase {
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(2);
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertSql(sql.get(0)).contains("from e_basic t0 where t0.id =");
assertSql(sql.get(1)).contains("from e_basic t0 where t0.id =");
if (isPostgres()) {
assertSql(sql.get(1)).contains("for update");
} else {
assertSql(sql.get(1)).contains("for update");
}
assertSql(sql.get(1)).contains("for update");
}
transaction.end();
@@ -165,8 +159,6 @@ public class TestQueryForUpdate extends BaseTestCase {
assertThat(sqlOf(query)).contains("for update");
} else if (isSqlServer()) {
assertThat(sqlOf(query)).contains("with (updlock,nowait)");
} else if (isPostgres()) {
assertThat(sqlOf(query)).contains("for update nowait");
} else {
assertThat(sqlOf(query)).contains("for update nowait");
}
@@ -192,8 +184,6 @@ public class TestQueryForUpdate extends BaseTestCase {
assertThat(sqlOf(query)).contains("with (updlock,nowait)");
} else if (isH2()) {
assertThat(sqlOf(query)).contains("for update");
} else if (isPostgres()) {
assertThat(sqlOf(query)).contains("for update nowait");
} else {
assertThat(sqlOf(query)).contains("for update nowait");
}
@@ -26,8 +26,7 @@ public class TestInetAddressType extends TransactionalTestCase {
@Test
public void testIp6() throws UnknownHostException {
if (isPostgres() || isYugabyte()) {
if (isPostgresCompatible()) {
insertUpdateDeleteFind("2001:db8:85a3:0:0:8a2e:370:7334", "2001:db8:85a3::8a2e:370:7334", "2001:4f8:3:ba::/64", "2001:4f8:3:ba::/64");
} else {
insertUpdateDeleteFind("2001:db8:85a3:0:0:8a2e:370:7334", "2001:db8:85a3:0:0:8a2e:370:7334", "192.168.100.128/25", "192.168.100.128/25");
@@ -43,7 +43,7 @@ public class TestSqlRowUUID extends BaseTestCase {
assertThat(value).isEqualTo(e.getId());
if (isPostgres()) {
if (isPostgresCompatible()) {
usingPostrgesAnyWithPositionedParameter_needsExplicitCast(e);
}
}
@@ -86,7 +86,7 @@ public class TestOnCascadeDeleteChildrenWithCompositeKeys extends BaseTestCase {
beanProperty.findIdsByParentId(null, ids, null, null, true);
beanProperty.findIdsByParentId(1L, null, null, null, true);
}
/**
* Test makes select and a select distinct of entities with composite keys.
*/
@@ -106,7 +106,7 @@ public class TestOnCascadeDeleteChildrenWithCompositeKeys extends BaseTestCase {
query1.setDistinct(true).setCountDistinct(CountDistinctOrder.COUNT_DESC_ATTR_ASC).setMaxRows(20);
query1.findSingleAttributeList();
if (isH2() || isMariaDB() || isPostgres()) {
if (isH2() || isMariaDB() || isPostgresCompatible()) {
assertThat(query1.getGeneratedSql()).contains("select distinct r1.attribute_, count(*) from "
+ "(select distinct t0.user_id, t0.role_id, t1.name as attribute_ "
+ "from em_user_role t0 join em_user t1 on t1.id = t0.user_id) r1 "
@@ -40,7 +40,7 @@ public class TestDeleteByQuery extends BaseTestCase {
assertSql(sql.get(0)).contains("delete from bbookmark_user where id in (select top 3 t0.id from bbookmark_user t0 where t0.name like ");
} else {
assertSql(sql.get(0)).contains("delete from bbookmark_user where id in (select t0.id from bbookmark_user t0 where t0.name like");
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertSql(sql.get(0)).contains("limit 3");
}
}
@@ -139,7 +139,7 @@ public class TestHistoryInsert extends BaseTestCase {
assertThat(sql).hasSize(1);
if (isH2()) {
assertThat(sql.get(0)).contains("and t0.sys_period_start < ? and (t0.sys_period_end >= ? or t0.sys_period_end is null)");
} else if (isPostgres()) {
} else if (isPostgresCompatible()) {
assertThat(sql.get(0)).contains("and lower(t0.sys_period) < ? and (upper(t0.sys_period) >= ? or upper(t0.sys_period) is null)");
}
@@ -85,7 +85,7 @@ public class TestCarWheelIud extends BaseTestCase {
final List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(2);
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertSql(sql.get(0)).contains("select t0.brand, sum(t0.sold) from sa_car t0 group by t0.brand limit 10");
assertSql(sql.get(1)).contains("select count(*) from ( select t0.brand, sum(t0.sold) from sa_car t0 group by t0.brand)");
}
@@ -49,7 +49,7 @@ public class TestAggregationTopLevel extends BaseTestCase {
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(2);
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertSql(sql.get(0)).contains("select count(*) from ( select t0.edate, sum(t0.total_kms) from d_machine_stats t0 group by t0.edate having sum(t0.total_kms) > ?)");
assertSql(sql.get(1)).contains("select t0.edate, sum(t0.total_kms) from d_machine_stats t0 group by t0.edate having sum(t0.total_kms) > ? limit 10");
} else if (isSqlServer()) {
@@ -53,7 +53,7 @@ public class TestDbArray_asSet extends BaseTestCase {
assertThat(found.getPhoneNumbers()).containsExactly("4321", "9823");
if (isPostgres()) {
if (isPostgresCompatible()) {
Query<EArraySetBean> query = DB.find(EArraySetBean.class)
.where()
.arrayContains("otherIds", 96L, 97L)
@@ -60,7 +60,7 @@ class TestDbArray_basic extends BaseTestCase {
assertThat(found.getPhoneNumbers()).containsExactly("4321", "9823");
if (isPostgres()) {
if (isPostgresCompatible()) {
Query<EArrayBean> query = DB.find(EArrayBean.class)
.where()
.arrayContains("otherIds", 96L, 97L)
@@ -369,7 +369,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
if (isH2()) {
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,'-',t0.code) in (?,?) order by t0.sku desc; --bind(def,Array[2]={2-1000,3-1000})");
} else if (isPostgres() || isOracle() || isDb2() || isYugabyte()) {
} else if (isPostgresCompatible() || isOracle() || isDb2()) {
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||'-'||t0.code)");
} else if (isHana()) {
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, '-'||t0.code)");
@@ -412,7 +412,7 @@ public class TestCacheViaComplexNaturalKey3 extends BaseTestCase {
if (isH2()) {
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku,':',t0.code,'-foo') in (?,?) order by t0.sku desc; --bind(def,Array[2]={2:1000-foo,3:1000-foo})");
} else if (isPostgres() || isOracle() || isDb2() || isYugabyte()){
} else if (isPostgresCompatible() || isOracle() || isDb2()){
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and (t0.sku||':'||t0.code||'-foo')");
} else if (isHana()){
assertSql(sql.get(0)).contains("from o_cached_natkey3 t0 where t0.store = ? and concat(t0.sku, ':'||t0.code||'-foo')");
@@ -30,7 +30,7 @@ public class TestMTOInheritNoDiscriminator extends BaseTestCase {
final List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(1);
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertSql(sql.get(0)).contains("select t0.id, t0.name, t0.version, t2.type, t0.truck_plate_no, t0.basic_id, t1.id, t1.some_uid, t1.foo, t1.owner_id from ttruck_holder t0 join tcar t2 on t2.plate_no = t0.truck_plate_no left join ttruck_holder_item t1 on t1.owner_id = t0.id where t0.id = ? order by t0.id");
}
}
@@ -51,7 +51,7 @@ public class TestHistoryEmbeddedId extends BaseTestCase {
assertThat(sql.get(0)).contains("from hembi_bean_with_history t0 where t0.part=? and t0.brand=?");
if (isH2()) {
assertThat(sql.get(0)).contains("order by t0.sys_period_start desc");
} else if (isPostgres()) {
} else if (isPostgresCompatible()) {
assertThat(sql.get(0)).contains("order by lower(t0.sys_period) desc");
}
}
@@ -29,7 +29,7 @@ public class TestQueryExists extends BaseTestCase {
String sql = LoggedSql.stop().get(0);
assertThat(check).isTrue();
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sql).contains("select t0.id from o_order t0 where t0.id > ? limit 1");
}
@@ -65,7 +65,7 @@ public class TestQueryFilterMany extends BaseTestCase {
assertThat(sqlList.get(0)).contains("lower(t0.name) = ?");
assertThat(sqlList.get(1)).contains("status = ?");
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sqlList.get(0)).doesNotContain("offset");
assertThat(sqlList.get(0)).contains(" limit 5");
assertThat(sqlList.get(1)).contains(" offset 3");
@@ -97,7 +97,7 @@ public class TestQueryFilterMany extends BaseTestCase {
assertThat(sqlList.get(0)).contains("lower(t0.name) = ?");
assertThat(sqlList.get(1)).contains("status = ?");
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sqlList.get(0)).doesNotContain("offset");
assertThat(sqlList.get(0)).contains(" limit 5");
assertThat(sqlList.get(1)).contains(" offset 3");
@@ -126,7 +126,7 @@ public class TestQueryFilterMany extends BaseTestCase {
assertThat(sqlList.get(0)).contains("lower(t0.name) = ?");
assertThat(sqlList.get(1)).contains("status = ?");
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sqlList.get(0)).doesNotContain("offset");
assertThat(sqlList.get(0)).contains(" limit 5");
assertThat(sqlList.get(1)).contains(" order by t0.order_date desc, t0.id limit 100 offset 3");
@@ -220,7 +220,7 @@ public class TestQueryFilterMany extends BaseTestCase {
List<String> sqlList = LoggedSql.stop();
assertEquals(1, sqlList.size());
assertThat(sqlList.get(0)).contains("from o_customer t0 left join o_order t1 on t1.kcustomer_id = t0.id and t1.order_date is not null left join o_customer t2 on t2.id = t1.kcustomer_id where t1.status ");
if (isPostgres()) {
if (isPostgresCompatible()) {
assertThat(sqlList.get(0)).contains("where t1.status = any(?) order by t0.id");
} else {
assertThat(sqlList.get(0)).contains("where t1.status in (?) order by t0.id");
@@ -243,7 +243,7 @@ public class TestQueryFilterMany extends BaseTestCase {
List<String> sqlList = LoggedSql.stop();
assertEquals(2, sqlList.size());
assertThat(sqlList.get(0)).contains("from o_customer t0");
if (isPostgres()) {
if (isPostgresCompatible()) {
assertThat(sqlList.get(1)).contains("from o_order t0 join o_customer t1 on t1.id = t0.kcustomer_id where t0.order_date is not null and (t0.kcustomer_id) = any(?)");
assertThat(sqlList.get(1)).contains(" and t0.status = any(?)");
} else {
@@ -69,7 +69,7 @@ public class TestSubQuery extends BaseTestCase {
// execute the subQuery as copy (generatedSQL must be part of original query)
Query<OrderDetail> debugSq = sq.copy();
debugSq.findSingleAttribute();
if (isPostgres()) {
if (isPostgresCompatible()) {
assertThat(debugSq.getGeneratedSql()).isEqualTo("select t1.id from o_order_detail t0 join o_order t1 on t1.id = t0.order_id where t0.product_id = any(?)");
} else {
assertSql(debugSq.getGeneratedSql()).isEqualTo("select t1.id from o_order_detail t0 join o_order t1 on t1.id = t0.order_id where t0.product_id in (?)");
@@ -78,7 +78,7 @@ public class TestSubQuery extends BaseTestCase {
Query<Order> query = DB.find(Order.class).select("shipDate").where().isIn("id", sq).query();
query.findSingleAttribute();
if (isPostgres()) {
if (isPostgresCompatible()) {
assertThat(query.getGeneratedSql()).isEqualTo("select t0.ship_date from o_order t0 where (t0.id) in (" + debugSq.getGeneratedSql() + ")");
} else {
assertSql(query.getGeneratedSql()).isEqualTo("select t0.ship_date from o_order t0 where (t0.id) in (" + trimSql(debugSq.getGeneratedSql()) + ")");
@@ -149,7 +149,7 @@ public class TestAggregationCount extends BaseTestCase {
String sql = sqlOf(query, 5);
if (isH2()) {
assertThat(sql).contains("select distinct t0.id, t0.name, count(u1.id), sum(u1.my_units), sum(u1.my_units * u1.amount), sum(u1.my_units), t0.name from tevent_one t0 ");
} else if (isPostgres()) {
} else if (isPostgresCompatible()) {
assertThat(sql).contains("t0.name, count(u1.id), sum(u1.my_units), sum(u1.my_units * u1.amount), sum(u1.my_units), t0.name from tevent_one t0 ");
}
assertThat(sql).contains("from tevent_one t0 join tevent_many u1 on u1.event_id = t0.id ");
@@ -237,7 +237,7 @@ public class TestCustomerFinder extends BaseTestCase {
assertThat(metricsJson).contains("\"name\":\"txn.main\"");
assertThat(metricsJson).contains("\"name\":\"orm.Customer.findList\"");
assertThat(metricsJson).contains("\"loc\":\"org.tests.model.basic.finder.CustomerFinder.byNameStatus\"");
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(metricsJson).contains("\"hash\":\"de3affa5b4bff07e19c1c012590dcde6\"");
assertThat(metricsJson).contains("\"sql\":\"select t0.id, t0.status,");
}
@@ -94,7 +94,7 @@ public class TestQueryDistinct extends BaseTestCase {
query.findList();
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
String generatedSql = sqlOf(query);
assertThat(generatedSql).contains("select distinct t0.name from o_customer t0 limit 10");
}
@@ -313,8 +313,7 @@ public class SqlQueryTests extends BaseTestCase {
@Test
public void firstRow() {
if (isPostgres()) {
if (isPostgresCompatible()) {
ResetBasicData.reset();
@@ -25,7 +25,7 @@ public class TestQuotedIdentifierQuery extends BaseTestCase {
.raw("t0.`CODE` = ?", "bar")
.findList();
} else if (isH2() || isPostgres()) {
} else if (isH2() || isPostgresCompatible()) {
DB.find(BWithQIdent.class)
.where()
@@ -94,7 +94,7 @@ public class TestNativeSqlBasic extends BaseTestCase {
query.findList();
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sqlOf(query)).contains(" limit 10");
}
}
@@ -113,7 +113,7 @@ public class TestNativeSqlBasic extends BaseTestCase {
query.findList();
if (isH2() || isPostgres()) {
if (isH2() || isPostgresCompatible()) {
assertThat(sqlOf(query)).contains(" limit 10 offset 20");
}
}