Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ public ResourceMetaData(final Map<String, DataSource> dataSources) {
.collect(Collectors.toMap(each -> each, StorageNode::new, (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
Map<String, DataSourcePoolProperties> dataSourcePoolPropsMap = dataSources.entrySet().stream().collect(
Collectors.toMap(Entry::getKey, entry -> DataSourcePoolPropertiesCreator.create(entry.getValue()), (oldValue, currentValue) -> oldValue, LinkedHashMap::new));
storageUnits = storageUnitNodeMap.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> new StorageUnit(entry.getValue(), dataSourcePoolPropsMap.get(entry.getKey()), dataSources.get(entry.getValue().getName())),
(oldValue, currentValue) -> currentValue, LinkedHashMap::new));
storageUnits = storageUnitNodeMap.entrySet().stream().collect(Collectors.toMap(Entry::getKey, entry -> new StorageUnit(
entry.getValue(), dataSourcePoolPropsMap.get(entry.getKey()), dataSources.get(entry.getValue().getName())), (oldValue, currentValue) -> currentValue, LinkedHashMap::new));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import org.apache.shardingsphere.test.infra.fixture.jdbc.MockedDataSource;
import org.junit.jupiter.api.Test;

import javax.sql.DataSource;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -30,17 +33,20 @@ class ResourceMetaDataTest {

@Test
void assertGetAllInstanceDataSourceNames() {
assertThat(new ResourceMetaData(Collections.singletonMap("foo", new MockedDataSource())).getAllInstanceDataSourceNames(), is(Collections.singletonList("foo")));
Map<String, DataSource> dataSources = new LinkedHashMap<>(2, 1F);
dataSources.put("foo_ds", new MockedDataSource());
dataSources.put("bar_ds", new MockedDataSource());
assertThat(new ResourceMetaData(dataSources).getAllInstanceDataSourceNames().size(), is(1));
}

@Test
void assertGetNotExistedDataSources() {
assertTrue(new ResourceMetaData(Collections.singletonMap("foo", new MockedDataSource())).getNotExistedDataSources(Collections.singleton("foo")).isEmpty());
assertTrue(new ResourceMetaData(Collections.singletonMap("foo_ds", new MockedDataSource())).getNotExistedDataSources(Collections.singleton("foo_ds")).isEmpty());
}

@Test
void assertGetDataSourceMap() {
assertThat(new ResourceMetaData(Collections.singletonMap("foo", new MockedDataSource())).getDataSourceMap().size(), is(1));
assertTrue(new ResourceMetaData(Collections.singletonMap("foo", new MockedDataSource())).getDataSourceMap().containsKey("foo"));
assertThat(new ResourceMetaData(Collections.singletonMap("foo_ds", new MockedDataSource())).getDataSourceMap().size(), is(1));
assertTrue(new ResourceMetaData(Collections.singletonMap("foo_ds", new MockedDataSource())).getDataSourceMap().containsKey("foo_ds"));
}
}