Skip to content

Commit

Permalink
Revise GenericSchemaBuilderTest (apache#33989)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Dec 10, 2024
1 parent 7df9e25 commit 7a1663c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@

class GenericSchemaBuilderMaterialTest {

private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE");

@Test
void assertIsSameProtocolAndStorageTypes() {
GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"),
Collections.emptyMap(), Collections.emptyList(), new ConfigurationProperties(new Properties()), "");
GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(databaseType, Collections.emptyMap(), Collections.emptyList(), new ConfigurationProperties(new Properties()), "");
assertTrue(material.isSameProtocolAndStorageTypes());
}

@Test
void assertIsDifferentProtocolAndStorageTypes() {
GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"),
GenericSchemaBuilderMaterial material = new GenericSchemaBuilderMaterial(databaseType,
Collections.singletonMap("foo", mock()), Collections.emptyList(), new ConfigurationProperties(new Properties()), "");
assertFalse(material.isSameProtocolAndStorageTypes());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ void setUp() {
when(storageUnit.getStorageType()).thenReturn(databaseType);
when(storageUnit.getDataSource()).thenReturn(new MockedDataSource());
material = new GenericSchemaBuilderMaterial(
databaseType, Collections.singletonMap("foo_db", storageUnit), Collections.singleton(rule), new ConfigurationProperties(new Properties()), "foo_db");
databaseType, Collections.singletonMap("foo_schema", storageUnit), Collections.singleton(rule), new ConfigurationProperties(new Properties()), "foo_schema");
}

@Test
void assertLoadWithExistedTableName() throws SQLException {
Collection<String> tableNames = Collections.singletonList("data_node_routed_table1");
when(MetaDataLoader.load(any())).thenReturn(createSchemaMetaDataMap(tableNames, material));
assertFalse(GenericSchemaBuilder.build(tableNames, material).get("foo_db").getAllTables().isEmpty());
assertFalse(GenericSchemaBuilder.build(tableNames, material).get("foo_schema").getAllTables().isEmpty());
}

@Test
void assertLoadWithNotExistedTableName() throws SQLException {
Collection<String> tableNames = Collections.singletonList("invalid_table");
when(MetaDataLoader.load(any())).thenReturn(createSchemaMetaDataMap(tableNames, material));
assertTrue(GenericSchemaBuilder.build(tableNames, material).get("foo_db").getAllTables().isEmpty());
assertTrue(GenericSchemaBuilder.build(tableNames, material).get("foo_schema").getAllTables().isEmpty());
}

@Test
Expand All @@ -92,7 +92,7 @@ void assertLoadAllTables() throws SQLException {
when(MetaDataLoader.load(any())).thenReturn(createSchemaMetaDataMap(tableNames, material));
Map<String, ShardingSphereSchema> actual = GenericSchemaBuilder.build(tableNames, material);
assertThat(actual.size(), is(1));
assertTables(new ShardingSphereSchema("foo_db", actual.values().iterator().next().getAllTables(), Collections.emptyList()));
assertTables(new ShardingSphereSchema("foo_schema", actual.values().iterator().next().getAllTables(), Collections.emptyList()));
}

private Map<String, SchemaMetaData> createSchemaMetaDataMap(final Collection<String> tableNames, final GenericSchemaBuilderMaterial material) {
Expand Down

0 comments on commit 7a1663c

Please sign in to comment.