Skip to content

Commit

Permalink
Refactor master slave integrate test cases 5th.
Browse files Browse the repository at this point in the history
  • Loading branch information
haocao committed Sep 6, 2017
1 parent aa05e10 commit 5d3d29b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,36 @@ private static DatabaseType findDatabaseType(final String databaseType) {

private static void createSchema(final DatabaseType dbType) {
createJdbcSchema(dbType);
createMasterSlaveOnlySchema(dbType);
createShardingSchema(dbType);
}

private static void createShardingSchema(final DatabaseType dbType) {
try {
Connection conn;
for (int i = 0; i < 10; i++) {
for (String database : Arrays.asList("tbl", "db", "dbtbl", "nullable", "master", "slave")) {
if ("tbl".equals(database) && i == 0) {
conn = initialConnection(database, dbType);
RunScript.execute(conn, new InputStreamReader(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/schema/table/tbl.sql")));
conn.close();
} else {
conn = initialConnection(database + "_" + i, dbType);
RunScript.execute(conn, new InputStreamReader(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/schema/table/" + database + ".sql")));
conn.close();
}
for (String database : Arrays.asList("db", "dbtbl", "nullable", "master", "slave")) {
conn = initialConnection(database + "_" + i, dbType);
RunScript.execute(conn, new InputStreamReader(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/schema/table/" + database + ".sql")));
conn.close();
}
}
conn = initialConnection("tbl", dbType);
RunScript.execute(conn, new InputStreamReader(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/schema/table/tbl.sql")));
conn.close();
} catch (final SQLException ex) {
ex.printStackTrace();
}
}

private static void createMasterSlaveOnlySchema(final DatabaseType dbType) {
try {
Connection conn;
for (String database : Arrays.asList("master_only", "slave_only")) {
conn = initialConnection(database, dbType);
RunScript.execute(conn, new InputStreamReader(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/schema/table/" + database + ".sql")));
conn.close();
}
} catch (final SQLException ex) {
ex.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<data parameter="10,19,1000,1909,6" expected="select/postgresql/SelectPagingWithOffsetSql.xml" />
</sharding-rule>
</sql>
<sql id="assertSelectPaginationWithLimitOnly">
<sql id="assertSelectPaginationWithRowCount">
<sharding-rule>
<data parameter="10,19,1000,1909,2" expected="select/SelectPagingWithRowCountSql.xml" />
</sharding-rule>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</order-by-columns>
<limit offset="5" offset-index="4" />
</assert>
<assert id="assertSelectPaginationWithLimitOnly" parameters="1,2,9,10,5">
<assert id="assertSelectPaginationWithRowCount" parameters="1,2,9,10,5">
<tables>
<table name="t_order" alias="o" />
<table name="t_order_item" alias="i" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<sqls>
<sql id="assertSelectPaginationWithOffset" value="SELECT i.* FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (%s, %s) AND o.order_id BETWEEN %s AND %s ORDER BY i.item_id DESC OFFSET %s" type="PostgreSQL" />
<sql id="assertSelectPaginationWithLimitOnly" value="SELECT i.* FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (%s, %s) AND o.order_id BETWEEN %s AND %s ORDER BY i.item_id DESC LIMIT %s" type="MySQL,H2,PostgreSQL" />
<sql id="assertSelectPaginationWithRowCount" value="SELECT i.* FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (%s, %s) AND o.order_id BETWEEN %s AND %s ORDER BY i.item_id DESC LIMIT %s" type="MySQL,H2,PostgreSQL" />
<sql id="assertSelectPaginationWithTop" value="SELECT * FROM (SELECT TOP (%s) row_number() OVER (ORDER BY i.item_id DESC) AS rownum_, i.item_id, o.order_id as order_id, o.status as status, o.user_id as user_id FROM t_order o JOIN t_order_item i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.user_id IN (%s, %s) AND o.order_id BETWEEN %s AND %s) AS row_" type="SQLServer" />
<sql id="assertSelectPaginationWithRowNumber" value="SELECT * FROM (SELECT row_.*, rownum rownum_ FROM (SELECT order0_.order_id as order_id, order0_.status as status, order0_.user_id as user_id FROM t_order order0_ JOIN t_order_item i ON order0_.user_id = i.user_id AND order0_.order_id = i.order_id WHERE order0_.user_id IN (%s, %s) AND order0_.order_id BETWEEN %s AND %s ORDER BY i.item_id DESC) row_ WHERE rownum &lt;= %s)" type="Oracle" />
<sql id="assertSelectPaginationWithLimit" value="SELECT i.* FROM `t_order` o JOIN `t_order_item` i ON o.user_id = i.user_id AND o.order_id = i.order_id WHERE o.`user_id` IN (%s, %s) AND o.`order_id` BETWEEN %s AND %s ORDER BY i.item_id DESC LIMIT %s, %s" type="MySQL,H2" />
Expand Down

0 comments on commit 5d3d29b

Please sign in to comment.