Skip to content

Commit

Permalink
Fix test cases (#28642)
Browse files Browse the repository at this point in the history
* Fix test cases

* For code format

* Fix test cases
  • Loading branch information
terrymanu authored Oct 5, 2023
1 parent 3278b08 commit eaaabab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,28 @@ public final class ResourceMetaData {
public ResourceMetaData(final Map<String, DataSource> dataSources) {
this.dataSources = StorageNodeAggregator.aggregateDataSources(dataSources);
Map<String, StorageNode> storageNodes = StorageUnitNodeMapUtils.fromDataSources(dataSources);
Map<String, DataSourcePoolProperties> dataSourcePoolPropertiesMap = dataSources.entrySet().stream().collect(
Map<String, DataSourcePoolProperties> dataSourcePoolPropsMap = dataSources.entrySet().stream().collect(
Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
storageUnits = new LinkedHashMap<>();
for (Entry<String, StorageNode> entry : storageNodes.entrySet()) {
DataSource dataSource = dataSources.get(entry.getValue().getName().getName());
if (!(dataSource instanceof CatalogSwitchableDataSource)) {
dataSource = new CatalogSwitchableDataSource(dataSource, entry.getValue().getCatalog(), entry.getValue().getUrl());
}
storageUnits.put(entry.getKey(), new StorageUnit(null, entry.getValue(), dataSourcePoolPropertiesMap.get(entry.getKey()), dataSource));
storageUnits.put(entry.getKey(), new StorageUnit(null, entry.getValue(), dataSourcePoolPropsMap.get(entry.getKey()), dataSource));
}
}

public ResourceMetaData(final String databaseName, final Map<StorageNodeName, DataSource> dataSources,
final Map<String, StorageNode> storageNodes, final Map<String, DataSourcePoolProperties> propsMap) {
final Map<String, StorageNode> storageNodes, final Map<String, DataSourcePoolProperties> dataSourcePoolPropsMap) {
this.dataSources = dataSources;
storageUnits = new LinkedHashMap<>();
for (Entry<String, StorageNode> entry : storageNodes.entrySet()) {
DataSource dataSource = dataSources.get(entry.getValue().getName());
if (!(dataSource instanceof CatalogSwitchableDataSource)) {
dataSource = new CatalogSwitchableDataSource(dataSource, entry.getValue().getCatalog(), entry.getValue().getUrl());
}
storageUnits.put(entry.getKey(), new StorageUnit(databaseName, entry.getValue(), propsMap.get(entry.getKey()), dataSource));
storageUnits.put(entry.getKey(), new StorageUnit(databaseName, entry.getValue(), dataSourcePoolPropsMap.get(entry.getKey()), dataSource));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -65,7 +66,7 @@ void setUp() {
@Test
void assertExecuteFailedAndProtocolTypeDifferentWithDatabaseType() throws SQLException {
Object saneResult = new Object();
ResourceMetaData resourceMetaData = mock(ResourceMetaData.class);
ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS);
when(resourceMetaData.getStorageUnits().get("ds").getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"));
JDBCExecutorCallback<Object> callback =
new JDBCExecutorCallback<Object>(TypedSPILoader.getService(DatabaseType.class, "MySQL"), resourceMetaData, mock(SelectStatement.class), true) {
Expand All @@ -86,7 +87,7 @@ protected Optional<Object> getSaneResult(final SQLStatement sqlStatement, final

@Test
void assertExecuteSQLExceptionOccurredAndProtocolTypeSameAsDatabaseType() {
ResourceMetaData resourceMetaData = mock(ResourceMetaData.class);
ResourceMetaData resourceMetaData = mock(ResourceMetaData.class, RETURNS_DEEP_STUBS);
when(resourceMetaData.getStorageUnits().get("ds").getStorageType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"));
JDBCExecutorCallback<Object> callback =
new JDBCExecutorCallback<Object>(TypedSPILoader.getService(DatabaseType.class, "MySQL"), resourceMetaData, mock(SelectStatement.class), true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ private ContextManager mockContextManager() {
}

private Map<String, StorageUnit> createStorageUnits() {
StorageUnit storageUnit1 = mock(StorageUnit.class);
StorageUnit storageUnit1 = mock(StorageUnit.class, RETURNS_DEEP_STUBS);
when(storageUnit1.getDataSource()).thenReturn(createDataSource("ds_0"));
StorageUnit storageUnit2 = mock(StorageUnit.class);
StorageUnit storageUnit2 = mock(StorageUnit.class, RETURNS_DEEP_STUBS);
when(storageUnit2.getDataSource()).thenReturn(createDataSource("ds_2"));
Map<String, StorageUnit> result = new LinkedHashMap<>(2, 1F);
result.put("ds_0", storageUnit1);
Expand Down

0 comments on commit eaaabab

Please sign in to comment.