Skip to content

Commit

Permalink
Use gson JSONParser for asserting JSON equality deterministically (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-kumbhar authored Dec 2, 2022
1 parent 8e5241c commit 2bf753d
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.advance;

import com.google.gson.Gson;
import com.google.gson.JsonParser;
import org.apache.shardingsphere.distsql.parser.statement.rul.sql.ParseStatement;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
Expand Down Expand Up @@ -76,7 +77,7 @@ public void assertGetRowDataForMySQL() throws SQLException {
parseDistSQLHandler.next();
SQLStatement statement = sqlParserRule.getSQLParserEngine("MySQL").parse(sql, false);
assertThat(new LinkedList<>(parseDistSQLHandler.getRowData().getData()).getFirst(), is("MySQLSelectStatement"));
assertThat(new LinkedList<>(parseDistSQLHandler.getRowData().getData()).getLast(), is(new Gson().toJson(statement)));
assertThat(JsonParser.parseString(new LinkedList<>(parseDistSQLHandler.getRowData().getData()).getLast().toString()), is(JsonParser.parseString(new Gson().toJson(statement))));
}

@Test
Expand All @@ -89,8 +90,7 @@ public void assertGetRowDataForPostgreSQL() throws SQLException {
parseDistSQLHandler.execute();
parseDistSQLHandler.next();
SQLStatement statement = sqlParserRule.getSQLParserEngine("PostgreSQL").parse(sql, false);
assertThat(new LinkedList<>(parseDistSQLHandler.getRowData().getData()).getFirst(), is("PostgreSQLSelectStatement"));
assertThat(new LinkedList<>(parseDistSQLHandler.getRowData().getData()).getLast(), is(new Gson().toJson(statement)));
assertThat(JsonParser.parseString(new LinkedList<>(parseDistSQLHandler.getRowData().getData()).getLast().toString()), is(JsonParser.parseString(new Gson().toJson(statement))));
}

@Test(expected = SQLParsingException.class)
Expand Down

0 comments on commit 2bf753d

Please sign in to comment.