SQLRouteEngine { public RouteContext route(final LogicSQL logicSQL) { routingHook.start(logicSQL.getSql()); try { RouteContext result = doRoute(logicSQL); routingHook.finishSuccess(result, logicSQL.getSchema().getMetaData().getRuleSchemaMetaData().getConfiguredSchemaMetaData()); return result; } catch (final Exception ex) { routingHook.finishFailure(ex); throw ex; } } SQLRouteEngine(final ConfigurationProperties props, final Collection<ShardingSphereRule> rules); RouteContext route(final LogicSQL logicSQL);  }
@Test public void assertRouteSuccess() { ShardingSphereSchema schema = new ShardingSphereSchema("logic_schema", Collections.emptyList(), Collections.singleton(new RouteRuleFixture()), Collections.emptyMap(), metaData); LogicSQL logicSQL = new LogicSQL(schema, mock(SQLStatementContext.class), "SELECT 1", Collections.emptyList()); SQLRouteEngine sqlRouteEngine = new SQLRouteEngine(props, Collections.singleton(new RouteRuleFixture())); setSPIRoutingHook(sqlRouteEngine); RouteContext actual = sqlRouteEngine.route(logicSQL); assertThat(actual.getRouteUnits().size(), is(1)); RouteUnit routeUnit = actual.getRouteUnits().iterator().next(); assertThat(routeUnit.getDataSourceMapper().getLogicName(), is("ds")); assertThat(routeUnit.getDataSourceMapper().getActualName(), is("ds_0")); assertTrue(routeUnit.getTableMappers().isEmpty()); verify(routingHook).start("SELECT 1"); verify(routingHook).finishSuccess(actual, metaData.getRuleSchemaMetaData().getConfiguredSchemaMetaData()); }
@Test(expected = UnsupportedOperationException.class) public void assertRouteFailure() { ShardingSphereSchema schema = new ShardingSphereSchema("logic_schema", Collections.emptyList(), Collections.singleton(new RouteRuleFixture()), Collections.emptyMap(), metaData); LogicSQL logicSQL = new LogicSQL(schema, mock(SQLStatementContext.class), "SELECT 1", Collections.emptyList()); SQLRouteEngine sqlRouteEngine = new SQLRouteEngine(props, Collections.singleton(new RouteFailureRuleFixture())); setSPIRoutingHook(sqlRouteEngine); try { sqlRouteEngine.route(logicSQL); } catch (final UnsupportedOperationException ex) { verify(routingHook).start("SELECT 1"); verify(routingHook).finishFailure(ex); throw ex; } }