Skip to content

Commit

Permalink
Revise code format for apache#9192 (apache#9197)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Jan 28, 2021
1 parent 022868f commit 36e5f86
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,50 @@

@RunWith(MockitoJUnitRunner.class)
public final class SchemaBuilderTest {

private static final String TEST_CATALOG = "catalog";

private static final String TEST_SCHEMA = "schema";

private static final String TABLE_TYPE = "TABLE";

private static final String VIEW_TYPE = "VIEW";

private static final String TABLE_NAME = "TABLE_NAME";

private final String[] unConfiguredTableNames = new String[]{"unconfigured_table1", "unconfigured_table2"};

private final String[] unConfiguredTableNames = {"unconfigured_table1", "unconfigured_table2"};
private SchemaBuilderMaterials schemaBuilderMaterials;

@Mock
private DatabaseType databaseType;

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private DataSource dataSource;

@Mock
private ConfigurationProperties props;

@Before
public void setUp() {
schemaBuilderMaterials = new SchemaBuilderMaterials(databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(), new DataNodeContainedFixtureRule()),
props);
schemaBuilderMaterials = new SchemaBuilderMaterials(
databaseType, Collections.singletonMap("logic_db", dataSource), Arrays.asList(new CommonFixtureRule(), new DataNodeContainedFixtureRule()), props);
}

@Test
public void assertBuildOfAllShardingTables() throws SQLException {
ShardingSphereSchema actual = SchemaBuilder.build(schemaBuilderMaterials);
assertThat(actual.getAllTableNames().size(), is(2));
assertSchemaOfShardingTables(actual);
}

private void assertSchemaOfShardingTables(final ShardingSphereSchema actual) {
assertTrue(actual.containsTable("data_node_routed_table1"));
assertTrue(actual.get("data_node_routed_table1").getColumns().containsKey("id"));
assertTrue(actual.containsTable("data_node_routed_table2"));
assertTrue(actual.get("data_node_routed_table2").getColumns().containsKey("id"));
}

@Test
@SneakyThrows(SQLException.class)
public void assertBuildOfShardingTablesAndUnConfiguredTables() {
Expand All @@ -101,13 +102,13 @@ public void assertBuildOfShardingTablesAndUnConfiguredTables() {
when(connection.getSchema()).thenReturn(TEST_SCHEMA);
when(databaseMetaData.getTables(connection.getCatalog(), connection.getSchema(), null, new String[]{TABLE_TYPE, VIEW_TYPE})).thenReturn(resultSet);
when(resultSet.next()).thenReturn(true, true, true, true, true, true, false);
String[] mockReturnTables = new String[]{unConfiguredTableNames[1], "data_node_routed_table1_0", "data_node_routed_table1_1", "data_node_routed_table2_0", "data_node_routed_table2_1"};
String[] mockReturnTables = {unConfiguredTableNames[1], "data_node_routed_table1_0", "data_node_routed_table1_1", "data_node_routed_table2_0", "data_node_routed_table2_1"};
when(resultSet.getString(TABLE_NAME)).thenReturn(unConfiguredTableNames[0], mockReturnTables);
ShardingSphereSchema actual = SchemaBuilder.build(schemaBuilderMaterials);
assertThat(actual.getAllTableNames().size(), is(4));
assertSchemaOfShardingTablesAndUnConfiguredTables(actual);
}

private void assertSchemaOfShardingTablesAndUnConfiguredTables(final ShardingSphereSchema actual) {
assertSchemaOfShardingTables(actual);
assertTrue(actual.containsTable(unConfiguredTableNames[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@
import java.util.Optional;

public final class DataNodeContainedFixtureRuleBasedTableMetaDataBuilder implements RuleBasedTableMetaDataBuilder<DataNodeContainedFixtureRule> {

@Override
public Optional<TableMetaData> load(final String tableName, final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap,
final DataNodes dataNodes, final DataNodeContainedFixtureRule rule, final ConfigurationProperties props) {
return ("data_node_routed_table1".equals(tableName) || "data_node_routed_table2".equals(tableName))
? Optional.of(new TableMetaData(Collections.emptyList(), Collections.emptyList())) : Optional.empty();
}

@Override
public TableMetaData decorate(final String tableName, final TableMetaData tableMetaData, final DataNodeContainedFixtureRule rule) {
ColumnMetaData columnMetaData = new ColumnMetaData("id", 1, "INT", true, true, false);
return new TableMetaData(Collections.singletonList(columnMetaData), Collections.emptyList());
}

@Override
public int getOrder() {
return 1;
}

@Override
public Class<DataNodeContainedFixtureRule> getTypeClass() {
return DataNodeContainedFixtureRule.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,48 @@

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

public final class DataNodeContainedFixtureRule implements DataNodeContainedRule, TableContainedRule {

private final Map<String, String> actualTableNameMaps = new HashMap<>(4);

public DataNodeContainedFixtureRule() {
actualTableNameMaps.putIfAbsent("data_node_routed_table1_0", "data_node_routed_table1");
actualTableNameMaps.putIfAbsent("data_node_routed_table1_1", "data_node_routed_table1");
actualTableNameMaps.putIfAbsent("data_node_routed_table2_0", "data_node_routed_table2");
actualTableNameMaps.putIfAbsent("data_node_routed_table2_1", "data_node_routed_table2");
}

@Override
public Map<String, Collection<DataNode>> getAllDataNodes() {
return null;
}

@Override
public Collection<String> getAllActualTables() {
return actualTableNameMaps.keySet();
}

@Override
public Optional<String> findFirstActualTable(final String logicTable) {
return Optional.empty();
}

@Override
public boolean isNeedAccumulate(final Collection<String> tables) {
return false;
}

@Override
public Optional<String> findLogicTableByActualTable(final String actualTable) {
return Optional.ofNullable(actualTableNameMaps.get(actualTable));
}

@Override
public Collection<String> getTables() {
return actualTableNameMaps.values().stream().collect(Collectors.toSet());
return new HashSet<>(actualTableNameMaps.values());
}
}

0 comments on commit 36e5f86

Please sign in to comment.