|
17 | 17 |
|
18 | 18 | package org.apache.shardingsphere.sharding.route.engine.type.unicast;
|
19 | 19 |
|
| 20 | +import com.sphereex.dbplusengine.SphereEx; |
| 21 | +import com.sphereex.dbplusengine.SphereEx.Type; |
20 | 22 | import org.apache.groovy.util.Maps;
|
21 | 23 | import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
|
22 | 24 | import org.apache.shardingsphere.infra.binder.context.statement.ddl.CursorStatementContext;
|
@@ -55,47 +57,58 @@ void setUp() {
|
55 | 57 |
|
56 | 58 | @Test
|
57 | 59 | void assertRoutingForShardingTable() {
|
58 |
| - RouteContext actual = new ShardingUnicastRoutingEngine(mock(SQLStatementContext.class), Collections.singleton("t_order"), new ConnectionContext(Collections::emptySet)).route(shardingRule); |
| 60 | + @SphereEx(Type.MODIFY) |
| 61 | + RouteContext actual = new ShardingUnicastRoutingEngine( |
| 62 | + mock(SQLStatementContext.class), "sharding_db", Collections.singleton("t_order"), new ConnectionContext(Collections::emptySet)).route(shardingRule); |
59 | 63 | assertThat(actual.getRouteUnits().size(), is(1));
|
60 | 64 | assertFalse("ds_2".equalsIgnoreCase(actual.getRouteUnits().iterator().next().getDataSourceMapper().getLogicName()));
|
61 | 65 | }
|
62 | 66 |
|
63 | 67 | @Test
|
64 | 68 | void assertRoutingForBroadcastTable() {
|
65 |
| - RouteContext actual = new ShardingUnicastRoutingEngine(mock(SQLStatementContext.class), Collections.singleton("t_config"), new ConnectionContext(Collections::emptySet)).route(shardingRule); |
| 69 | + @SphereEx(Type.MODIFY) |
| 70 | + RouteContext actual = new ShardingUnicastRoutingEngine( |
| 71 | + mock(SQLStatementContext.class), "sharding_db", Collections.singleton("t_config"), new ConnectionContext(Collections::emptySet)).route(shardingRule); |
66 | 72 | assertThat(actual.getRouteUnits().size(), is(1));
|
67 | 73 | }
|
68 | 74 |
|
69 | 75 | @Test
|
70 | 76 | void assertRoutingForNoTable() {
|
71 |
| - RouteContext actual = new ShardingUnicastRoutingEngine(mock(SQLStatementContext.class), Collections.emptyList(), new ConnectionContext(Collections::emptySet)).route(shardingRule); |
| 77 | + @SphereEx(Type.MODIFY) |
| 78 | + RouteContext actual = new ShardingUnicastRoutingEngine( |
| 79 | + mock(SQLStatementContext.class), "sharding_db", Collections.emptyList(), new ConnectionContext(Collections::emptySet)).route(shardingRule); |
72 | 80 | assertThat(actual.getRouteUnits().size(), is(1));
|
73 | 81 | }
|
74 | 82 |
|
| 83 | + @SphereEx(Type.MODIFY) |
75 | 84 | @Test
|
76 | 85 | void assertRouteForWithNoIntersection() {
|
77 | 86 | assertThrows(ShardingTableRuleNotFoundException.class, () -> new ShardingUnicastRoutingEngine(
|
78 |
| - mock(SQLStatementContext.class), Arrays.asList("t_order", "t_config", "t_product"), new ConnectionContext(Collections::emptySet)).route(shardingRule)); |
| 87 | + mock(SQLStatementContext.class), "sharding_db", Arrays.asList("t_order", "t_config", "t_product"), new ConnectionContext(Collections::emptySet)).route(shardingRule)); |
79 | 88 | }
|
80 | 89 |
|
81 | 90 | @Test
|
82 | 91 | void assertRoutingForTableWithoutTableRule() {
|
83 |
| - RouteContext actual = new ShardingUnicastRoutingEngine(mock(SQLStatementContext.class), Collections.singleton("t_other"), new ConnectionContext(Collections::emptySet)).route(shardingRule); |
| 92 | + @SphereEx(Type.MODIFY) |
| 93 | + RouteContext actual = new ShardingUnicastRoutingEngine( |
| 94 | + mock(SQLStatementContext.class), "sharding_db", Collections.singleton("t_other"), new ConnectionContext(Collections::emptySet)).route(shardingRule); |
84 | 95 | assertThat(actual.getRouteUnits().size(), is(1));
|
85 | 96 | }
|
86 | 97 |
|
87 | 98 | @Test
|
88 | 99 | void assertRoutingForBroadcastTableWithCursorStatement() {
|
| 100 | + @SphereEx(Type.MODIFY) |
89 | 101 | RouteContext actual = new ShardingUnicastRoutingEngine(
|
90 |
| - mock(CursorStatementContext.class), Collections.singleton("t_config"), new ConnectionContext(Collections::emptySet)).route(shardingRule); |
| 102 | + mock(CursorStatementContext.class), "sharding_db", Collections.singleton("t_config"), new ConnectionContext(Collections::emptySet)).route(shardingRule); |
91 | 103 | assertThat(actual.getRouteUnits().size(), is(1));
|
92 | 104 | assertThat(actual.getRouteUnits().iterator().next().getDataSourceMapper().getActualName(), is("ds_0"));
|
93 | 105 | }
|
94 | 106 |
|
95 | 107 | @Test
|
96 | 108 | void assertRoutingForBroadcastTableWithPreferredDataSource() {
|
97 | 109 | ConnectionContext connectionContext = new ConnectionContext(() -> Collections.singleton("ds_1"));
|
98 |
| - RouteContext actual = new ShardingUnicastRoutingEngine(mock(SelectStatementContext.class), Collections.singleton("t_config"), connectionContext).route(shardingRule); |
| 110 | + @SphereEx(Type.MODIFY) |
| 111 | + RouteContext actual = new ShardingUnicastRoutingEngine(mock(SelectStatementContext.class), "sharding_db", Collections.singleton("t_config"), connectionContext).route(shardingRule); |
99 | 112 | assertThat(actual.getRouteUnits().size(), is(1));
|
100 | 113 | assertThat(actual.getRouteUnits().iterator().next().getDataSourceMapper().getActualName(), is("ds_1"));
|
101 | 114 | }
|
|
0 commit comments