Skip to content

Commit

Permalink
Rename RDBTracingStorageConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Oct 31, 2023
1 parent 2034bfd commit c0e99f9
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import java.util.concurrent.ConcurrentMap;

/**
* Mapping tracing storage configuration} to data source.
* Mapping tracing storage configuration to data source.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DataSourceRegistry {

private static volatile DataSourceRegistry instance;

private final ConcurrentMap<DataSourceConfiguration, DataSource> dataSources = new ConcurrentHashMap<>();
private final ConcurrentMap<RDBTracingStorageConfiguration, DataSource> dataSources = new ConcurrentHashMap<>();

/**
* Get instance of {@link DataSourceRegistry}.
Expand All @@ -50,17 +50,17 @@ public static DataSourceRegistry getInstance() {
return instance;
}

void registerDataSource(final DataSourceConfiguration dataSourceConfig, final DataSource dataSource) {
void registerDataSource(final RDBTracingStorageConfiguration dataSourceConfig, final DataSource dataSource) {
dataSources.putIfAbsent(dataSourceConfig, dataSource);
}

/**
* Get {@link DataSource} by {@link DataSourceConfiguration}.
* Get {@link DataSource} by {@link RDBTracingStorageConfiguration}.
*
* @param dataSourceConfig data source configuration
* @return instance of {@link DataSource}
*/
public DataSource getDataSource(final DataSourceConfiguration dataSourceConfig) {
return dataSources.computeIfAbsent(dataSourceConfig, DataSourceConfiguration::createDataSource);
public DataSource getDataSource(final RDBTracingStorageConfiguration dataSourceConfig) {
return dataSources.computeIfAbsent(dataSourceConfig, RDBTracingStorageConfiguration::createDataSource);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
import java.util.Optional;

/**
* Data source configuration.
* RDB tracing storage configuration.
*/
@RequiredArgsConstructor
@Getter
public final class DataSourceConfiguration implements TracingStorageConfiguration<DataSource> {
public final class RDBTracingStorageConfiguration implements TracingStorageConfiguration<DataSource> {

private static final String GETTER_PREFIX = "get";

Expand All @@ -67,8 +67,8 @@ public final class DataSourceConfiguration implements TracingStorageConfiguratio
* @param dataSource data source
* @return data source configuration
*/
public static DataSourceConfiguration getDataSourceConfiguration(final DataSource dataSource) {
DataSourceConfiguration result = new DataSourceConfiguration(dataSource.getClass().getName());
public static RDBTracingStorageConfiguration getDataSourceConfiguration(final DataSource dataSource) {
RDBTracingStorageConfiguration result = new RDBTracingStorageConfiguration(dataSource.getClass().getName());
result.props.putAll(findAllGetterProperties(dataSource));
return result;
}
Expand Down Expand Up @@ -97,11 +97,6 @@ private static Collection<Method> findAllGetterMethods(final Class<?> clazz) {
return result;
}

@Override
public DataSource getStorage() {
return DataSourceRegistry.getInstance().getDataSource(this);
}

/**
* Create data source.
*
Expand Down Expand Up @@ -135,12 +130,17 @@ private Optional<Method> findSetterMethod(final Method[] methods, final String p
return Optional.empty();
}

@Override
public DataSource getStorage() {
return DataSourceRegistry.getInstance().getDataSource(this);
}

@Override
public boolean equals(final Object obj) {
return this == obj || null != obj && getClass() == obj.getClass() && equalsByProperties((DataSourceConfiguration) obj);
return this == obj || null != obj && getClass() == obj.getClass() && equalsByProperties((RDBTracingStorageConfiguration) obj);
}

private boolean equalsByProperties(final DataSourceConfiguration dataSourceConfig) {
private boolean equalsByProperties(final RDBTracingStorageConfiguration dataSourceConfig) {
return dataSourceClassName.equals(dataSourceConfig.dataSourceClassName) && props.equals(dataSourceConfig.props);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import java.sql.SQLException;

/**
* {@link TracingStorageConverter} for {@link DataSource}.
* RDB tracing storage converter.
*/
@Slf4j
public final class DataSourceTracingStorageConverter implements TracingStorageConverter<DataSource> {
public final class RDBTracingStorageConverter implements TracingStorageConverter<DataSource> {

@Override
public TracingStorageConfiguration<DataSource> convertObjectToConfiguration(final DataSource dataSource) {
Expand All @@ -40,7 +40,7 @@ public TracingStorageConfiguration<DataSource> convertObjectToConfiguration(fina
log.error(ex.getLocalizedMessage(), ex);
throw new TracingStorageUnavailableException(ex);
}
DataSourceConfiguration result = DataSourceConfiguration.getDataSourceConfiguration(dataSource);
RDBTracingStorageConfiguration result = RDBTracingStorageConfiguration.getDataSourceConfiguration(dataSource);
DataSourceRegistry.getInstance().registerDataSource(result, dataSource);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import lombok.Setter;
import org.apache.shardingsphere.elasticjob.kernel.tracing.api.TracingStorageConfiguration;
import org.apache.shardingsphere.elasticjob.kernel.tracing.yaml.YamlTracingStorageConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.RDBTracingStorageConfiguration;

import javax.sql.DataSource;
import java.util.LinkedHashMap;
Expand All @@ -42,7 +42,7 @@ public final class YamlDataSourceConfiguration implements YamlTracingStorageConf

@Override
public TracingStorageConfiguration<DataSource> toConfiguration() {
DataSourceConfiguration result = new DataSourceConfiguration(dataSourceClassName);
RDBTracingStorageConfiguration result = new RDBTracingStorageConfiguration(dataSourceClassName);
result.getProps().putAll(props);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.shardingsphere.elasticjob.kernel.infra.yaml.config.YamlConfigurationConverter;
import org.apache.shardingsphere.elasticjob.kernel.tracing.api.TracingStorageConfiguration;
import org.apache.shardingsphere.elasticjob.kernel.tracing.yaml.YamlTracingStorageConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.RDBTracingStorageConfiguration;

import javax.sql.DataSource;

Expand All @@ -32,7 +32,7 @@ public final class YamlDataSourceConfigurationConverter implements YamlConfigura

@Override
public YamlTracingStorageConfiguration<DataSource> convertToYamlConfiguration(final TracingStorageConfiguration<DataSource> data) {
DataSourceConfiguration dataSourceConfig = (DataSourceConfiguration) data;
RDBTracingStorageConfiguration dataSourceConfig = (RDBTracingStorageConfiguration) data;
YamlDataSourceConfiguration result = new YamlDataSourceConfiguration();
result.setDataSourceClassName(dataSourceConfig.getDataSourceClassName());
result.setProps(dataSourceConfig.getProps());
Expand All @@ -41,6 +41,6 @@ public YamlTracingStorageConfiguration<DataSource> convertToYamlConfiguration(fi

@Override
public Class getType() {
return DataSourceConfiguration.class;
return RDBTracingStorageConfiguration.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# limitations under the License.
#

org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceTracingStorageConverter
org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.RDBTracingStorageConverter
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class DataSourceRegistryTest {

@Mock
private DataSourceConfiguration dataSourceConfig;
private RDBTracingStorageConfiguration dataSourceConfig;

@Test
void assertGetDataSourceBySameConfiguration() {
Expand All @@ -49,7 +49,7 @@ void assertGetDataSourceBySameConfiguration() {
@Test
void assertGetDataSourceWithDifferentConfiguration() {
when(dataSourceConfig.createDataSource()).then(invocation -> mock(DataSource.class));
DataSourceConfiguration anotherDataSourceConfig = mock(DataSourceConfiguration.class);
RDBTracingStorageConfiguration anotherDataSourceConfig = mock(RDBTracingStorageConfiguration.class);
when(anotherDataSourceConfig.createDataSource()).then(invocation -> mock(DataSource.class));
DataSource one = DataSourceRegistry.getInstance().getDataSource(dataSourceConfig);
DataSource another = DataSourceRegistry.getInstance().getDataSource(anotherDataSourceConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;

class DataSourceConfigurationTest {
class RDBTracingStorageConfigurationTest {

@Test
void assertGetDataSourceConfiguration() throws SQLException {
Expand All @@ -45,7 +45,7 @@ void assertGetDataSourceConfiguration() throws SQLException {
actualDataSource.setUsername("root");
actualDataSource.setPassword("root");
actualDataSource.setLoginTimeout(1);
DataSourceConfiguration actual = DataSourceConfiguration.getDataSourceConfiguration(actualDataSource);
RDBTracingStorageConfiguration actual = RDBTracingStorageConfiguration.getDataSourceConfiguration(actualDataSource);
assertThat(actual.getDataSourceClassName(), is(HikariDataSource.class.getName()));
assertThat(actual.getProps().get("driverClassName").toString(), is("org.h2.Driver"));
assertThat(actual.getProps().get("jdbcUrl").toString(), is("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
Expand All @@ -63,7 +63,7 @@ void assertCreateDataSource() {
props.put("password", "root");
props.put("loginTimeout", "5000");
props.put("test", "test");
DataSourceConfiguration dataSourceConfig = new DataSourceConfiguration(HikariDataSource.class.getName());
RDBTracingStorageConfiguration dataSourceConfig = new RDBTracingStorageConfiguration(HikariDataSource.class.getName());
dataSourceConfig.getProps().putAll(props);
HikariDataSource actual = (HikariDataSource) dataSourceConfig.createDataSource();
assertThat(actual.getDriverClassName(), is("org.h2.Driver"));
Expand All @@ -74,8 +74,8 @@ void assertCreateDataSource() {

@Test
void assertEquals() {
DataSourceConfiguration originalDataSourceConfig = new DataSourceConfiguration(HikariDataSource.class.getName());
DataSourceConfiguration targetDataSourceConfig = new DataSourceConfiguration(HikariDataSource.class.getName());
RDBTracingStorageConfiguration originalDataSourceConfig = new RDBTracingStorageConfiguration(HikariDataSource.class.getName());
RDBTracingStorageConfiguration targetDataSourceConfig = new RDBTracingStorageConfiguration(HikariDataSource.class.getName());
assertThat(originalDataSourceConfig, is(originalDataSourceConfig));
assertThat(originalDataSourceConfig, is(targetDataSourceConfig));
originalDataSourceConfig.getProps().put("username", "root");
Expand All @@ -85,22 +85,22 @@ void assertEquals() {

@Test
void assertNotEquals() {
DataSourceConfiguration originalDataSourceConfig = new DataSourceConfiguration(HikariDataSource.class.getName());
DataSourceConfiguration targetDataSourceConfig = new DataSourceConfiguration(HikariDataSource.class.getName());
RDBTracingStorageConfiguration originalDataSourceConfig = new RDBTracingStorageConfiguration(HikariDataSource.class.getName());
RDBTracingStorageConfiguration targetDataSourceConfig = new RDBTracingStorageConfiguration(HikariDataSource.class.getName());
originalDataSourceConfig.getProps().put("username", "root");
targetDataSourceConfig.getProps().put("username", "root0");
assertThat(originalDataSourceConfig, not(targetDataSourceConfig));
}

@Test
void assertEqualsWithNull() {
assertFalse(new DataSourceConfiguration(HikariDataSource.class.getName()).equals(null));
assertFalse(new RDBTracingStorageConfiguration(HikariDataSource.class.getName()).equals(null));
}

@Test
void assertSameHashCode() {
DataSourceConfiguration originalDataSourceConfig = new DataSourceConfiguration(HikariDataSource.class.getName());
DataSourceConfiguration targetDataSourceConfig = new DataSourceConfiguration(HikariDataSource.class.getName());
RDBTracingStorageConfiguration originalDataSourceConfig = new RDBTracingStorageConfiguration(HikariDataSource.class.getName());
RDBTracingStorageConfiguration targetDataSourceConfig = new RDBTracingStorageConfiguration(HikariDataSource.class.getName());
assertThat(originalDataSourceConfig.hashCode(), is(targetDataSourceConfig.hashCode()));
originalDataSourceConfig.getProps().put("username", "root");
targetDataSourceConfig.getProps().put("username", "root");
Expand All @@ -112,14 +112,14 @@ void assertSameHashCode() {

@Test
void assertDifferentHashCode() {
DataSourceConfiguration originalDataSourceConfig = new DataSourceConfiguration(HikariDataSource.class.getName());
DataSourceConfiguration targetDataSourceConfig = new DataSourceConfiguration(HikariDataSource.class.getName());
RDBTracingStorageConfiguration originalDataSourceConfig = new RDBTracingStorageConfiguration(HikariDataSource.class.getName());
RDBTracingStorageConfiguration targetDataSourceConfig = new RDBTracingStorageConfiguration(HikariDataSource.class.getName());
originalDataSourceConfig.getProps().put("username", "root");
targetDataSourceConfig.getProps().put("username", "root");
targetDataSourceConfig.getProps().put("password", "root");
assertThat(originalDataSourceConfig.hashCode(), not(targetDataSourceConfig.hashCode()));
originalDataSourceConfig = new DataSourceConfiguration(HikariDataSource.class.getName());
targetDataSourceConfig = new DataSourceConfiguration(BasicDataSource.class.getName());
originalDataSourceConfig = new RDBTracingStorageConfiguration(HikariDataSource.class.getName());
targetDataSourceConfig = new RDBTracingStorageConfiguration(BasicDataSource.class.getName());
assertThat(originalDataSourceConfig.hashCode(), not(targetDataSourceConfig.hashCode()));
}

Expand All @@ -132,7 +132,7 @@ void assertGetDataSourceConfigurationWithConnectionInitSqls() {
actualDataSource.setUsername("root");
actualDataSource.setPassword("root");
actualDataSource.setConnectionInitSqls(Arrays.asList("set names utf8mb4;", "set names utf8;"));
DataSourceConfiguration actual = DataSourceConfiguration.getDataSourceConfiguration(actualDataSource);
RDBTracingStorageConfiguration actual = RDBTracingStorageConfiguration.getDataSourceConfiguration(actualDataSource);
assertThat(actual.getDataSourceClassName(), is(BasicDataSource.class.getName()));
assertThat(actual.getProps().get("driverClassName").toString(), is("org.h2.Driver"));
assertThat(actual.getProps().get("url").toString(), is("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class DataSourceTracingStorageConverterTest {
class RDBTracingStorageConverterTest {

@Mock
private DataSource dataSource;
Expand All @@ -55,14 +55,14 @@ void assertConvert() throws SQLException {
when(dataSource.getConnection()).thenReturn(connection);
when(connection.getMetaData()).thenReturn(databaseMetaData);
when(databaseMetaData.getURL()).thenReturn("jdbc:url");
DataSourceTracingStorageConverter converter = new DataSourceTracingStorageConverter();
RDBTracingStorageConverter converter = new RDBTracingStorageConverter();
assertNotNull(converter.convertObjectToConfiguration(dataSource));
}

@Test
void assertConvertFailed() {
assertThrows(TracingStorageUnavailableException.class, () -> {
DataSourceTracingStorageConverter converter = new DataSourceTracingStorageConverter();
RDBTracingStorageConverter converter = new RDBTracingStorageConverter();
doThrow(SQLException.class).when(dataSource).getConnection();
converter.convertObjectToConfiguration(dataSource);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.shardingsphere.elasticjob.tracing.rdb.yaml;

import org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.RDBTracingStorageConfiguration;
import org.apache.shardingsphere.elasticjob.kernel.tracing.yaml.YamlTracingStorageConfiguration;
import org.junit.jupiter.api.Test;

Expand All @@ -28,11 +28,11 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

class YamlDataSourceConfigurationConverterTest {
class YamlRDBTracingStorageConfigurationConverterTest {

@Test
void assertConvertDataSourceConfiguration() {
DataSourceConfiguration dataSourceConfig = new DataSourceConfiguration("org.h2.Driver");
RDBTracingStorageConfiguration dataSourceConfig = new RDBTracingStorageConfiguration("org.h2.Driver");
dataSourceConfig.getProps().put("foo", "bar");
YamlDataSourceConfigurationConverter converter = new YamlDataSourceConfigurationConverter();
YamlTracingStorageConfiguration<DataSource> actual = converter.convertToYamlConfiguration(dataSourceConfig);
Expand Down
2 changes: 1 addition & 1 deletion ecosystem/tracing/rdb/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
<appender-ref ref="STDOUT" />
</root>

<logger name="org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.DataSourceTracingStorageConverter" level="OFF" />
<logger name="org.apache.shardingsphere.elasticjob.tracing.rdb.datasource.RDBTracingStorageConverter" level="OFF" />
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.shardingsphere.elasticjob.kernel.tracing.fixture.config.TracingStorageConfigurationFixture;

/**
* YAML JobEventCaller configuration converter.
* YAML job event caller configuration converter.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public final class YamlJobEventCallerConfigurationConverter
Expand Down

0 comments on commit c0e99f9

Please sign in to comment.