Skip to content

Commit d19f132

Browse files
Backport to branch(3) : Fix missing unit tests for MariaDB RdbEngine (#2467)
Co-authored-by: Vincent Guilpain <[email protected]>
1 parent d7042ab commit d19f132

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTestBase.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public abstract class JdbcAdminTestBase {
8383
RdbEngine.SQLITE,
8484
new RdbEngineSqlite(),
8585
RdbEngine.YUGABYTE,
86-
new RdbEngineYugabyte());
86+
new RdbEngineYugabyte(),
87+
RdbEngine.MARIADB,
88+
new RdbEngineMariaDB());
8789

8890
@Mock private BasicDataSource dataSource;
8991
@Mock private Connection connection;
@@ -123,6 +125,7 @@ private JdbcAdmin createJdbcAdminFor(RdbEngineStrategy rdbEngineStrategy) {
123125
private void mockUndefinedTableError(RdbEngine rdbEngine, SQLException sqlException) {
124126
switch (rdbEngine) {
125127
case MYSQL:
128+
case MARIADB:
126129
when(sqlException.getErrorCode()).thenReturn(1049);
127130
break;
128131
case POSTGRESQL:
@@ -2977,6 +2980,7 @@ private List<String> prepareSqlForCreateSchemaStatements(RdbEngine rdbEngine) {
29772980
case POSTGRESQL:
29782981
case YUGABYTE:
29792982
case SQL_SERVER:
2983+
case MARIADB:
29802984
statements.add(
29812985
"CREATE SCHEMA "
29822986
+ (rdbEngine.equals(RdbEngine.SQL_SERVER) ? "" : "IF NOT EXISTS ")

core/src/test/java/com/scalar/db/storage/jdbc/RdbEngine.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public enum RdbEngine {
1111
ORACLE,
1212
SQL_SERVER,
1313
SQLITE,
14-
YUGABYTE;
14+
YUGABYTE,
15+
MARIADB;
1516

1617
public static RdbEngineStrategy createRdbEngineStrategy(RdbEngine rdbEngine) {
1718
switch (rdbEngine) {
@@ -27,6 +28,8 @@ public static RdbEngineStrategy createRdbEngineStrategy(RdbEngine rdbEngine) {
2728
return new RdbEngineSqlite();
2829
case YUGABYTE:
2930
return new RdbEngineYugabyte();
31+
case MARIADB:
32+
return new RdbEngineMariaDB();
3033
default:
3134
throw new AssertionError();
3235
}

core/src/test/java/com/scalar/db/storage/jdbc/query/QueryBuilderTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ public void selectQueryTest(RdbEngine rdbEngineType) throws SQLException {
334334
case MYSQL:
335335
case POSTGRESQL:
336336
case YUGABYTE:
337+
case MARIADB:
337338
expectedQuery =
338339
"SELECT c1,c2 FROM n1.t1 WHERE p1=? AND c1>=? AND c1<=? "
339340
+ "ORDER BY c1 ASC,c2 DESC LIMIT 10";
@@ -1300,6 +1301,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
13001301
preparedStatement = mock(PreparedStatement.class);
13011302
switch (rdbEngineType) {
13021303
case MYSQL:
1304+
case MARIADB:
13031305
expectedQuery =
13041306
"INSERT INTO n1.t1 (p1,v1,v2,v3) VALUES (?,?,?,?)"
13051307
+ " ON DUPLICATE KEY UPDATE v1=?,v2=?,v3=?";
@@ -1340,6 +1342,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
13401342
case POSTGRESQL:
13411343
case SQLITE:
13421344
case YUGABYTE:
1345+
case MARIADB:
13431346
verify(preparedStatement).setString(1, "p1Value");
13441347
verify(preparedStatement).setString(2, "v1Value");
13451348
verify(preparedStatement).setString(3, "v2Value");
@@ -1364,6 +1367,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
13641367
preparedStatement = mock(PreparedStatement.class);
13651368
switch (rdbEngineType) {
13661369
case MYSQL:
1370+
case MARIADB:
13671371
expectedQuery =
13681372
"INSERT INTO n1.t1 (p1,c1,v1,v2,v3) VALUES (?,?,?,?,?)"
13691373
+ " ON DUPLICATE KEY UPDATE v1=?,v2=?,v3=?";
@@ -1406,6 +1410,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
14061410
case POSTGRESQL:
14071411
case SQLITE:
14081412
case YUGABYTE:
1413+
case MARIADB:
14091414
verify(preparedStatement).setString(1, "p1Value");
14101415
verify(preparedStatement).setString(2, "c1Value");
14111416
verify(preparedStatement).setString(3, "v1Value");
@@ -1434,6 +1439,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
14341439
preparedStatement = mock(PreparedStatement.class);
14351440
switch (rdbEngineType) {
14361441
case MYSQL:
1442+
case MARIADB:
14371443
expectedQuery =
14381444
"INSERT INTO n1.t1 (p1,p2,c1,c2,v1,v2,v3,v4) VALUES (?,?,?,?,?,?,?,?)"
14391445
+ " ON DUPLICATE KEY UPDATE v1=?,v2=?,v3=?,v4=?";
@@ -1480,6 +1486,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
14801486
case POSTGRESQL:
14811487
case SQLITE:
14821488
case YUGABYTE:
1489+
case MARIADB:
14831490
verify(preparedStatement).setString(1, "p1Value");
14841491
verify(preparedStatement).setString(2, "p2Value");
14851492
verify(preparedStatement).setString(3, "c1Value");
@@ -1518,6 +1525,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
15181525
preparedStatement = mock(PreparedStatement.class);
15191526
switch (rdbEngineType) {
15201527
case MYSQL:
1528+
case MARIADB:
15211529
expectedQuery =
15221530
"INSERT INTO n1.t1 (p1,p2,c1,c2,v1,v2,v3,v4,v5) VALUES (?,?,?,?,?,?,?,?,?)"
15231531
+ " ON DUPLICATE KEY UPDATE v1=?,v2=?,v3=?,v4=?,v5=?";
@@ -1565,6 +1573,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
15651573
case POSTGRESQL:
15661574
case SQLITE:
15671575
case YUGABYTE:
1576+
case MARIADB:
15681577
verify(preparedStatement).setString(1, "p1Value");
15691578
verify(preparedStatement).setString(2, "p2Value");
15701579
verify(preparedStatement).setString(3, "c1Value");
@@ -1617,6 +1626,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
16171626
preparedStatement = mock(PreparedStatement.class);
16181627
switch (rdbEngineType) {
16191628
case MYSQL:
1629+
case MARIADB:
16201630
expectedQuery = "INSERT IGNORE INTO n1.t1 (p1) VALUES (?)";
16211631
break;
16221632
case POSTGRESQL:
@@ -1649,6 +1659,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
16491659
case POSTGRESQL:
16501660
case SQLITE:
16511661
case YUGABYTE:
1662+
case MARIADB:
16521663
verify(preparedStatement).setString(1, "p1Value");
16531664
break;
16541665
case ORACLE:
@@ -1661,6 +1672,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
16611672
preparedStatement = mock(PreparedStatement.class);
16621673
switch (rdbEngineType) {
16631674
case MYSQL:
1675+
case MARIADB:
16641676
expectedQuery = "INSERT IGNORE INTO n1.t1 (p1,c1) VALUES (?,?)";
16651677
break;
16661678
case POSTGRESQL:
@@ -1698,6 +1710,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
16981710
case POSTGRESQL:
16991711
case SQLITE:
17001712
case YUGABYTE:
1713+
case MARIADB:
17011714
verify(preparedStatement).setString(1, "p1Value");
17021715
verify(preparedStatement).setString(2, "c1Value");
17031716
break;
@@ -1713,6 +1726,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
17131726
preparedStatement = mock(PreparedStatement.class);
17141727
switch (rdbEngineType) {
17151728
case MYSQL:
1729+
case MARIADB:
17161730
expectedQuery = "INSERT IGNORE INTO n1.t1 (p1,p2,c1,c2) VALUES (?,?,?,?)";
17171731
break;
17181732
case POSTGRESQL:
@@ -1754,6 +1768,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
17541768
case POSTGRESQL:
17551769
case SQLITE:
17561770
case YUGABYTE:
1771+
case MARIADB:
17571772
verify(preparedStatement).setString(1, "p1Value");
17581773
verify(preparedStatement).setString(2, "p2Value");
17591774
verify(preparedStatement).setString(3, "c1Value");

0 commit comments

Comments
 (0)