Skip to content

Commit

Permalink
新增散库散表批量更新测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
ash committed Mar 23, 2016
1 parent 9dea86c commit 3bfd3f6
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

import javax.sql.DataSource;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -65,6 +67,7 @@ public void before() throws Exception {
@Test
public void test() throws Exception {
int price = 0;
List<Order> orders = new ArrayList<Order>();
for (int cid = 0; cid < 10; cid++) {
for (int intUid = 10; intUid < 20; intUid++) {
String uid = String.valueOf(intUid);
Expand All @@ -75,8 +78,14 @@ public void test() throws Exception {
o.setPrice(price);
orderDao.insert(o);
assertThat(orderDao.getOrder(cid, uid), equalTo(o));
o.setPrice(9527);
orders.add(o);
}
}
orderDao.batchUpdate(orders);
for (Order o : orders) {
assertThat(orderDao.getOrder(o.getCid(), o.getUid()), equalTo(o));
}
}

@DB(table = "order", dataSourceRouter = OrderShardStrategy.class, tablePartition = OrderShardStrategy.class)
Expand All @@ -88,6 +97,9 @@ interface OrderDao {
@SQL("select cid, uid, price from #table where cid = :1 and uid = :2")
public Order getOrder(@DataSourceShardBy int cid, @TableShardBy String uid);

@SQL("update #table set price = :price where cid = :cid and uid = :uid")
public int batchUpdate(@DataSourceShardBy("cid") @TableShardBy("uid") List<Order> orders);

}

static class OrderShardStrategy implements TupleShardStrategy<Integer, String> {
Expand Down

0 comments on commit 3bfd3f6

Please sign in to comment.