Skip to content

Commit

Permalink
Backport to branch(3) : Fix missing unit tests for MariaDB RdbEngine (#…
Browse files Browse the repository at this point in the history
…2467)

Co-authored-by: Vincent Guilpain <[email protected]>
  • Loading branch information
feeblefakie and Torch3333 authored Jan 20, 2025
1 parent d7042ab commit d19f132
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public abstract class JdbcAdminTestBase {
RdbEngine.SQLITE,
new RdbEngineSqlite(),
RdbEngine.YUGABYTE,
new RdbEngineYugabyte());
new RdbEngineYugabyte(),
RdbEngine.MARIADB,
new RdbEngineMariaDB());

@Mock private BasicDataSource dataSource;
@Mock private Connection connection;
Expand Down Expand Up @@ -123,6 +125,7 @@ private JdbcAdmin createJdbcAdminFor(RdbEngineStrategy rdbEngineStrategy) {
private void mockUndefinedTableError(RdbEngine rdbEngine, SQLException sqlException) {
switch (rdbEngine) {
case MYSQL:
case MARIADB:
when(sqlException.getErrorCode()).thenReturn(1049);
break;
case POSTGRESQL:
Expand Down Expand Up @@ -2977,6 +2980,7 @@ private List<String> prepareSqlForCreateSchemaStatements(RdbEngine rdbEngine) {
case POSTGRESQL:
case YUGABYTE:
case SQL_SERVER:
case MARIADB:
statements.add(
"CREATE SCHEMA "
+ (rdbEngine.equals(RdbEngine.SQL_SERVER) ? "" : "IF NOT EXISTS ")
Expand Down
5 changes: 4 additions & 1 deletion core/src/test/java/com/scalar/db/storage/jdbc/RdbEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum RdbEngine {
ORACLE,
SQL_SERVER,
SQLITE,
YUGABYTE;
YUGABYTE,
MARIADB;

public static RdbEngineStrategy createRdbEngineStrategy(RdbEngine rdbEngine) {
switch (rdbEngine) {
Expand All @@ -27,6 +28,8 @@ public static RdbEngineStrategy createRdbEngineStrategy(RdbEngine rdbEngine) {
return new RdbEngineSqlite();
case YUGABYTE:
return new RdbEngineYugabyte();
case MARIADB:
return new RdbEngineMariaDB();
default:
throw new AssertionError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public void selectQueryTest(RdbEngine rdbEngineType) throws SQLException {
case MYSQL:
case POSTGRESQL:
case YUGABYTE:
case MARIADB:
expectedQuery =
"SELECT c1,c2 FROM n1.t1 WHERE p1=? AND c1>=? AND c1<=? "
+ "ORDER BY c1 ASC,c2 DESC LIMIT 10";
Expand Down Expand Up @@ -1300,6 +1301,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
preparedStatement = mock(PreparedStatement.class);
switch (rdbEngineType) {
case MYSQL:
case MARIADB:
expectedQuery =
"INSERT INTO n1.t1 (p1,v1,v2,v3) VALUES (?,?,?,?)"
+ " ON DUPLICATE KEY UPDATE v1=?,v2=?,v3=?";
Expand Down Expand Up @@ -1340,6 +1342,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
case POSTGRESQL:
case SQLITE:
case YUGABYTE:
case MARIADB:
verify(preparedStatement).setString(1, "p1Value");
verify(preparedStatement).setString(2, "v1Value");
verify(preparedStatement).setString(3, "v2Value");
Expand All @@ -1364,6 +1367,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
preparedStatement = mock(PreparedStatement.class);
switch (rdbEngineType) {
case MYSQL:
case MARIADB:
expectedQuery =
"INSERT INTO n1.t1 (p1,c1,v1,v2,v3) VALUES (?,?,?,?,?)"
+ " ON DUPLICATE KEY UPDATE v1=?,v2=?,v3=?";
Expand Down Expand Up @@ -1406,6 +1410,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
case POSTGRESQL:
case SQLITE:
case YUGABYTE:
case MARIADB:
verify(preparedStatement).setString(1, "p1Value");
verify(preparedStatement).setString(2, "c1Value");
verify(preparedStatement).setString(3, "v1Value");
Expand Down Expand Up @@ -1434,6 +1439,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
preparedStatement = mock(PreparedStatement.class);
switch (rdbEngineType) {
case MYSQL:
case MARIADB:
expectedQuery =
"INSERT INTO n1.t1 (p1,p2,c1,c2,v1,v2,v3,v4) VALUES (?,?,?,?,?,?,?,?)"
+ " ON DUPLICATE KEY UPDATE v1=?,v2=?,v3=?,v4=?";
Expand Down Expand Up @@ -1480,6 +1486,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
case POSTGRESQL:
case SQLITE:
case YUGABYTE:
case MARIADB:
verify(preparedStatement).setString(1, "p1Value");
verify(preparedStatement).setString(2, "p2Value");
verify(preparedStatement).setString(3, "c1Value");
Expand Down Expand Up @@ -1518,6 +1525,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
preparedStatement = mock(PreparedStatement.class);
switch (rdbEngineType) {
case MYSQL:
case MARIADB:
expectedQuery =
"INSERT INTO n1.t1 (p1,p2,c1,c2,v1,v2,v3,v4,v5) VALUES (?,?,?,?,?,?,?,?,?)"
+ " ON DUPLICATE KEY UPDATE v1=?,v2=?,v3=?,v4=?,v5=?";
Expand Down Expand Up @@ -1565,6 +1573,7 @@ public void upsertQueryTest(RdbEngine rdbEngineType) throws SQLException {
case POSTGRESQL:
case SQLITE:
case YUGABYTE:
case MARIADB:
verify(preparedStatement).setString(1, "p1Value");
verify(preparedStatement).setString(2, "p2Value");
verify(preparedStatement).setString(3, "c1Value");
Expand Down Expand Up @@ -1617,6 +1626,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
preparedStatement = mock(PreparedStatement.class);
switch (rdbEngineType) {
case MYSQL:
case MARIADB:
expectedQuery = "INSERT IGNORE INTO n1.t1 (p1) VALUES (?)";
break;
case POSTGRESQL:
Expand Down Expand Up @@ -1649,6 +1659,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
case POSTGRESQL:
case SQLITE:
case YUGABYTE:
case MARIADB:
verify(preparedStatement).setString(1, "p1Value");
break;
case ORACLE:
Expand All @@ -1661,6 +1672,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
preparedStatement = mock(PreparedStatement.class);
switch (rdbEngineType) {
case MYSQL:
case MARIADB:
expectedQuery = "INSERT IGNORE INTO n1.t1 (p1,c1) VALUES (?,?)";
break;
case POSTGRESQL:
Expand Down Expand Up @@ -1698,6 +1710,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
case POSTGRESQL:
case SQLITE:
case YUGABYTE:
case MARIADB:
verify(preparedStatement).setString(1, "p1Value");
verify(preparedStatement).setString(2, "c1Value");
break;
Expand All @@ -1713,6 +1726,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
preparedStatement = mock(PreparedStatement.class);
switch (rdbEngineType) {
case MYSQL:
case MARIADB:
expectedQuery = "INSERT IGNORE INTO n1.t1 (p1,p2,c1,c2) VALUES (?,?,?,?)";
break;
case POSTGRESQL:
Expand Down Expand Up @@ -1754,6 +1768,7 @@ public void upsertQueryWithoutValuesTest(RdbEngine rdbEngineType) throws SQLExce
case POSTGRESQL:
case SQLITE:
case YUGABYTE:
case MARIADB:
verify(preparedStatement).setString(1, "p1Value");
verify(preparedStatement).setString(2, "p2Value");
verify(preparedStatement).setString(3, "c1Value");
Expand Down

0 comments on commit d19f132

Please sign in to comment.