@@ -0,0 +1,3310 @@
+/*%0A * Licensed to the Apache Software Foundation (ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.apache.shardingsphere.infra.optimize.schema.table.execute;%0A%0Aimport org.apache.calcite.DataContext;%0Aimport org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;%0Aimport org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;%0Aimport org.apache.shardingsphere.infra.route.context.RouteContext;%0Aimport org.apache.shardingsphere.infra.route.context.RouteMapper;%0Aimport org.apache.shardingsphere.infra.route.context.RouteUnit;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.util.Collection;%0Aimport java.util.Collections;%0Aimport java.util.LinkedHashSet;%0Aimport java.util.LinkedList;%0A%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.mockito.Mockito.mock;%0A%0Apublic final class CalciteExecutionContextGeneratorTest %7B%0A    %0A    private ExecutionContext initialExecutionContext;%0A    %0A    @Before%0A    public void setUp() %7B%0A        RouteContext routeContext = new RouteContext();%0A        routeContext.getRouteUnits().addAll(getRouteUnits());%0A        initialExecutionContext = new ExecutionContext(mock(SQLStatementContext.class), Collections.emptyList(), routeContext);%0A    %7D%0A    %0A    private Collection%3CRouteUnit%3E getRouteUnits() %7B%0A        Collection%3CRouteMapper%3E tables = new LinkedList%3C%3E();%0A        tables.add(new RouteMapper(%22t_order%22, %22t_order_0%22));%0A        tables.add(new RouteMapper(%22t_order%22, %22t_order_1%22));%0A        RouteUnit unit1 = new RouteUnit(new RouteMapper(%22ds%22, %22ds0%22), tables);%0A        Collection%3CRouteUnit%3E result = new LinkedHashSet%3C%3E();%0A        result.add(unit1);%0A        tables = new LinkedList%3C%3E();%0A        tables.add(new RouteMapper(%22t_order%22, %22t_order_3%22));%0A        tables.add(new RouteMapper(%22t_order%22, %22t_order_4%22));%0A        RouteUnit unit2 = new RouteUnit(new RouteMapper(%22ds%22, %22ds1%22), tables);%0A        result.add(unit2);%0A        return result;%0A    %7D%0A    %0A    @Test%0A    public void assertGenerate() %7B%0A        CalciteExecutionContextGenerator generator =%0A                new CalciteExecutionContextGenerator(%22t_order%22, initialExecutionContext, new CalciteExecutionSQLGenerator(mock(DataContext.class), Collections.emptyList(), new int%5B%5D%7B%7D));%0A        ExecutionContext actual = generator.generate();%0A        assertThat(actual.getExecutionUnits().size(), is(4));%0A        assertThat(actual.getExecutionUnits().iterator().next().getDataSourceName(), is(%22ds0%22));%0A        assertThat(actual.getExecutionUnits().iterator().next().getSqlUnit().getSql(), is(%22SELECT * FROM t_order_0%22));%0A    %7D%0A%7D%0A

add CalciteExecutionContextGeneratorTest (#9014)